[REBOL] Re: string to object - was: Ask
From: greggirwin:starband at: 28-Sep-2001 10:28
Hi Andrew,
<< This should do the trick and is a little safer:
probe get in get to-word "system" to-word "options"
>>
Yeah! That's what Ammon's function builds, on the fly, from a path.
<< Safer still is:
Words-Objects: reduce [
"System Options" system/options
"My unique object" make object! [m: 123]
"q" :quit
]
Thing: select Words-Objects ask "Please enter the name of an object?"
>>
Very cool! I had thought about this kind of approach but the goal will be to
dynamically access any object in the system. That would make this approach
rather difficult, wouldn't it? I mean, I'd have to build the block
initially, and then I'd have to update it periodically. I can see other
places, though, where it will be very useful. For example, I did something
similar when I needed to dynamically draw an arrow based on a compass
direction:
sign: func [value[number! money! time!]] [
if positive? value [return 1]
if zero? value [return zero]
if negative? value [return -1]
]
compass: context [
same: 0x0
S: 0x1
N: 0x-1
E: 1x0
W: -1x0
SE: 1x1
NW: -1x-1
NE: 1x-1
SW: -1x1
]
compass-direction: func [
"Returns the compass direction, as a pair, from point a to point b."
a[pair!] "The starting reference point"
b[pair!] "The ending reference point"
][
to-pair compose [(sign subtract b/1 a/1) (sign subtract b/2 a/2)]
]
; Hard-coded for 3 points (simple triangles) right now
fn-arw: func [color[tuple!] points /local result][
result: make block! 2
append result 'draw
append/only result compose [pen (color) fill-pen (color) polygon
(points/1) (points/2) (points/3)]
return result
]
arrows: context [
n: fn-arw black [8x0 3x16 13x16]
e: fn-arw black [16x8 0x3 0x13]
s: fn-arw black [8x16 3x0 13x0]
w: fn-arw black [0x8 16x3 16x13]
nw: fn-arw black [0x0 16x8 8x16]
ne: fn-arw black [16x0 0x8 8x16]
se: fn-arw black [16x16 0x8 8x0]
sw: fn-arw black [0x16 8x0 16x8]
]
arrow-map: reduce [
compass/same arrows/sw
compass/N arrows/n
compass/E arrows/e
compass/S arrows/s
compass/W arrows/w
compass/NW arrows/nw
compass/NE arrows/ne
compass/SE arrows/se
compass/SW arrows/sw
]
; Get an arrow definition from a compass direction
; select arrow-map direction
get-arrow: func [start[pair!] end[pair!]] [
select arrow-map compass-direction start end
]
There are two other blocks, similar to arrows and arrow-map that are used to
get the offset for a particular arrow so the point will always fall at a
target point rather than rotating around a center point.
--Gregg