Hi Brett,

Do-path really sounds good, so I decided to accept it, thanks. To your
second question. The Rebol paths are not referentially-transparent in Rebol,
e.g.

a/(1 + 1)

isn't a path in Rebol,

now/time/second

doesn't work as some of us would like it to, etc. It means, that Do-path is
referentially transparent as opposed to a direct Rebol path use.

do-path: function [
    {A referentially transparent way to invoke paths}
    [catch]
    block [block!]
] [head path stop] [
    path: either stop: find block first [/] [
        copy/part block stop
    ] [
        stop: [none]
        block
    ]
    if not empty? path [
        path: reduce path
        if not word? set/any 'head first path [change/only path 'head]
        if error? path: try [to-path! path] [
            throw make error! {Invalid path representation}
        ]
    ]
    do compose [(:path) (next stop)]
]

to-path!: function [
    [catch]
    path-block [block!]
] [path] [
    path: make path! length? path-block
    foreach element path-block [
        throw-on-error [
            if :element [insert/only tail :path :element]
        ]
    ]
    :path
]

{
    Example:

do-path [now 'time 'second]
a: [1 2 3]
do-path [a 1 + 1]
only: false
head do-path ['insert if only ['only] / tail a [4]]
only: true
head do-path ['insert if only ['only] / tail a [4]]
do-path [make object! [a: 14] 'a]

}
----- Original Message -----
From: Brett Handley <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, November 05, 2000 10:25 AM
Subject: [REBOL] Re: Accessing nested Blocks + search in blocks


> Hi Ladislav,
>
> This looks really useful.
>
> A more general use of the behaviour than that of my posts.
>
> But two things.
>
> The name. Why not something more accessible like invoke-path, do-path or
> whatever?
>
> Can you explain why the emphasis on referential transparency? Or put
another
> way, what is a non-referentially transparent way to invoke paths and how
> does that differ from your functions?
>
>
> Brett.
>


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to