Re: Keyword arguments in procedures specified in SRFIs
Marc Feeley 24 Jul 2019 13:26 UTC
> On Jul 24, 2019, at 8:34 AM, Lassi Kortela <xxxxxx@lassi.io> wrote:
>
>> I tried the following test in Gauche:
>> [...]
>> According to these tests, an uninterned symbol read from a port is never equal to another uninterned symbol with the same name, even if the references are embedded in the same data structure (here, a cons cell).
>
> Just confirmed that Gambit has the same interpretation as Gauche. Marc already hinted at this upthread:
>
>> Yes… but eq-ness is not preserved because a new uninterned symbol is generated for each one:
>>> (eq? '#:foo '#:foo)
>> #f
>
> Common Lisp doesn't preserve equality either:
>
> (setf gg (with-input-from-string
> (in (let ((g (gensym)))
> (with-output-to-string (out)
> (write (cons g g) :stream out))))
> (read in)))
>
> (car gg) ; => #:G3010
> (cdr gg) ; => #:G3010
> (eq (car gg) (cdr gg)) ; => NIL
>
> I had never realized that before.
>
> If it turns out that #: would be a good prefix for keywords, how hard would it be to change the uninterned symbol prefix in Gambit and Gauche? Do users rely on the semantics of #: symbols being inequal when read back in, considering that they probably can't do much with those symbols if equality of references to the same gensym within the same data structure are not preserved?
>
The #: prefix was chosen due to prior art (Common Lisp). It makes sense to preserve the compatibility for
- programmers with prior experience with CL
- prior documentation, manuals and books on CL
- interoperability with CL (write a datum from CL and read it from Gambit, and vice-versa)
- past ~10 years of use by Gambit users
It can be changed easily, but the reasons above prevent that.
By the way, the eq-ness in a datum can be preserved with write-shared…
> (let ((a (string->uninterned-symbol "foo"))
(b (string->uninterned-symbol "foo")))
(write-shared (list a b b))
(newline))
(#:foo #0=#:foo #0#)
Marc