3 ms·
> So you want eq, unless the object hasn't been mutated, in which case you want equal. Easy enough. The following example is in CHICKEN, a lisp I am more famili
by catnaroek 10y ago
> So you want eq, unless the object hasn't been mutated, in which case you want equal. Easy enough. The following example is in CHICKEN, a lisp I am more familiar with, but translation to Common Lisp should be simple:
I want the language to make it impossible to use eq on values. When I'm manipulating values, I don't care about their location in memory, and I don't want it to be possible to care.
> If it doesn't, you could always just create functions that return the immuatable. It's not fast or pretty, but it works.
This is actually even worse, because Common Lisp will gladly tell me two function objects are different, even if they are otherwise extensionally equal.
> No, it's not. Scheme does the best by having mutation separate from single assignment, but pushing immutability on everybody by default is crazy.
I said Racket for a reason.
> Which is why, save cons cells (which are bad enough), Racket doesn't do so. Observe:
`x` is a variable, not a value. The value 7 isn't being mutated, 7 is always 7, of course! What has changed is that the variable `x` now stands for a different value.
- qwertyuiop924 10y ago>I want the language to make it impossible to use eq on values. When I'm manipulating values, I don't care about their location in memory, and I don't want it to be possible to care. Oh. Well why didn't you say so? In SBCL: (unlock-package 'common-lisp) (fmakunbound eq) Note that this will probably break a ton of stuff. In Scheme: (set! eq? #f) >`x` is a variable, not a value. The value 7 isn't being mutated, 7 is always 7, of course! What has changed is that the variable `x` now stands for a different value. Hey, watch this! (define x '(hello world)) (set! x (cons 'goodbye (cdr x))) x =>(goodbye world)
- catnaroek 10y ago> Note that this will probably break a ton of stuff. To me, the correct way to interpret “It's possible. Just do this thing that breaks pretty much all existing code.” is “It's not possible.” And your solution still doesn't fix the lack of compound values. > Hey, watch this! (snippet) (0) I said Racket for a reason. (1) A better objection would've been using `set-car!` to replace "hello" with "goodbye" in-place. But Racket doesn't have `set-car!` or `set-cdr!`.
- qwertyuiop924 10y agoTo me, the correct way to interpret “It's possible. Just do this thing that breaks pretty much all existing code.” is “It's not possible.” And your solution still doesn't fix the lack of compound values. Oh, it just breaks stuff that uses eq. Which you didn't want anyway, right? >I said Racket for a reason. Last I checked, that's totally valid Racket. And it has the same effect as using set-car!.
- catnaroek 10y ago> Last I checked, that's totally valid Racket. And it has the same effect as using set-car!. No. There's an important difference. This is valid Scheme and Racket: (define x (list "hello" "world")) (define y x) (set! x (list "goodbye" "world")) ;; y is still (list "hello" "world") But this isn't valid Racket: (define x (list "hello" "world")) (define y x) (set-car! x "goodbye") ;; now y is (list "goodbye" "world") too Racket has a separate (dynamic) type of mutable cons cells, together with `set-mcar!` and `set-mcdr!` operations. In Racket, cons cells are bona fide compound values, but the object identity of an mcons cells is a primitive value.