Home   Archive   Permalink



How do I pick elements from a block using a string in Rebol?

Given this block
    
fs: [
usr [
    local [
     bin []
    ]
    share []
]
bin []
]
    
I could retrieve an item using a path notation like so:
    
fs/usr/local
    
How do I do the same when the path is a string?
    
path: "/usr/local"
find fs path ;does not work!
find fs to-path path ;does not work!

posted by:   AnonMouse     26-Feb-2013/12:21:41-8:00



Are you trying to do this?
    
     do "fs/usr/local"
    
R E B O L []
fs: [
     usr [
         local [
             bin []
         ]
         share []
     ]
     bin []
]
probe fs/usr/local
probe do "fs/usr/local"
probe do join "fs" "/usr/local"
halt
    
Output:
    
[
     bin []
]
[
     bin []
]

posted by:   Nick     26-Feb-2013/18:21:13-8:00



And just for fun:
    
select select fs to-word "usr" to-word "local"
    
:)

posted by:   Nick     26-Feb-2013/18:50:19-8:00



I use "do" for things like:
    
R E B O L [title: "Calculator"]
view layout [
     origin 0 space 0x0 across
     style btn btn 50x50 [append f/text face/text show f]
     f: field 200x40 font-size 20 return
     btn "1" btn "2" btn "3" btn " + " return
     btn "4" btn "5" btn "6" btn " - " return
     btn "7" btn "8" btn "9" btn " * " return
     btn "0" btn "." btn " / " btn "=" [
         attempt [f/text: form do f/text show f]
     ]
]
    
R E B O L [title: "Math Test"]
random/seed now
question: does [rejoin [random 10 " + " random 20]]
view layout [
     f1: field question
     text "Answer:"
     f2: field [attempt [
         alert either (to-integer f2/text) = (to-integer do f1/text)
             ["Yes!"]["No"]
         f1/text: question show f1 focus f2
     ]]
]

posted by:   Nick     26-Feb-2013/18:55:51-8:00



(Any time you want to evaluate or "execute" concatenated strings of code).

posted by:   Nick     26-Feb-2013/18:58:33-8:00



You could take the "do" dialect even farther in that last example:
    
R E B O L [title: "Math Test"]
random/seed now
question: [rejoin [random 10 " + " random 20]]
view layout [
     f1: field (do question)
     text "Answer:"
     f2: field [attempt [
         alert either (to-integer f2/text) = (to-integer do f1/text)
             ["Yes!"]["No"]
         f1/text: do question show f1 focus f2
     ]]
]

posted by:   Nick     27-Feb-2013/9:24:28-8:00



That really helps! Thank you Nick!

posted by:   AnonMouse     4-Mar-2013/15:27:05-8:00