* Don't Unquote Me
@ 2022-10-14 4:03 jgart
2022-10-14 6:59 ` (
0 siblings, 1 reply; 6+ messages in thread
From: jgart @ 2022-10-14 4:03 UTC (permalink / raw)
To: Guix Help
Are `unqote`, `quote` and `unquote-splice` functions after they get
desugared from their reader macro representation?
I just know how they work but never thought to think about this before...
paren hugs,
jgart
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Don't Unquote Me
2022-10-14 4:03 Don't Unquote Me jgart
@ 2022-10-14 6:59 ` (
2022-10-14 18:38 ` jgart
0 siblings, 1 reply; 6+ messages in thread
From: ( @ 2022-10-14 6:59 UTC (permalink / raw)
To: jgart, Guix Help
On Fri Oct 14, 2022 at 5:03 AM BST, jgart wrote:
> Are `unqote`, `quote` and `unquote-splice` functions after they get
> desugared from their reader macro representation?
Nope; they're special built-in forms like ``lambda'' and ``define''.
-- (
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Don't Unquote Me
2022-10-14 6:59 ` (
@ 2022-10-14 18:38 ` jgart
2022-10-14 19:32 ` (
2022-10-15 15:05 ` Akib Azmain Turja
0 siblings, 2 replies; 6+ messages in thread
From: jgart @ 2022-10-14 18:38 UTC (permalink / raw)
To: (; +Cc: Guix Help
On Fri, 14 Oct 2022 07:59:14 +0100 "(" <paren@disroot.org> wrote:
> On Fri Oct 14, 2022 at 5:03 AM BST, jgart wrote:
> > Are `unqote`, `quote` and `unquote-splice` functions after they get
> > desugared from their reader macro representation?
>
> Nope; they're special built-in forms like ``lambda'' and ``define''.
So, they are ordinary functions defined in guile?
Or by built-ins you mean that they are implemented in C?
I'll read through the guile source code a bit later ;()
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Don't Unquote Me
2022-10-14 18:38 ` jgart
@ 2022-10-14 19:32 ` (
2022-10-14 23:40 ` Philip McGrath
2022-10-15 15:05 ` Akib Azmain Turja
1 sibling, 1 reply; 6+ messages in thread
From: ( @ 2022-10-14 19:32 UTC (permalink / raw)
To: jgart; +Cc: Guix Help
On Fri Oct 14, 2022 at 7:38 PM BST, jgart wrote:
> > Nope; they're special built-in forms like ``lambda'' and ``define''.
>
> So, they are ordinary functions defined in guile?
>
> Or by built-ins you mean that they are implemented in C?
>
> I'll read through the guile source code a bit later ;()
They are fundumental forms. You cannot define ``quote'' et al in terms of any
other feature. Just like there's no way to implement ``lambda'' in Guile,
because ``lambda'' is a fundumental form. So yes, they will be implemented in
C as part of the Guile core.
-- (
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Don't Unquote Me
2022-10-14 19:32 ` (
@ 2022-10-14 23:40 ` Philip McGrath
0 siblings, 0 replies; 6+ messages in thread
From: Philip McGrath @ 2022-10-14 23:40 UTC (permalink / raw)
To: jgart, help-guix; +Cc: Guix Help, (
[-- Attachment #1: Type: text/plain, Size: 4305 bytes --]
On Friday, October 14, 2022 3:32:55 PM EDT ( wrote:
> On Fri Oct 14, 2022 at 7:38 PM BST, jgart wrote:
> > > Nope; they're special built-in forms like ``lambda'' and ``define''.
> >
> > So, they are ordinary functions defined in guile?
> >
> > Or by built-ins you mean that they are implemented in C?
> >
> > I'll read through the guile source code a bit later ;()
>
> They are fundumental forms. You cannot define ``quote'' et al in terms of
> any other feature. Just like there's no way to implement ``lambda'' in
> Guile, because ``lambda'' is a fundumental form. So yes, they will be
> implemented in C as part of the Guile core.
>
Well, `quasiquote`, `unquote`, and `unquote-splicing` can straightforwardly be defined as macros in a simpler core language that provides `quote`. That's how they are implemented in Racket. You can find the source, which is fairly close to portable Scheme, in:
--8<---------------cut here---------------start------------->8---
less $(guix shell racket-minimal -- racket -e '(display (collection-file-path "qq-and-or.rkt" "racket/private"))')
--8<---------------cut here---------------end--------------->8---
The only reason the implementation is a bit verbose is that is at quite an early step in building `racket/base` from the primitive `#%kernel` language understood by the core compiler and runtime system: the same file contains the implementation of `let`.
(Similarly, you need one of `lambda` or `case-lambda` to be primitive, but not necessarily both.)
The situation with `quote` is a bit trickier because `quote` encompasses a few different features. In practice, most languages in the Scheme family choose to implement `quote` as a primitive syntactic form (including Racket [1]), but many of its features, even those that seem quite magical, could be implemented as derived constructs with a sufficiently expressive macro system. For example, here's a portable implementation of the part of `quote` which creates a symbol corresponding to some syntactic identifier:
--8<---------------cut here---------------start------------->8---
#!r6rs
(import (rnrs))
(define-syntax quote-symbol
(lambda (stx)
(syntax-case stx ()
((_ id)
(identifier? #'id)
#`(string->symbol #,(symbol->string (syntax->datum #'id)))))))
(write (quote-symbol hooray))
--8<---------------cut here---------------end--------------->8---
You could get the right allocation behavior either by relying on "The Guaranteed Optimization Clause of the Macro-Writer's Bill of Rights"[2] or by using a macro system that provides functions like `syntax-local-lift-expression`[3].
The implementation above relies on the base language having a built-in notion of string literals, which feels a little like cheating because we typically explain the concept of literals in terms of `quote`. Indeed, in `#lang racket/base`, the expression:
"hooray"
expands to:
(#%datum . "hooray")
which then expands to:
(quote "hooray")
where the expander introduces `#%datum` with the lexical context of `"hooray"` to provide languages a means of hygienically interposing on the meaning of literal data. In other words, self-quoting literals are not primitive in Racket.
For some deep thoughts along these lines, I highly recommend this mailing list post by Ryan Culpepper, who designed Racket's `syntax-parse`: https://groups.google.com/g/racket-users/c/HaSmcTN0SA4/m/1XYa-mL5AgAJ
Returning to the original question, regardless of all of the above, you can tell that `quote` et al. can't be functions, primitive or derived, because of how evaluation works in Scheme-like languages. As an example, consider the expression:
(quote (hello world))
If `quote` were bound to a function, to evaluate that expression, we would need to first evaluate `hello` and `world` and then apply the value of `hello` to the value of `world`. We'd then apply the value of `quote` to the result.
Obviously that doesn't work: an essential aspect of `quote` is that it doesn't evaluate its subform.
-Philip
[1]: https://docs.racket-lang.org/reference/syntax-model.html#%28part._fully-expanded%29
[2]: https://www.youtube.com/watch?v=LIEX3tUliHw
[3]: https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._syntax-local-lift-expression%29%29
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Don't Unquote Me
2022-10-14 18:38 ` jgart
2022-10-14 19:32 ` (
@ 2022-10-15 15:05 ` Akib Azmain Turja
1 sibling, 0 replies; 6+ messages in thread
From: Akib Azmain Turja @ 2022-10-15 15:05 UTC (permalink / raw)
To: jgart; +Cc: (, Guix Help
[-- Attachment #1: Type: text/plain, Size: 849 bytes --]
jgart <jgart@dismail.de> writes:
> On Fri, 14 Oct 2022 07:59:14 +0100 "(" <paren@disroot.org> wrote:
>> On Fri Oct 14, 2022 at 5:03 AM BST, jgart wrote:
>> > Are `unqote`, `quote` and `unquote-splice` functions after they get
>> > desugared from their reader macro representation?
>>
>> Nope; they're special built-in forms like ``lambda'' and ``define''.
>
> So, they are ordinary functions defined in guile?
>
> Or by built-ins you mean that they are implemented in C?
>
> I'll read through the guile source code a bit later ;()
>
I think this type of questions should go to guile-user list.
--
Akib Azmain Turja
Find me on Mastodon at @akib@hostux.social, and on Codeberg (user
"akib").
This message is signed by me with my GnuPG key. Its fingerprint is:
7001 8CE5 819F 17A3 BBA6 66AF E74F 0EFA 922A E7F5
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-10-15 15:24 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-14 4:03 Don't Unquote Me jgart
2022-10-14 6:59 ` (
2022-10-14 18:38 ` jgart
2022-10-14 19:32 ` (
2022-10-14 23:40 ` Philip McGrath
2022-10-15 15:05 ` Akib Azmain Turja
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).