Set on path values
[1/5] from: rudolf:meijer:telenet:be at: 12-Aug-2007 23:09
I like the ++ or incr function (incr: func ['val [word!]] [set val 1 + get
val]) which saves lot of writing when updating counters. My problem is that
many of my counters are not single words (which is what the set function
requires) but rather paths like suit-size/:hand/:suit (from a bridge program
-- the paths contain computed values, which could also have been written
/(hand)/(suit) etc.).
Does anyone have a suggestion for a one-argument function that will do
[suit-size/:hand/:suit: suit-size/:hand/:suit + 1] just like incr cnt would
do [cnt: cnt + 1]?
Thanks in advance
Rudolf Meijer
[2/5] from: btiffin::rogers::com at: 13-Aug-2007 0:01
Hi Rudolf,
Check out http://www.rebol.com/docs/words/wto-set-path.html
Cheers,
Brian
On Sunday 12 August 2007 17:09, Rudolf W. MEIJER wrote:
[3/5] from: gregg:pointillistic at: 12-Aug-2007 22:06
Hi Rudolf,
RWM> Does anyone have a suggestion for a one-argument function that will do
RWM> [suit-size/:hand/:suit: suit-size/:hand/:suit + 1] just like incr cnt RWM> would
do [cnt: cnt + 1]?
Something like this?
incr: func ['val] [do reduce [to set-path! :val 1 + do val]]
-- Gregg
[4/5] from: btiffin:rogers at: 13-Aug-2007 1:19
Hi again,
I just noticed Gregg also posted some good code.
I also reread that dictionary description...it's not very useful...
wto-set-path.html should be changed:
replace the line
ps-blues compose [(ps-blues) "light"]
with
do compose [(ps-blues) ["blue" "reblue" "navy"]]
for some actual functionality. I just picked random color names for
inside the block.
Cheers,
Brian
On Monday 13 August 2007 00:01, Brian Tiffin wrote:
[5/5] from: rudolf:meijer:telenet:be at: 13-Aug-2007 12:27
Hi Gregg,
Thanks! This worked first time around. I was apprehensive of the binding of
the expressions to be evaluated as path members, but this was fine. Is that
the magic of [do val]?
Rudolf
RWM> Does anyone have a suggestion for a one-argument function that will do
RWM> [suit-size/:hand/:suit: suit-size/:hand/:suit + 1] just like incr cnt RWM> would
do [cnt: cnt + 1]?
Something like this?
incr: func ['val] [do reduce [to set-path! :val 1 + do val]]
-- Gregg