[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about how to check a symbol is bound
From: |
Alaric Snell-Pym |
Subject: |
Re: Question about how to check a symbol is bound |
Date: |
Wed, 28 Jun 2023 11:57:36 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 |
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/
OpenPGP_signature
Description: OpenPGP digital signature
- Question about how to check a symbol is bound, Pan Xie, 2023/06/23
- Re: Question about how to check a symbol is bound, Shawn Wagner, 2023/06/23
- Re: Question about how to check a symbol is bound, Pan, 2023/06/23
- Re: Question about how to check a symbol is bound, Peter Bex, 2023/06/23
- Re: Question about how to check a symbol is bound, Pan Xie, 2023/06/23
- Re: Question about how to check a symbol is bound, Lassi Kortela, 2023/06/23
- Re: Question about how to check a symbol is bound, Peter Bex, 2023/06/23
- Re: Question about how to check a symbol is bound, Thomas Chust, 2023/06/23
Re: Question about how to check a symbol is bound, Kon Lovett, 2023/06/23