Hi Joel,
You wrote,
> However, this all breaks down with functional options, because
>
> function-name/refinement-1 ...
>
> DOESN'T mean "invoke function-name, then apply refinement-1 to the
> result", and so on with additional refinements. In fact, I haven't
> been able to find any notation that implements the quoted phrase,
> except for
>
> dummyvariable: function-name ...
> dummyvariable/refinement-1 ...
I think what you are asking for can be achieved like this:
>> anon-refine: func [x 'r [word!] /local p][p: to-path reduce ['x r] p]
>> anon-refine now/time second
== 47
>> anon-refine now/time second
== 37
>> anon-refine [EMAIL PROTECTED] user
== KGD03011
>> anon-refine [EMAIL PROTECTED] host
== nifty.ne.jp
Note that using the tick on 'r in the argument definition allows you to pass
it bare words like SECOND USER and HOST without Rebol attempting to evaluate
them. When happens here is that 'p is assigned the path values x/second
x/user and x/host. When you evalute a word which holds a path, the path is
automatically applied (unless you use the get-word form :p), giving the
desired result.
This of course will only go one level deep refinement-wise. How about this?
&: func [
{Constructs and applies a path given a value and refinements}
value "value which takes refinements"
'path [word! refinement! block!] "a refinement or block thereof"
][
if not block? path [ path: append copy [] path ]
forall path [ change path to-word first path ]
insert path: head path 'value
path: to-path path
path
]
>> & now/time /second
== 36
>> & now/time second
== 8
>> & now [time second]
== 20
>> & [date 1999/9/26 time 12:01 e-mail [EMAIL PROTECTED]] [/e-mail/host]
== nifty.ne.jp
I definitely agree that the documentation on how paths and words behave is
sorely lacking. The best way I've found to experiment is to type various
expressions in blocks (too keep them from being evaluated immediately) and
use PICK (or REPICK) and TYPE? to look at them.
>> [ [EMAIL PROTECTED]/user ]
== [[EMAIL PROTECTED] /user] ; note the space that pops in
>> type? probe pick [ [EMAIL PROTECTED]/user ] 1
[EMAIL PROTECTED]
== email!
>> type? probe pick [ [EMAIL PROTECTED]/user ] 2
/user
== refinement!
>> type? probe pick [ this/is/a/path ] 1
this/is/a/path
== path!
>> length? pick [ this/is/a/path ] 1
== 4
>> type? probe repick [ this/is/a/path ] [1 1]
this
== word!
See you,
Eric
Latest version of REPICK:
repick: func [
{picks repeatedly}
block [any-block! any-function! object!]
indexes [block!]
][
foreach i reduce indexes [block: pick :block i]
:block
]