Sum of squares: Difference between revisions

Add a modern Tcl version
(→‎{{header|Kotlin}}: Add other approaches, and discuss pros and cons.)
(Add a modern Tcl version)
Line 2,440:
 
sum_of {x {* $x $x}} {1 2 3 4 5} ;# ==> 55</lang>
Modern version
<lang tcl>package require Tcl 8.6
namespace path ::tcl::mathop
 
+ {*}[lmap x {1 2 3 4} {** $x 2}]; # ==> 30
+ {*}[lmap x {} {** $x 2}]; # ==> 0
</lang>
 
=={{header|Trith}}==
Anonymous user