I like the (dolist) in the newLISP - it is similar to TCL's 'foreach', but 'foreach' has more freedom how to iterate through the list(s).
Here is the example from TCL manual:
Code: Select all
foreach - Iterate over all elements in one or more lists
foreach varname list body
foreach varlist1 list1 ?varlist2 list2 ...? body
1) The following loop uses i and j as loop variables to iterate over pairs of elements of a single list.
set x {}
foreach {i j} {a b c d e f} {
lappend x $j $i
}
# The value of x is "b a d c f e"
# There are 3 iterations of the loop.
2) The next loop uses i and j to iterate over two lists in parallel.
set x {}
foreach i {a b c} j {d e f g} {
lappend x $i $j
}
# The value of x is "a d b e c f {} g"
# There are 4 iterations of the loop.
3) The two forms are combined in the following example.
set x {}
foreach i {a b c} {j k} {d e f g} {
lappend x $i $j $k
}
# The value of x is "a d e b f g c {} {}"
# There are 3 iterations of the loop.
Code: Select all
(dolist ((x y) '(x1 y1 x2 y2)) (use x y))
(dolist ((name age) '("John" 32 "Richard" 41 "Lucy" 37)) (use name age))
(dolist (a '(a1 a2 a3) b '(b1 b2 b3)) (use a b))
(dolist (p '((1 2) (3 4) (5 6)))
(dolist ((x y) p)
(use x y)))
Fanda ;-)