Every time I can’t delete the first element of a list in lisp (I.e. del x[0] in the python sense) I get annoyed with racket.
The reason I look past it is because the benefits are so good that they outweigh the annoyances. I wouldn’t trade it away.
Hmm, maybe a marriage between Gerbil and J -> Jerbil!
I've been a fan of Gambit for a long time too. Love to see it being utilized this way.
$ pil +
: (cdr '(1 2 3))
-> (2 3)
:(Sorry for not being clearer to begin with. I realized as I was falling asleep that it would cause some confusion.)
Isn’t this just the difference between mutable and persistent data structures?
x = [42, 99]
y = x
del x[0]
y[0] ; 99
This is impossible in traditional Lisp, and it’s the source of many of my frustrations. It’s why you can write an algorithm to destructively modify a list at any point — except index zero. The head of the list is the thing that’s used as a reference to the list. This doesn’t happen in Python; it’s why you can have empty arrays set to x and y, push a value onto x, and see it at y.I think there is less confusion about this kind of thing with Clojure, where a preference for immutable persistent data structures is strongly stated in the language design. So the persistent nature of lists and other data structures is fore grounded, and there is no confusion over why the equivalent of "del x[0]" is not supported.
Most of the time I try to get rid of variable names so it seems somewhat strange to invent more than one pointing to the same data structure in RAM, but I'm a simple person that gets confused easily.
(defun vector-delete! (vector index)
"Delete the element at INDEX from the given VECTOR.
Destructively modifies the vector.
The vector must have a fill-pointer.
This is not thread-safe, use at your own risk.
Examples:
(let* ((x (make-array 4 :fill-pointer 4 :initial-contents '(1 2 3 4)))
(y x))
(vector-delete! x 0)
y)
;; => #(2 3 4)"
(declare (type (Integer 0 *) index)
(type Vector vector))
(assert (array-has-fill-pointer-p vector))
(let ((l (length vector)))
(assert (< index l))
(let ((removed-element (aref vector index)))
(loop :for i :from (1+ index) :below l
:do
(setf (aref vector (1- i))
(aref vector i)))
(decf (fill-pointer vector))
removed-element)))
(Granted, it could be done in 6 lines of code, but I'm already cringing at not providing a continuation when calling it with an out-of-bounds index)I noticed this about Norvig's toy Lispy:
It implements cdr as mylist[1:]
So if you recurse on a list with cdr, then you will get mylist[1:] mylist[2:] ... mylist[n:], which is a quadratic algortihm
Ordered data types are core to computers actually: arrays, heck even the memory itself. I always thought the list to be the most fundamental construct, but outside the neat world of computer, the real world is mostly unordered. Order is artificial, is indeed often not a given.
Has this been actually true in the last, say, two decades? Or is just a thin veneer to make your highly concurrent machine look like a PDP-11? Right now order seems to be somewhat important only when it comes to cache optimization: if you stick thing that belong together close to each other you end up with fewer cache misses.