Array access and paths
[1/3] from: dankelg8::cs::man::ac::uk at: 18-May-2001 15:21
On Tue, 15 May 2001, Joel Neely wrote:
> ... (And, of course, I'll be the first to cheer if REBOL 3.0
> turns out to be wonderful for array-based numerical computation.
> However, it will take changes BOTH in performance AND notation
> before that happy state arrives.)
I think this is the single most annoying thing about REBOL.
Dealing with matrices etc is a nightmare!!
I think there are a few problems with paths.
At first, they look like a replacement for array indexing in other
languages, but the fact that they only support a limited way of getting
values is a big annoyance.
Here is an example:
list: [A 0 B 5 C 0 D 0]
Say I want to change the number 5 following the B to 6.
It's easy to read this number:
>> list/B
== 5
Or more generally:
>> idx: 'B
== B
>> list/:idx
== 5
So far it looks very good.
But then, try changing this value!
>> change at list 'B 6
does not work.
>> change next find list 'B 6
Not very nice.
Another example:
I want to get a function from an array:
>> func-array: reduce [a: func [x][]]
== [func [x][]]
>> f: :func-array/1
** Script Error: 1 is missing its x argument
** Near: f: :func-array/1
Gisle
[2/3] from: cyphre:volny:cz at: 18-May-2001 17:00
> I think this is the single most annoying thing about REBOL.
> Dealing with matrices etc is a nightmare!!
>
I don't think so. Have a look at REBOLek's rebsite %matrix.r script... realy
nice and fast vector graphics example using matrices!
> Here is an example:
> list: [A 0 B 5 C 0 D 0]
<<quoted lines omitted: 11>>
> >> change at list 'B 6
> does not work.
'at needs as a second parameter index not word...
you can try this:
change at list index? next find list 'b 6
or
poke list index? next find list 'b 6
but I'd prefer your solution above...
> >> change next find list 'B 6
> Not very nice.
<<quoted lines omitted: 5>>
> ** Script Error: 1 is missing its x argument
> ** Near: f: :func-array/1
try:
probe pick :func-array 1
or
probe first :func-array
have fun,
Cyphre
[3/3] from: joel:neely:fedex at: 18-May-2001 12:44
Hi, Gisle,
Gisle Dankel wrote:
> I think there are a few problems with paths...
>
> Here is an example:
>
> list: [A 0 B 5 C 0 D 0]
>
...
> >> idx: 'B
> == B
> >> list/:idx
> == 5
>
Another land mine not to step on if you take that last approach
is this: the type of the value in IDX actually makes a difference
in what the / means. If, as in your example, IDX is set to a word,
then
list/:idx
is (almost) equivalent to
select list idx
but if IDX is set to an integer, then
list/:idx
is equivalent to
pick list idx
instead. (This also means that using integers as "symbolic keys"
is problematic -- a pain in the neck.)
I said "(almost) equivalent" above because of this situation
>> idx: 'E
== E
>> list/:idx
** Script Error: Invalid path value: E
** Where: halt-view
** Near: list/:idx
>> select list idx
== none
in which throwing an error and returning NONE are *not* IMHO
equivalent behavior.
-jn-
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted