On 23/06/2023 14:35, Kon Lovett wrote:
(symbol-value foo #f)
Error: unbound variable: foo

#;2> (symbol-value 'foo #f)
#f

(symbol-value foo #f) is asking for the symbol-value of the derefed variable 
`foo’

Does anybody have any tips for using symbol-value at macroexpansion time?

I am trying to port a library from chicken 4 to 5, that lets users write something along these lines (full details available on request, I'm trying to just extract and summarise the important parts here):

(define-custom-type foo ...some metadata...)

And then later:

(define-object-type bar ...list of fields and types...)

Eg:

  ;; A foo contains three strings
(define-custom-type foo string string string)

(define-object-type bar
  (field-1 foo)
  (field-2 some-other-type))

Now, the implementation of define-object-type needs to be able to examine the contents of the foo custom-type at macro expansion time (to give a bit more detail, this is a wrapper around a SQL database and it needs to know the structure of everything to pre-generate SQL queries, create table statements, and so on)

I've had partial success with making define-custom-type expand into a define-for-syntax that wraps a processed form of its metadata into a value and binds it to the symbol "foo", then making define-object-type find the type name symbols and call symbol-value on them - but this doesn't work if the type name is imported from a library. Even if I make the user write:

(define-object-type bar
  (field-1 name-of-library#foo)
  (field-2 name-of-other-library#some-other-type))

...even though calling symbol-value on those symbols at run time works just fine. It seems that the symbols imported into the environment at macro expansion time are handled differently in some way.

Is there a way to do what I want?

I'm also working on an alternate approach - where define-custom-type defines a macro that actually embeds the parts of the implementation of define-object-type that depend on the structure and make define-object-type invoke that macro as part of its expansion - but it's so inside out it makes my head hurt so I'm not 100% sure it'll be possible yet (at the very least, it might leave some string/list concatenation to run time, which is disappointing). And it's a sad violation of abstraction boundaries between define-custom-type and define-object-type. Hey ho.

PS: Hi everyone! I'm still alive!

--
Alaric Snell-Pym   (M0KTN neé M7KIT)
http://www.snell-pym.org.uk/alaric/

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to