3 ms·
>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 t
by 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.