Page 1 of 1

[proposal] unification: ref for arrays

Posted: Mon Dec 02, 2013 8:41 pm
by hartrock
Regarding refs, lists and arrays behave similar, but not the same.
There seems to be a possibility for further unification.

This works for both:

Code: Select all

(setq l (sequence 1 10)
      a (array 10 l))
;;
;; Applying refs works for both lists and arrays:
(setq r (ref 5 l))
(l r)
(a r)
But getting a ref does only work for lists (see above); this does not work:

Code: Select all

> (ref 5 a)

ERR: list expected in function ref : (1 2 3 4 5 6 7 8 9 10)
What about having refs for arrays, too?

Then this would work, too:

Code: Select all

(setq r (ref 5 a))
(l r)
(a r)
The semantics of an array ref could/should be the same as for list refs.

Such unification would be good for functions operating on containers - being agnostic against the array/list difference.

Because there already is setf for arrays, I'm assuming that most machinery to get this done already exists.

Re: [proposal] unification: ref for arrays

Posted: Mon Dec 02, 2013 10:00 pm
by Lutz
In the big picture of things arrays are used rarely in newLISP, there are more a speed optimization for specific situations then anything else. I did it for apply and map because it was extremely cheap to implement, and like for some of the statistical functions, because there was a moderately, frequent use-case for them - at least in my work - and an easy way to share additional code required among those functions.

Doing it for ref, ref-all, set-ref, set-ref-all is much more involved and I just don't see people using it that much. Most of the time when I see people using arrays, I think, a list would have been as good or better. Like most requests made in this forum, it goes on a list and could be re-evaluated in the future.