Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using keyword symbols as slot-descriptors in DEFSTRUCT #58

Open
arbv opened this issue Mar 20, 2019 · 0 comments
Open

Using keyword symbols as slot-descriptors in DEFSTRUCT #58

arbv opened this issue Mar 20, 2019 · 0 comments
Labels

Comments

@arbv
Copy link
Member

arbv commented Mar 20, 2019

From https://groups.google.com/d/msg/cormanlisp/_qB2KC4Nw5Q/Sgv6xoZ0CQAJ

I suspect using keyword symbols as slot-descriptors in defstruct doesn't meet HyperSpec and outcome is undefined.
I was trying it as I have a list of keyword symbols I was thinking of using to create a structure with them as slot names.

Corman Lisp handles this except for initializing the the slots when making instances. Setf to slot later works.

e.g.
;; Corman Lisp 3.1 (Patch level 2)
(defstruct book :title :pages)
BOOK
(setq book1 (make-book :title "hoho" :pages 190))
#S( BOOK :TITLE :TITLE :PAGES :PAGES )
book1
#S( BOOK :TITLE :TITLE :PAGES :PAGES )

(book-p book1)
T
(book-title book1)
:TITLE
(setf (book-title book1) "hihi")
"hihi"
(book-title book1)
"hihi"

SBCL initializes as might be expected or hoped for, but with warnings

This is SBCL 1.4.14, an implementation of ANSI Common Lisp.

  • (defstruct book :title :pages)
    STYLE-WARNING: slot name of :TITLE indicates possible syntax error in DEFSTRUCT
    STYLE-WARNING: slot name of :PAGES indicates possible syntax error in DEFSTRUCT
    BOOK

  • (setq book1 (make-book :title "hi" :pages 190))
    ; in: SETQ BOOK1
    ; (SETQ BOOK1 (MAKE-BOOK :TITLE "hi" :PAGES 190))
    ;
    ; caught WARNING:
    ; undefined variable: BOOK1
    ;
    ; compilation unit finished
    ; Undefined variable:
    ; BOOK1
    ; caught 1 WARNING condition
    #S(BOOK :TITLE "hi" :PAGES 190)

  • book1
    #S(BOOK :TITLE "hi" :PAGES 190)

  • (book-p book1)
    T

  • (book-title book1)
    "hi"

  • (setf (book-title book1) "hihi")
    ; in: SETF (BOOK-TITLE BOOK1)
    ; (THE BOOK BOOK1)
    ;
    ; caught WARNING:
    ; undefined variable: BOOK1
    ;
    ; compilation unit finished
    ; Undefined variable:
    ; BOOK1
    ; caught 1 WARNING condition
    "hihi"

  • book1
    #S(BOOK :TITLE "hihi" :PAGES 190)

What do you think of Corman Lisp behavior?

Cheers
Nigel

@arbv arbv added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant