[Home] [Back to Message Index]

Global SchoolNet - Automated Message Archive

LOGO-L> Thinking recursively




Yehuda Katz (yehuka@beitberl.beitberl.ac.il)
Fri, 24 Jan 1997 20:51:52 -0800

Dear Harrie,

The book arrived, thank you. I wonder what LCN (in "LCN Logo") stands
for. In any case, this Logo is different from any other Logo I have seen
yet.

About the problem you posted on this list, of using Logo to solving
expressions like:
[[3 * 2] + [4 * 3] + [5 + 4]] (equals 27)
[4 * 3 * [7 - 6 / 2]] (equals 48)

Here's a suggested recursive solution:

=========================================================
to main
ts ct
pr calculate expr
end

to calculate :expr
if 1=count :expr[op run first :expr]
op run(se first :expr item 2 :expr calculate bf bf :expr)
end

to expr
op[[3 * 2] + [4 * 3] + [5 + 4]]; =27
;op[4 * 3 * [7 - 6 / 2]] ; =48
end
==========================================================

This solution is a little bit clumsy, and I believe that it can be
somehow simplified.

I checked the problem in your book (p.68) and there must be a typo (an
extra single "open" squre before the "6 / 2" of the second expression).
That's what gave me some trouble before I had your book.

Please tell me if you need more clarifications.

Regards...
[[Yehuda]]
---------------------------------------------------------------
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.