A comment to Carl's blog
[1/13] from: hallvard::ystad::oops-as::no at: 20-Oct-2004 23:54
Hi, list,
About http://www.rebol.net/blog/carl.html#section-5
Here's Carl's exemple:
data: [10 20 30]
n: 3
This shorthand for accessing elements in blocks is added to rebol version 2.5.55:
data/:n: 150
But then: is it absolutely clear that this should mean
poke data n 150
Couldn't it just as well mean:
n: 150
pick data n
i.e. with the form
:n:
which should be evaluated first, :n or n: ?
This might be a dumb question, but I don't see that this is all that clear. Elucidate
me!
A copy of this email is sent via http://www.rebol.com/contacts.html.
HY
[2/13] from: Izkata::Comcast::net at: 20-Oct-2004 17:41
OMG whoops sorry about that I had meant to
respond then accidentally tried to click "Reply" twice...
It looks to me like -
data: [10 20 30]
n: 3
data/:n
does the exact same thing as "pick data n",
but with less typing, and that "data/2: n" is the same as
poke data 2 n
with less typing..
I wouldn't think these are the only differences though,
and note that the example with 'poke you can use a
variable for the index, but there seems like maybe one
way works faster than another..
Oh and I got an error when I tried "data/:n: 150"
[3/13] from: chalz:earthlink at: 20-Oct-2004 22:14
Personally, I am extremely pleased with these alterations to path forms.
(FYI, it's actually http://www.rebol.net/blog/carl.html#section-6 ).
On the point of:
data/:n: 150
It would appear to me that the way this works would be more like:
n: 4
poke data n 150
As for the statement:
>> Couldn't it just as well mean:
>> n: 150
>> pick data n
I don't see that being the case. To me, it wouldn't make sense to
operate that way, even. Just as
data/:n
returns the value of 'data at 'n, this new format is assigning the value
to 'n in 'data. I mean, I see the way you're talking, but combining symbols
like paths and colons in REBOL has always been handled completely
differently; data/:n: 150 means poke data n 150, because they didn't want it
to mean pick data (n: 150). *shrugs*
And oh, it shouldn't work yet. It's coming in version 2.5.55. Current
version for download is 2.5.6 according to the site. Patience. :)
[4/13] from: antonr:lexicon at: 21-Oct-2004 16:38
Well, I agree it is a bit ambiguous,
but if you think that rebol operates
left to right, then you can see that
the get-word :n happens before the set-word n:
The second possible meaning:
I imagine if it was wanted that way, you could
be able to write:
data/:(n: 150 'n)
or
data/(150)
since you already know the value of n
or know how to calculate n.
I don't see it's very useful to set 'n just to
be used as a temporary value in a path.
However, it got me thinking...
Perhaps temporary variables could be used further down
the path. ie.
data/(n: 150)/(n + 1)
is equivalent to:
data/150/151
Another idea is perhaps if data is a block which contains
a name/value pair, then you could access 'name inside the
parens. eg:
data: [index 3 a b c d e]
data/(index + 2)
;== c
or
data: [header 4 index 3 a b c d e]
data/(header + index)
;== c
Just some ideas.
Anton.
[5/13] from: ammon::johnson::gmail::com at: 21-Oct-2004 0:14
Interesting comments Anton, however, I can't see how any of this could work...
data/:(n: 150 'n)
Here you have a Get-Paren. What's a Get-Paren? Parens are
automatically evaluated....
data/(index + 2)
The equivelant to that would be...
pick data index + 2
since index wasn't given a value then it would throw an error.
Here's how I see this new path notation being used...
data: [Bob Hope "1234 Hope St."]
firstname: 1
lastname: 2
address: 3
data/:firstname: 'John
data/:lastname: 'Doe
data/:address: "4321 Doe St."
It is mostly to obtain a little more clarity in your code. Compare
the above with this...
data: [Bob Hope "1234 Hope St."]
data/1: 'John
data/2: 'Doe
data/3: "4321 Doe St."
The ability to use a Get-Set-Word in a path was actually one of my
first feature requests when I started using REBOL, as was the ability
to put a paren in the path. Now that is one really powerful feature.
;-) Simple examples simply don't show how much clarity these features
can provide in your code. Start doing some extensive block work with
it and I think that you will be amazed at how clear your code is...
HTH
~~Ammon ;~>
On Thu, 21 Oct 2004 16:38:57 +1000, Anton Rolls <[antonr--lexicon--net]> wrote:
> Well, I agree it is a bit ambiguous,
> but if you think that rebol operates
<<quoted lines omitted: 61>>
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
--
Enjoy!!
~~Ammon ;~[)
~Sui Generis~
[6/13] from: mgaya::conselldemallorca::net at: 21-Oct-2004 10:27
Hi, list,
From de console:
>> system/version
== 2.5.55.3.1
>> data
== [10 20 30]
>> n: 2
== 2
>> data/2
== 20
>> data/:n
== 20
>> data/(n)
== 20
>> data/(n: 3)
== 30
>>
I like the new feature!
Miquel.
-----Mensaje original-----
De: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]] En nombre de
Hallvard Ystad
Enviado el: mi=E9rcoles, 20 de octubre de 2004 23:55
Para: [rebolist--rebol--com]
Asunto: [REBOL] A comment to Carl's blog
Hi, list,
About http://www.rebol.net/blog/carl.html#section-5
Here's Carl's exemple:
data: [10 20 30]
n: 3
This shorthand for accessing elements in blocks is added to rebol version 2.5.55:
data/:n: 150
But then: is it absolutely clear that this should mean
poke data n 150
Couldn't it just as well mean:
n: 150
pick data n
i.e. with the form
:n:
which should be evaluated first, :n or n: ?
This might be a dumb question, but I don't see that this is all that clear. Elucidate
me!
A copy of this email is sent via http://www.rebol.com/contacts.html.
HY
[7/13] from: alain:goye:free at: 21-Oct-2004 10:16
----- Original Message -----
From: "Miquel Gay=E0" <[mgaya--conselldemallorca--net]>
To: <[rebolist--rebol--com]>
Sent: Thursday, October 21, 2004 10:27 AM
Subject: [REBOL] Re: A comment to Carl's blog
> Hi, list,
> From de console:
<<quoted lines omitted: 15>>
> I like the new feature!
> Miquel.
I would too, but where can I find a version (2.5.55.3.1) where it works ?
Is it only available in rebol/cmd, or in some beta I could not find ?
Alain.
[8/13] from: SunandaDH::aol::com at: 21-Oct-2004 5:41
Alain:
> I would too, but where can I find a version (2.5.55.3.1) where it works ?
> Is it only available in rebol/cmd, or in some beta I could not find ?
www.rebol.net
Then click "Interim Builds for Developers"
Sunanda
[9/13] from: mgaya::conselldemallorca::net at: 21-Oct-2004 12:54
Go to: http://www.rebol.net/builds/
Miquel
-----Mensaje original-----
De: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]] En nombre de
Alain Goy=E9
Enviado el: jueves, 21 de octubre de 2004 10:16
Para: [rebolist--rebol--com]
Asunto: [REBOL] Re: A comment to Carl's blog
----- Original Message -----
From: "Miquel Gay=E0" <[mgaya--conselldemallorca--net]>
To: <[rebolist--rebol--com]>
Sent: Thursday, October 21, 2004 10:27 AM
Subject: [REBOL] Re: A comment to Carl's blog
> Hi, list,
> From de console:
<<quoted lines omitted: 15>>
> I like the new feature!
> Miquel.
I would too, but where can I find a version (2.5.55.3.1) where it works ?
Is it only available in rebol/cmd, or in some beta I could not find ?
Alain.
[10/13] from: antonr::lexicon::net at: 22-Oct-2004 2:58
They are ideas for possible future implmentation.
See comments interspersed:
> Interesting comments Anton, however, I can't see how any of this
> could work...
>
> data/:(n: 150 'n)
>
> Here you have a Get-Paren. What's a Get-Paren? Parens are
> automatically evaluated....
That's right. The paren is evaluated first, and the result
could be combined with the colon to become a get-word.
Or that's the idea, anyway. Perhaps a get-paren! datatype
would need to be created to support that idea, and maybe not.
> data/(index + 2)
>
> The equivelant to that would be...
>
> pick data index + 2
>
> since index wasn't given a value then it would throw an error.
In this, my next idea, it gets the value from "context" or block
specified by that level of the path. A more complex example:
data: [sub [felafel 16 flatbread 1 ... ]]
data/sub/(felafel + 4)
which would access the 20th element of data/sub.
I repeat, they are just ideas. Obviously they
don't work now, but all the good stuff we are
getting now started off just as ideas too.
Note that I haven't thought of any really good uses
for the above ideas yet, but they may occur to me
later.
Anton.
[11/13] from: hallvard:ystad:oops-as:no at: 21-Oct-2004 23:47
Dixit Anton:
>Well, I agree it is a bit ambiguous,
>but if you think that rebol operates
>left to right, then you can see that
>the get-word :n happens before the set-word n:
Well, rebol operates left to right, yes. But :n: still would have to be treated as one
single word, not as one character appearing in two different words. (Afterall n: is not
the word 'n and then a colon, it is a set-word!, and so this would have to be a something-word
too. Someone in this thread called it a get-set-word. Why not?) I just wanted to point
out that it is ambiguous.
Once this is becomming part of a standard and is being used, however, I agree it won't
be ambiguous anymore. I like the feature, and I have wanted something like this before.
Come to think about it, posting this as a comment directly to Carl maybe was a bit hasty...
HY
[12/13] from: rotenca:telvia:it at: 22-Oct-2004 0:02
Hi,
> data/:n: 150
> But then: is it absolutely clear that this should mean
<<quoted lines omitted: 5>>
> :n:
> which should be evaluated first, :n or n: ?
Can be seen in this way:
the expression
data/:n:
is a set-path!, because it ends with ":"
This set-path! is formed by 2 items:
1) data (word!)
2) :n (get-word!)
The final ":" is part of the set-path!, while the first ":" is part of the
last item of the set-path!
---
Ciao
Romano
[13/13] from: moliad::aei::ca at: 21-Oct-2004 23:31
I'm just happy its finally in there... I've needed these on countless occasions... yippe...
but using this means my code will only work on very latest releases... so it wont be
completely portable... :-(
but for non api stuff, I'm very happy.
-MAx
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted