Hi Anton

Good question. How does read-via work when parse-url is not a globally
defined variable? I thinkyou will find the answer very interesting.

The answer is that many functions in both Core and View are defined in the
context of objects, and some subset of them is then exported to the global
context for general use. This is the current method of encapsulating
functions and data. When modules come along this may change.

Here is a simple console example of the way this works:

>> ob: make object! [hidden-func: func [x][x * x] set 'sq func [y]
[hidden-func y]]
>> source sq
sq: func [y][hidden-func y]
>> sq 5
== 25
>> help hidden-func
No information on hidden-func (word has no value)
>>
>>probe ob
make object! [
    hidden-func: func [x][x * x]
]
>>
Because sq is defined in the object ob, it can use hidden-func or any other
object variable defined. The object spec block is executed at object
creation time. When words are defined by word: blabla, they are defined in
the context of the object. When they are defined with set, they are defined
in the next higher context level. So mult in this case is global, but it's
definition uses the hidden-func in ob. Notice the executed lines of code
which do not define an object var are not present after the object is
created.

Make sense?

-Larry

PS This approach can be nested at several levels.

----- Original Message -----
From: Anton <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 30, 2001 7:33 AM
Subject: [REBOL] 'parse-url - where defined?


> Hi,
>
> Looking at
> source read-via
>
> It uses 'parse-url in the second line of read-via's function body.
> Where does parse-url come from?
> On the console, parse-url has no value.
> How then, does read-via work?
>
> my system/version == 0.10.38.3.1
>
> >> parse-url
> ** Script Error: parse-url has no value.
> ** Where: parse-url
>
> >> source read-via
> read-via: func [
>     {Read a file via the cache. Returns binary. Failure returns error.}
>     url [url! file!]
>     /progress callfunc port-hand
>     /update "Force update from source site"
>     /local path file data purl loc-path
> ][
>     if file? url [return read url]
>     if none? purl: parse-url url [return none]
>     loc-path: rejoin [system/options/home/public "/" purl/host "/" any
> [purl/path ""]]
>     file: join loc-path purl/target
>     path: rejoin ["/" any [purl/path ""] purl/target]
>     either all [not update exists? file] [data: read/binary file] [
>         data: either progress [read-net/progress url :callfunc port-hand]
> [read-net url]
>         if data [
>             if not exists? loc-path [make-dir/deep loc-path]
>             write/binary file data
>         ]
>     ]
>     data
> ]
>
> Anton.
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>

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

Reply via email to