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
4:35:14
pillton
It will work with declarations provided your implementation is supported in Bike's introspect-environment system.
4:41:01
stylewarning
I want to help out with initiatives to make high level efficient code easier to write in Lisp
4:42:07
Zhivago
I used to think that type based dispatch was a good idea, and then I realized that it's only really useful if your function doesn't have coherent semantics.
4:43:39
stylewarning
My problem is usually just specializing functions for all different manner numbers, like single and double floats
4:45:03
pillton
Zhivago: One of the premises is that it doesn't matter which specialization is executed.
4:45:41
Zhivago
pillton: Right, in which case you might as well dispatch off the representational decision.
4:46:19
Zhivago
pillton: It's just that CL doesn't expose fixnum, bignum, single-float, etc as classes.
4:48:46
stylewarning
Replacing an IF with some spectacular function dispatch mechanism requires good justification in my opinion, at least if I have my code reviewer hat on
4:49:14
Zhivago
I think that defining functions with discontinuities isn't too terrible using some kind of pattern matching, but it doesn't feel like it's really the right thing to be trying to do in terms of type.
4:50:58
pillton
You are comparing apples and oranges. Specializations are independently extensible. COND is not.
4:51:34
Zhivago
Sure, but does it make sense to independently extend a function in terms of semantic discontinuty?
4:52:33
pillton
Which is why one of the premises is that each specialization performs the "same" task.
4:53:48
pillton
This premise avoids the problem you find yourself in when dispatching on types that do not form a tree.
5:01:52
pillton
Maybe if you provided me with an example I could implement it for you and put it on the wiki?