Comments on: New Path Forms in Version 2.5.55
REBOL Technologies

Comments on: New Path Forms in Version 2.5.55

Carl Sassenrath, CTO
REBOL Technologies
18-Oct-2004

Article #0025
Main page || Index || Prior Article [0024] || Next Article [0026] || Post Comments || Send feedback

Paths are a shorthand form for refining (specifying more detailed) references to values. Among other things, paths are often used for series ("array") element references. For example:

data: [10 20 30]
print data/2
data/2: 200

If you need to access the data using a variable, the preferred method was to use the non-shorthand (functional) forms:

n: 3
print pick data n
poke data n 300

Of course, people don't like typing that much, so they normally write:

print data/:n

Which means the same thing: use the value of n as the index (ie. don't use the n as a symbol, which is allowed in associative accesses).

That's fine, but the problem was that the equivalent SET (assignment) form was not allowed. This line returned an error:

data/:n: 150

However, that shorthand form has been added to 2.5.55. It can come in handy.

Another form that was suggested by Ladislav Mecir, a professor at the Technical University of Liberec, is to allow computation within the index (as you would find in many other languages). For example, if you want to access:

pick data n + 1

You can write the shorthand:

data/(n + 1)

Remember to include the spaces within the paren expression. This is a standard REBOL expression.

The SET form of this is also allowed:

data/(n + 1): 100

means the same as:

poke data n + 1 100

But, the path form is not as efficient (in memory or in performance) as the PICK and POKE forms.

Of course, you're not limited to simple numerical index paths. You can also do associative paths (SELECT), function refinements, etc. (Although, the benefit of these forms is not that clear.

>> now/(to-word "date")
== 18-Oct-2004/10:33:07-7:00

All of these forms are supported now in 2.5.55. If you are interested, please test these new forms. Changes were made at the lexical scanner and interpreter core, so it is possible that new bugs may appear.

Post Comments

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

CS-0025


Comment:


 Note: HTML tags allowed for: b i u li ol ul font p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 25-Nov-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code