Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Text-List more help please

 [1/10] from: ammoncooke::yahoo::com at: 25-May-2001 15:01


hi, I need to be able to remove the selected item(line) from the list. Sorry for all these lame questions, I am new here & the REBlist seems to be the only way to find this stuff out. Thanks!! Ammon

 [2/10] from: gjones05:mail:orion at: 25-May-2001 16:59


From: "Ammon Cooke"
> I need to be able to remove the > selected item(line) from the list.
This example demonstrates one technique. Note that the item is only removed if only one is selected in this version. fix-slider: func [faces [object! block!]] [ foreach list to-block faces [ list/sld/redrag list/lc / max 1 length? head list/lines ] ] view layout [ txt "Select an item to delete, then click button" tl1: text-list 150x50 data ["apples" "oranges" "bananas" "pears" kiwi ] button "Delete" [ remove find tl1/data tl1/picked tl1/data: head tl1/data fix-slider tl1 show tl1 ] ]
> Sorry for all these lame questions, I am > new here & the REBlist seems to be the > only way to find this stuff out.
They are *not* lame questions, and you are right that the documentation is slim, and that the list is one of the few ways to find this sort of thing out. Happy VIDing. --Scott Jones

 [3/10] from: ammoncooke:yaho:o at: 25-May-2001 16:16


I came up with: fix-slider: func [faces [object! block!]] [ foreach list to-block faces [ list/sld/redrag list/lc / max 1 length? head list/lines ] ] view layout [ txt "Select an item to delete, then click button" tl1: text-list 150x50 data ["apples" "oranges" "bananas" "pears" kiwi ] button "Delete" [ remove tl1/lines fix-slider tl1 show tl1 ] ] Which also only deleted one item no matter how many where selected. I would additionally like to be able to reference the data in the list like an index. i.e. how do I know how many items are in the list? Can I access an item from an index number??
<snip> > > They are *not* lame questions, and you are right that the documentation > is slim, and that the list is one of the few ways to find this sort of > thing out. > > Happy VIDing. > --Scott Jones
</snip> Thanks!! Ammon

 [4/10] from: ammoncooke:ya:hoo at: 25-May-2001 16:37


I just discovered that your example works until I click on an item that is in the list multiple times. It then produces the same behavior that, logically, what I came up with should. The strange thing is that my example worked for a while & I didn't test it extesively to find it wasn't quite what I was looking for. I think I have answered my question as to how to find the total number of items in the list: tl1/lines Correct?? But that worries me because it seemed to be unpredictable somtimes returning the item that is selected, other times it would return the last item in the list. Thanks!! Ammon

 [5/10] from: gjones05:mail:orion at: 25-May-2001 17:57


From: "Ammon Cooke"
> Which also only deleted one item no > matter how many where selected. I would > additionally like to be able to reference the > data in the list like an index. i.e. how do I > know how many items are in the list? > Can I access an item from an index number??
This sample adds a label that reflects how many items are in the list. This label is initialized in the 'do block, which is run once upon evaluation. One can also select multiple items for deletion. I am unsure whether I understand what your last question is asking. fix-slider: func [faces [object! block!]] [ foreach list to-block faces [ list/sld/redrag list/lc / max 1 length? head list/lines ] ] view layout [ txt "Select items to delete, then click button" tl1: text-list 150x50 data ["apples" "oranges" "bananas" "pears" kiwi ] across txt "Items in list: " t1: txt 80 below button "Delete" [ foreach p tl1/picked [ remove find tl1/data p] tl1/data: head tl1/data fix-slider tl1 t1/text: to-string length? tl1/data show [tl1 t1] ] do [ t1/text: to-string length? tl1/data show tl1 ] ] ;;;;; --Scott Jones

 [6/10] from: ammoncooke:yah:oo at: 25-May-2001 17:50


