Quoting in define-method and define-object
siiky 30 Jul 2025 10:32 UTC
Hi zilti and all,
I happened to try prometheus[0] (IUUC the CHICKEN egg on which this SRFI is based) recently.
[0]: https://wiki.call-cc.org/eggref/5/prometheus
And had a lot of trouble getting things done because of the implicit quoting of messages/slots in define-method/define-object; in part because I didn't properly RTFM, I must admit. Nonetheless, considering the section on "Private Messages", suggesting that it is possible to use arbitrary unique values as messages/slots, it's counterintuitive that both features do not work well together.
To make sure everyone is in on the problem, consider the following:
```
(define munch (list 'munch))
(define cookie (*the-root-object* 'clone))
; (1)
(cookie 'add-method-slot! munch
(lambda (self resend)
(display "This works") (newline)))
; (2)
(define-method (cookie munch self resend)
(display "This doesn't work") (newline))
(let ((my-cookie (cookie 'clone)))
(my-cookie munch))
```
(1) will work as expected. (2) is not even valid syntax -- the method is expected to be quoted; see the syntax-rules pattern:
```
(_ (obj 'message self resend args ...)
body1 body ...)
```
A similar problem affects define-object:
```
(define-object cookie (*the-root-object*)
((munch self resend txt)
(display txt) (newline)))
(let ((my-cookie (cookie 'clone)))
(my-cookie 'munch "This works")
(my-cookie munch "This doesn't work"))
```
In this case messages/slots are implicitly quoted, as per the corresponding syntax-rules implementation:
```
((_ o ((method-name . method-args) body ...)
slots ...)
(begin
(o 'add-method-slot! 'method-name (lambda method-args
body ...))
(define-object/add-slots! o slots ...)))
```
---
Enough of the problems. It would be great to have this SRFI, it would be even greater to have it ironed out.
We've discussed a little in #chicken already and my first suggestion was to drop the implicit quotes from both macros. This would make them work for everyone, even if in many scenarios (possibly most) an extra quote would be required in define-object (it's already required in define-method).
Another suggestion came from sjamaan, arguably a much better option: to add an implicit quasiquote. In this case, we do nothing extra to get an implicitly quoted symbol or what have you, but can unquote the messages/slots if needed:
```
(define-method (cookie ,munch self resend)
(display "This doesn't work") (newline))
(define-object cookie (*the-root-object*)
((,munch self resend txt)
(display txt) (newline)))
```
Thanks for reading thus far, ((cookie 'clone) munch)
siiky