> thanks for your ideas and elaborations!
thank you for having created picolisp
> Personally, I must say that I am against using arrays
> in PicoLisp, and wrote it up a few years ago in:
Yes, I have read it. I agree more or less with it.
> Can you give me an example where you need a list with 65536 elements, in
> a Lisp program? Normally you would use some kind of tree to maintain
> larger data structures, and you example of using helper list does
> exactly that.
If I had a 65536 elements array at my disposal, the first thing I
would do is to couple it to the cute 'hash picolisp function (whose
output is 1..65536) in order to have very good hash tables. (I could
use binary trees instead, hash tables are simpler and a little faster,
binary trees are more powerful).
If one is interested in building virtual machines in picolisp, I think
that one needs arrays, to emulate flat memory above all, but as well
to execute the machine instructions efficiently by table dispatching.
> Besides this, technically your implementation looks good.
> It breaks the Lisp programming style though. You can't use the rich set
> of list-manipulation functions on arrays. To do anything interesting,
> you have to either fetch the whole array (or parts of it) into a list,
> or operate one by one by accessing individual elements. Very tedious.
I use lists for most tasks, as usual, it's only at very selected
places that I would reach for an array for random access.
> You have to take care of garbage collecting these arrays by yourself,
> i.e. to know when a given array is no longer needed. and this
> inconvenience alone destroys the possible advantage of an array.
Given a function markAll(CELL*) that marks all cons-cells reachable
from a given cell, we can just insert the following code in the
garbage collector marking phase, so that the contents of all arrays
can be protected from being sweeped.
for (int i=1; i<=current; i++) # thru each array
if (void **p=arrays[i]) # only if array hasn't been disposed of
for (int j=1; j<=size(p); j++) # thru each bucket
These 4 lines of code (plus the creation and disposing code) are the
price to pay (I think) for having arrays in picolisp.