[REBOL] Re: REBOL Enhancement Proposals (REPs)
From: joel:neely:fedex at: 26-Sep-2001 2:48
Hi, Allen and Geza and all,
Allen Kamp wrote:
> I would find that REP handy, particularly when dealing with
> REBOL/Command and the blocks it returns .
> ["username" "userpass"]
>
> e.g
> config: context [user: pass: none offset: 0x0 color: grey]
> insert db-port [
> {SELECT User, Pass FROM Clients WHERE ClientID = 3}
> ]
> set [config/user config/pass] pick db-port 1
>
> This is more using the "c-struct" fashion as you mention, but
> when dealing with a lot of fields, I will make less errors
> when dealing with named elements from an object (or block)
> rather than trying to remember their index numbers to pick
> them from a block.
>
Good point. I was also interested whether anyone would mention
the old classic:
>> fee == "fee"
>> fie == "fie"
>> set [fee fie] reduce [fie fee] == ["fie" "fee"]
>> fee == "fie"
>> fie == "fee"
as an argument for a "multiple assignment" pattern without use
of extra names.
Anyway... Here's my quick, sleep-deprived hack on the subject;
I'm sure it can be improved, especially in the error-handling
area! (Ladislav? You're really skillful at such things...)
a: make object! [ b: make object! [ c: "abc" ] ]
d: make object! [ e: "de" ]
f: "something"
bp: [a/b/c d/e f]
pset: function [
pp [block!] vv [block!]
][
x actions
][
x: make block! length? pp
actions: reduce [
path! [append/only x to-set-path first pp]
lit-path! [append/only x to-set-path first pp]
set-path! [append/only x first pp]
word! [append/only x to-set-word first pp]
get-word! [append/only x to-set-word first pp]
lit-word! [append/only x to-set-word first pp]
set-word! [append/only x first pp]
]
while [not empty? pp] [
switch/default type? first pp actions [
make error! append "Unexpected type: " mold pp
]
pp: next pp
either empty? vv [
append x none
][
append x first vv
vv: next vv
]
]
do x
exit
]
which behaves as follows:
>> do %pset.r
>> source a source d print f
a:
make object! [
b:
make object! [
c: "abc"
]
]
d:
make object! [
e: "de"
]
something
>> pset bp ["yes" "no" "maybe"] source a source d print f
a:
make object! [
b:
make object! [
c: "yes"
]
]
d:
make object! [
e: "no"
]
maybe
>> pset bp [1] source a source d print f
a:
make object! [
b:
make object! [
c: 1
]
]
d:
make object! [
e: none
]
none
Feedback/corrections/improvements welcomed!
> See some past REPs at http://www.rebolforces.com/archive/rep/
>
OBTW, Allen, in case no-one has said so recently...
Thanks very to you and to Chris for all your work in
making REBOL Forces such a useful (and usable!) resource
to the REBOL community! Three cheers!
-jn-
--
All I ask is a chance to prove that money can't make me happy.
-- John Alan Belli
joel+dot+neely+at+fedex+dot+FIX+PUNCTUATION+com