Jump to content

Sum of squares: Difference between revisions

Add functional Common Lisp version
imported>GoulashAmateur
(Add functional Common Lisp version)
Line 890:
<syntaxhighlight lang="lisp">(defun sum-of-squares (vector)
(loop for x across vector sum (expt x 2)))</syntaxhighlight>
 
Or in a functional way:
<syntaxhighlight lang="lisp">(defun sum-of-squares (vec)
(reduce #'+ (map 'vector (lambda (x) (* x x)) vec)))</syntaxhighlight>
 
=={{header|Cowgol}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.