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

Re: Re: LOGO-L> (turn a list);butitem



That's right there is a side effect with poprandom and pick&remove, the original
list is turned. 
If the goal is to continue picking randomly other items, it is not a inconvenient.


For me turn is a ground piece to build other things with it.

Here a better turn to use as tool for kids. 

to turn :l [:n 1 + random  count :l]
repeat  :n [make "l lput first :l bf :l ]
op :l
end


With default it acts just as previous turn, turning randomly; with a value for :n
it turns the list for :n
position.

show (turn [a b c d] 2)
[c d a b]


About butitem, what do you thing for that:

to butitem :n :l
op filter [not  # = :n]:l
end

; and for butitems

to butitems :itemlist :l
op filter [not memberp # :itemlist] :l
end

;  And to be complete,  then add  items.

to items :itemlist :l
op filter [memberp # :itemlist] :l
end

I like the symetry of items and butitems .

Regards.

P-A Dreyfuss




 




>That's similar to what my BUTITEM did.
>It shifted things over until the item you want removed
>is at the head and pops it off and returns the left and
>right list.
>
>But your solution also has the side effect of changing
>the order of the list. If I read it correctly.
>
>Your solution is clever though.
>You could rotate the wheel back before you output
>if the side effect is not desired. Which is by the way
>what the popping out of the recursive call does.
>
>Dreyfuss Pierre-Andre wrote:
>> 
>> Here is a solution based of the circular shift of the list.
>> 
>> Make a wheel with your list then turn the wheel an
>> pick the element at the head.
>> 
>> to  turn :l
>> repeat  1 + random count :l [make "l lput first :l bf :l ]
>> op :l
>> end
>> 
>> turn uses only repeat and make which should be in any logo.
>> 
>> Turn just return the list with random circular permutation.
>> pick the first element for use and continue with the rest (bf ) of the list.
>> 
>> ; So build poprandom (If you have pop in library)
>> 
>> to poprandom :nameoflist
>> make :nameoflist turn thing :nameoflist
>> op pop :nameoflist
>> end
>> 
>> ; Or the same with basic primitives.
>> 
>> to pick&remove  :nameoflist
>> make :nameoflist turn thing :nameoflist
>> localmake "picked first thing :nameoflist
>> make  :nameoflist bf thing :nameoflist
>> op :picked
>> end
>> 
>> You can work with first and butfirs.
>> As in this example.
>> 
>> to printrandom :l
>> if emptyp :l [stop]
>> make "l  turn :l
>> print first :l
>> printrandom bf :l
>> end
>> 
>> And now your dream :
>> 
>> to shuffle :l [:l2 []]
>> if emptyp :l [op :l2]
>> make "l turn :l
>> op (shuffle bf  :l  fput first :l  :l2)
>> end
>> 
>> Shuffle returns a list with the elements randomly shuffled.
>> 
>> butitem is a good tool to put in the library
>> 
>> If you like turn you can find a better name for it,
>> I don't speak english very well.
>> 
>> Regards
>> 
>> P-A Dreyfuss.
>> 
>> >I hope there is an easy explanation, but I can't find it!  I have tried
>> 
>> >every combination of likely commands I can think of, to no avail.
>> >
>> >I have a list with 11 words in it; each is the name of a procedure.  I am
>> 
>> >trying to pick one of these words at random and then eliminate it from the
>> 
>> >list.  (At a certain button click, all of the words can be restored to the
>> 
>> >list.)  But all I can manage to do is either run through the list in the
>> 
>> >same order as originally entered, eliminating the first (or last) each time
>> 
>> >(using butfirst or butlast), or select randomly without eliminating any
>> 
>> >words and sometimes have the same word get chosen repeatedly.  How can I
>> 
>> >select a word randomly and then place that word at the beginning or end
>> of
>> >the list so it can be eliminated?  Or if this is not possible, is there
>> 
>> >some handy way of entering the list in a newly scrambled order each time
>> a
>> >button is clicked?  Does it help to put the list into a text box?
>> >
>> >Thanks in advance,
>> >Wendy Petti
>> >Washington International School
>> >wap3@cornell.edu  or comp3@wis.edu
>> 
>> >
>> >
>> >---------------------------------------------------------------
>> >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.
>> 
>> >
>> 
>> Free web-based email, Forever, From anywhere!
>> http://www.mailexcite.com
>> ---------------------------------------------------------------
>> 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.
>
>-- 
>===============================================================
>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.
>




Free web-based email, Forever, From anywhere!
http://www.mailexcite.com
---------------------------------------------------------------
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