Well, here is a version of "addlists" that even avoids the use of make
(either global or local):to addlists :l1 :l2
if emptyp :l1 [op []]
op (fput sum first :l1 first :l2) addlists bf :l1 bf :l2
end<...>
Here isHello Augusto,
another way to achieve the same result (in UCBLogo) using Brian Harvey's
"map" higher-order procedure:to add2lists :l1 :l2
op (map [sum ?1 ?2] :l1 :l2)
end
There is an unavoided inconvenience with the high-order functions. It's the mysterious error messages you get while using them. Usually something like "RUN doesn't like ...", while no RUN is not visible anywhere inside the code. Try in your above example to write ?3 instead of ?2, and you get:
? doesn't like 3 as input in map1
[output combine (apply :map.template firsts :template.lists)
(map1 bfs :template.lists :template.number+1)]
This sort of message "frightens" the average user.
For *me*, the first procedure above is very readable, and so find it also my students (after gaining some experience and practice).
On the other hand, FOR is easy to understand, comes very handy, and doesn't produce obscure error messages.
Regards...
[[Yehuda]]
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home