Alice Community  

Go Back   Alice Community > Educators > Teaching with Alice

Reply
 
Thread Tools Display Modes
does a list contain an item?
Old
mullins
Guest
 
Status:
Posts: n/a
Default does a list contain an item? - 10-22-2007, 02:57 PM

Another request for trivia I can't seem to locate:

1. Create a list of objects
2. Add an if/else
3. Drag & drop the list onto the conditional...

Alice seems to offer to check whether the list contains a particular object, however it only appears to look at the last object in the list.

Am I misreading this? It is used for something else (number, strings, properties)? Or, is this a bug?

Searching a list to see if it contains an object is a nice classroom example, but students always think they're one up on me when they see this option.
   
Reply With Quote
bug fixes
Old
mullins
Guest
 
Status:
Posts: n/a
Default bug fixes - 11-17-2007, 12:48 PM

I assume that the lack of replies means this is indeed a bug, especially since lots of people read the post.

In case you were looking for a solution, I provide a work around as an example of writing a function to search a list for a specific object.
for all in order
if theObject = item from list parameter
return true
else
// do nothing
return false

This is also useful for discussing why I don't want to use for all together (assuming it was available).

Similarly, I use the buggy IEEERemainder and remove last element from a list as examples of extending the language with useful functions/methods.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.