Arc Forumnew | comments | leaders | submitlogin
2 points by Jekyll 6165 days ago | link | parent

This behaviour is already standard in all lisps. Try: (with (a (list 1 2) b [ = (car _) 3]) (b a) a)

=>(3 2)

the list (1 2) is passed to function b, which modifies the car of the first cons cell, changing the original list.



2 points by cadaver 6164 days ago | link

I'm new to lisp/scheme/arc so this may not be an issue in practice, but what if you want to add a new pair to the beginning of the list?

The only way to do this would be to insert a new pair after the first, then copy the car from the first to the second, then set the first car as desired.

Unfortunately this does not work if you have references to this first pair in particular, because of its car, rather than because it is the beginning of the list;

-----

1 point by cadaver 6163 days ago | link

Now that I think of it, passing parameters by reference would not be useful in this case.

Passing lists (pairs) by reference simply means creating a level of indirection to where the address of the first pair is stored. However, in a running program, there can be an arbitrary number of such locations.

I think that the problem of lists, of which the sort order is significant and which may be modified in arbitrary ways, can only be solved by, a) having a global binding, that is, a global level of indirection that everyone uses, or b) using a pair, of which the cdr remains unused, or some other reference-object as a level of indirection.

I suppose this is where arrays come in.

-----

1 point by Jekyll 6162 days ago | link

My example wasn't exactly orthodox lisp style. Normally, you should explicitly set any variables you are manipulating, so you'd be writing: (= a (f a)) rather than relying side effects to set it for you (This is especially important when calling functions like sort). It's such a common idiom that in common lisp I have a ! macro to turn (! f a . b) into (setf a (f a . b)).

-----