freenode/#lisp - IRC Chatlog
Search
2:54:17
didi
Is there a straighter way of changing the cdr of each cons of a list of cons than: (mapcar (lambda (x) (cons (car x) (change (cdr x)))) list-of-cons) ?
3:03:19
didi
|3b|: I still want a new list. I just don't want to call (cons (car x) ...). I want to only change the cdr of conses.
3:03:21
|3b|
if CHANGE is a function, or you don't want to modify structure of input lists, then probably not
3:31:52
pjb
didi: clhs 3.6 For list traversal operations, the cdr chain of the list is not allowed to be destructively modified.
3:32:28
pjb
didi: this doesn't prevent you to implement your own iteration, mutating the cdr as you want. But you have to think about what you are doing!
3:48:26
pjb
(let ((loc (acons :o 1 (acons :t 2 (acons :t 3 nil))))) (dolist (cons loc loc) (setf (cdr cons) 0))) #| --> ((:o . 0) (:t . 0) (:t . 0)) |#
3:49:24
pjb
Now, if you insist on a HOF, use mapc: (let ((loc (acons :o 1 (acons :t 2 (acons :t 3 nil))))) (mapc (lambda (cons) (setf (cdr cons) 0)) loc)) #| --> ((:o . 0) (:t . 0) (:t . 0)) |#
4:23:28
beach
You need to remind me of this. I am working on the CST-to-AST system, and I am notorious for having a hard time switching between different tasks.
4:25:17
pillton
Well, template-function and its relative specialization-store, are for solving problems similar to the problems you faced when implementing the CL sequence protocol.
4:26:10
stylewarning
pillton: did you see this kooky thing I wrote a few years ago? https://bitbucket.org/tarballs_are_good/parameterized-function
4:26:48
stylewarning
I don't think what I wrote is exactly matching the vision of what I wanted to write. But it worked ok enough for an efficient Lisp matrix library, even if the calling convention was verbose
4:32:59
pillton
stylewarning: This is an example: https://github.com/markcox80/specialization-store/blob/master/tests/standard-store-syntax-layer.lisp#L20