>Of course if you are careful, you can implement a tail-recursion algorithm
>which is not terribly more expensive than iteration. It will always be
>less efficient, though -- in your example you had to call two functions
>(do_stuff & butfirst) in each iteration, pass them arguments and return a
>value. And, in many cases, it will also be less clear and more error prone
>than a for-loop style iteration. When I see a Lisp/LOGO compiler which
>compiles your LOGO algorithm into something as efficient as your C
>algorithm, I will have to take my words back...
It's a known fact that recursion is, generally speaking, less efficient than
interative procedures.
If I were looking for efficient processor use (namely: using a high rate of
of processor cycles for a given task) I wouldn't be learning LOGO. (C would be
a much better choice).
I like LOGO, and recursion, and list processing, and property lists, and
template-based interation for their expressive power.
This thing got me really impressed:
-----
Here is a short but complete program in Berkeley Logo:
to choices :menu [:sofar []]
if emptyp :menu [print :sofar stop]
foreach first :menu [(choices butfirst :menu sentence :sofar ?)]
end
And here's how you use it. You type
choices [[small medium large]
[vanilla [ultra chocolate] lychee [rum raisin] ginger]
[cone cup]]
and Logo replies
small vanilla cone
small vanilla cup
small ultra chocolate cone
small ultra chocolate cup
small lychee cone
small lychee cup
small rum raisin cone
small rum raisin cup
small ginger cone
small ginger cup
medium vanilla cone
medium vanilla cup
medium ultra chocolate cone
medium ultra chocolate cup
...
------
Yesterday I used it to show every possible unification of:
[[OVERTABLE [x]] [CLEAR [y]]]
given the state:
show :estado
[[OVERTABLE [A]]
[OVERTABLE [C]]
[OVERTABLE [D]]
[OVER [D B]]
[CLEAR [B]]
[CLEAR [C]]
[CLEAR [D]]
[EMPTYHAND []]]
show posibleUnif :estado [[OVERTABLE [x]] [CLEAR [y]]]
[[[OVERTABLE [A]] [CLEAR [B]]]
[[OVERTABLE [A]] [CLEAR [C]]]
[[OVERTABLE [A]] [CLEAR [D]]]
[[OVERTABLE [C]] [CLEAR [B]]]
[[OVERTABLE [C]] [CLEAR [C]]]
[[OVERTABLE [C]] [CLEAR [D]]]
[[OVERTABLE [D]] [CLEAR [B]]]
[[OVERTABLE [D]] [CLEAR [C]]]
[[OVERTABLE [D]] [CLEAR [D]]]]
---------------------------------------------------------------
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