Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 40 |
Nodes: | 6 (0 / 6) |
Uptime: | 10:38:44 |
Calls: | 291 |
Files: | 910 |
Messages: | 76,430 |
How about loop for greater clarity than either do or Python?
(loop
for a = 1 then b
and b = 1 then (+ a b)
do (print a))
Which neatly demonstrates the power of macros as well. If there's a
Here's a more realistic example that illustrates exactly theWell..
opposite point. Take the task of finding the sum of the square of a
bunch of numbers.
Do people really think to themselves when they do this task:
Umm first make a variable called sum
then set that variable sum to zero.
Then get the next number in the list,
square it,
add it to the old value of sum,
store the resulting value into sum,
then get the next variable,etc....
No they they think: sum up the square of a bunch of numbers.
This has an almost direct translation to the lisp style:
(apply '+ (mapcar #'(lambda(x)(* x x)) numlist)).
sum (map (\x -> x ** 2) [1..10])
in Haskell, or
sum (map ((lambda x: x ** 2), range(1,11)))
Too much line noise ;-)
sum([x*x for x in range(1,11)])
Then I would say that a clearer way to express what a person think is:
(loop for number in numberlist sum (expt number power))