Call by value but the value is two pointers
With push! from miscmacros you can cons onto that particular name whereas with mutate-cons! defined like this:
(define (mutate-cons! val lis) (set-cdr! lis (cons (car lis) (cdr lis))) (set-car! lis val))
You can change all instances of that particular list. Super dangerous.♥︎
Here, I’ll show you:
(let* ((abc '(a b c))
(abc2 abc)
(fish '(f i s h))
(fish2 fish))
(push! 'nope abc)
(mutate-cons! 'yeah fish)
(list abc abc2 fish fish2))
Returns this:
((nope a b c) (a b c) (yeah f i s h) (yeah f i s h))
That’s not a slag on push! which is often what you want. It’s a macro modifying what one particular name points to. Whereas mutate-cons! is a procedure that changes the actual underlying object.
Also mutate-cons! doesn’t work on the empty list. You can only push onto lists with at least one element. They need to be actual cons pairs.