It always concerns me that folks feel fewer lines of code is better. Avoiding sub expressions to clarify code is NO advantage. I also intentionally kept as much of his original code in tact so he could more easily see the primary difference. I also think someone should tackle understanding list manipulation (primarily a lesson in recursion) before moving into high level list manipulation functions such as MAP and friends. Excluding the turtle graphics recursive list processing is the HEART of Logo. It can be a difficult step for some but the reward of writing something like below for the first time should not be avoided. Augusto Chioccariello wrote: > > >However, here is a more logical approach. > > > >TO ADDLISTS :LIST1 :LIST2 > >; We know the answer to empty list thats easy > >IF EMPTYP :LIST1 [OP []] > >MAKE "A1 FIRST :LIST1 > >MAKE "A2 FIRST :LIST2 > >MAKE "S :A1 + :A2 > >; We have the answer for one pair (:s) now combine it with the > >; the answer for the rest and output it. > >OP FPUT :S ADDLISTS BF :LIST1 BF :LIST2 > >END > > > >The concept is almost like a math induction proof. > > 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 > > I must confess that I do find these little programming exercises relaxing, > it's a way to let my mind concentrate on details and turn off more > problematics thoughts. > > But if you have problems conceptualizing recursion, may be you need a > different approach before confronting "the challange of recursion". Here is > 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 > > I'd suggest reading Harvey's rationale for "avoiding recursion". Here is > Harvey's short description of his paper: > > Functional languages such as Logo and Scheme generally use recursion as > the main control mechanism, rather than iterative constructs such as > while and for. Many beginning programmers find the idea of recursion > difficult, and that gives these languages a bad reputation. Here I > suggest that the use of higher-order procedures can allow a wide range > of interesting programs to be written before the learner must confront > the challenge of recursion. > > "Avoiding Recursion" (in Learning Mathematics and Logo, Celia Hoyles and > Richard Noss, editors, MIT Press, 1992). > http://http.cs.berkeley.edu/~bh/noss.ps > > -- Augusto > > /// Dr. Augusto Chioccariello tel: +39 10 6475319 > /// Istituto Tecnologie Didattiche - CNR fax: +39 10 6475300 > /// e-mail: augusto@itd.ge.cnr.it -- =============================================================== George Mills email: mills@softronix.com http://www.softronix.com The www page contains some very powerful educational software. Our single most important investment is our kids. --------------------------------------------------------------- Please post messages to the Logo forum to logo-l@gsn.org. Mail questions about the list administration to logofdn@gsn.org. To unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
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