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

Re: LOGO-L> eliminating items randomly from a list



> There is BUTFIRST, BUTLAST but no BUTITEM

That's a good idea!  I'll add that to the library.

I still think, though, that there's a place for the original EXTRACT.
The thing is, part of the purpose of lists, as opposed to arrays, is
to enable writing programs without having to think about auxiliary
numeric variables that are irrelevant to the problem you're trying to
solve.  In this case, if you want to choose one of a bunch of options,
you don't care about the option's *position* in the menu, and you
shouldn't have to take note of the position in your program.  That's
why PICK is so popular.

If EXTRACT seems too complicated, here's an alternative:

to pick.and.remove :listname
localmake "which 1 + random length thing :listname
localmake "result item :which thing :listname
make :listname butitem :which thing :listname
output :result
end

To use it you'd say

? make "choices [a b c d e f]
? print pick.and.remove "choices
d
? show :choices
[a b c e f]

The only difficulty about it is remembering to use the name of the
list, rather than the list itself, as the input.  But this is already
the situation with Berkeley Logo library procedures such as PUSH and POP.

The name's too long, of course; any suggestions?

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