Thanks, now I need to be able to convert that to an integer so I can do a for loop stopping at the length of the list. ;)) Now to fix the vaugeness of the last question I asked :))) Have you ever scripted with Perl?? If so, the values of an array are accessed from an index: $array[0] $array[1] $array[2] Is there a similar way to access data from a list with REBOL?? Thanks!! Ammon PS Is there absolutely nothing to gain by not declaring variables in REBOL or why don't I ever see anything about?

 [7/10] from: gjones05:mail:orion at: 25-May-2001 19:35


From: "Ammon Cooke"
> Thanks, now I need to be able to convert that to an integer so I can
do a
> for loop stopping at the length of the list. ;))
This expression returns an integer: length? tl1/data I changed it to a string so that it could be inserted into the text label. to-string length? tl1/data While REBOL offers a 'for loop, I can only remember using it one time. I have found 'foreach, 'forall, and 'forskip to be much more powerful and easier to use. If you need to process each item in the list, do what I did: use 'foreach. Example: fruits: ["apples" "oranges" "bananas" "pears" "kiwi"] foreach fruit fruits [print ["The length of the word" fruit "is" length? fruit]] Would a looping structure like this work?
> Now to fix the vaugeness of the last question I asked :))) Have you
ever
> scripted with Perl??
I hacked a Perl script once, does that count? :-) I'm slightly familiar with it.
> If so, the values of an array are accessed from an > index: > > $array[0] > $array[1] > $array[2] > > Is there a similar way to access data from a list with REBOL??
I guess my example above answers the question. Does it?
> PS Is there absolutely nothing to gain by not declaring variables in
REBOL
> or why don't I ever see anything about?
When you say "declaring a variable", are you meaning assigning a value to a variable, or are you meaning assigning a type to a variable? (or both?) I assume that what you are getting at is why don't you see more variable assignments in REBOL. Like why do this: ... remove find tl1/data p ... and not this: ... index: find tl1/data p remove index ... It can be done, if you wish, and for clarity, especially early in programming, this may help you see the flow of data. However, the ability to take advantage of REBOL's abilities in fucntional programming is what I like most about it. Most of the throw-away, temporary variables are no longer needed. The data in the code just "flows" along. It's like our spoken language itself: ideas hook together, and act upon each other in a kind of stream or flow. Like spoken languages, the REBOL way becomes very natural after a while, and then it will seem annoying to set up temporary variables in other languages. At least it does for me. But I will readily admit that it requires a paradigm shift in comparison to more strictly imperative languages like Pascal. No one doubts that Perl is a fine, powerful language. It is more C like in its characteristics, at least if I recall correctly. I am no expert on any of these concepts, but a useful reference that talks more about the difference between imperative programming versus functional programming can be found at the following link. Haskell is a functional language that is similar to REBOL in concept. Check it out when you have ten minutes. http://www.haskell.org/aboutHaskell.html
> Thanks!! > Ammon
You are welcome! --Scott Jones

 [8/10] from: ammoncooke::yahoo at: 28-May-2001 16:12


I need to be able to randomly select an item from the list if it is accessable like an index in a Perl array: #array[0] #array[1] #array[2] #array[3] with each [number] being a different item. Thanks Again!! Ammon

 [9/10] from: gjones05:mail:orion at: 28-May-2001 17:33


From: "Ammon Cooke"
> I need to be able to randomly select an item from the list if it is > accessable like an index in a Perl array:
<<quoted lines omitted: 5>>
> Thanks Again!! > Ammon
The following will pick an item at random each time it is evaluated: random/only ["apples" "oranges" "bananas" "pears" "kiwi"] So: view layout [ tl1: text-list data ["apples" "oranges" "bananas" "pears" "kiwi"] txt "Select items randomly with a click" button "Select" [t1/text: random/only tl1/data show t1] t1: txt 80 0.0.255 255.255.255 ] --Scott Jones

 [10/10] from: ammoncooke::yahoo at: 28-May-2001 17:03


Thanks!! I just need to get used to the REBOL 'way of thinking' Ammon

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted