Joel's technical essay/challenge
[1/2] from: lmecir:geocities at: 7-Oct-2000 9:51
Hi,
I recently suggested my Rt (Referentially transparent) function, but
overlooked, that Joel wanted to have the first element of the path to be an
object (or a general Rebol value), not a Rebol word. Here is my next trial:
rt: func [
{
a referentially transparent way
to invoke a path on a given object/function/something
Usage:
rt [[object 'function 'refinement1 ...] arg1...]
}
[catch]
blk [block!]
] [
do function [] [result1 result2 something] [
throw-on-error [
result1: do/next first blk
something: first result1
result2: append copy ['something] reduce second result1
do head change/only copy blk to path! result2
]
]
]
; Warning - although it seems to work, it is untested against the GC bug!
; (and my personal guess is, that it wouldn't survive)
; Joel's examples:
bunchanums: [3 1 35 8 4 5 52 42 19 13 32 43 81 2 6 34 46]
tally: make object! [
tot: 0
zero: does [tot: 0]
up: func [/by n [number!]] [tot: tot + either by [n] [1]]
down: func [/by n [number!]] [tot: tot - either by [n] [1]]
now?: does [tot]
]
; example #1:
use [evens odds] [
evens: make tally []
odds: make tally []
foreach num bunchanums [
rt [[either even? num [evens] [odds] 'up 'by] num]
]
print ["evens:" evens/now? " odds:" odds/now?]
]
{
Result:
evens: 226 odds: 200
}
; example #2:
use [diffs] [
diffs: make tally []
foreach num bunchanums [
rt [[diffs either even? num ['up] ['down] 'by] num]
]
print ["net sum:" diffs/now?]
]
{
Result:
net sum: 26
}
Regards
Ladislav
[2/2] from: joel::neely::fedex::com at: 7-Oct-2000 9:57
Hi, Ladislav,
Thanks for the update...
[lmecir--geocities--com] wrote:
> rt: func [
> {
<<quoted lines omitted: 17>>
> ; Warning - although it seems to work, it is untested against the GC bug!
> ; (and my personal guess is, that it wouldn't survive)
I'm going to be off-line for a few days, but if no-one else has had
a chance to test this, I'll try to do so when I return to wired
status.
-jn-
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted