bug#48712: (is-a? #nil <list>) --> #f (oop goops)

Maxime Devos <[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
I want to make sure some Scheme code using (oop goops) can be used
from elisp. The method I'm defining is something like this (overly
simplified):

;; TODO: Define a <mach-port> instead of working with raw integers?
(define-method (send-message! (msg <message-box>) (data <list>) (remote <mach-port>))
  [ write data to msg ]
  [ call mach_msg appropriately ])

I tested whether elisp's #nil is considered a <list>, apparently not:

(use-modules (oop goops))

(is-a? '() <list>) ;; #t
(is-a? '(a . ()) <list>) ;; #t
(is-a? #nil <list>) ;; #f, expected #t
(is-a? '(a . #nil) <list>) ;; #t

(class-of '()) ;; <null>
(class-of '(a . ())) ;; <pair>
(class-of #nil) ;; <boolean>, expected (a subclass of) <null>
(class-of '(a . #nil)) ;; <pair>

#nil is both a boolean, and an end-of-list object.
As such, it should be both <boolean> and <null> (and <list>).
But currently it is only <boolean>.

My untested suggestion:
Define a class <elisp-nil>, inheriting from <boolean> and <null>.
Define class_elisp_nil appropriately in libguile/goops.c and (oop goops).
In scm_class_of, adjust

    case scm_tc3_imm24:
      if (SCM_CHARP (x))
        return class_char;
      else if (scm_is_bool (x))
        return class_boolean;
      else if (scm_is_null (x))
        return class_null;
      else
        return class_unknown;

appropriately.

Greetings,
Maxime
signature.asc (application/pgp-signature, 260 B)
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYLCw2RccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7n3YAP4w3L7pOZGS3146cm0YC011l7Vp
P3mhAVThpReOhoVtxwEA9fMoo41+2UOJmI/IYTPXD9zrrhFNHrOBOn5D+RT3jA0=
=eoU1
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.