[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LOGO-L> QUESTION ON CONDITIONAL OUTPUTS



>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


---------------------------------------------------------------
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