From: Blake Shaw <blake@sweatshoppe.org>
To: help-guix@gnu.org
Subject: Re: boiler plate generation with hygenic macros in guile
Date: Wed, 20 Jul 2022 23:57:46 +0000 [thread overview]
Message-ID: <CAKjmbcBOQ1P5=4Th7A4-j1DkhMtpqkCoJkgbO3OknP9rrpWSHA@mail.gmail.com> (raw)
In-Reply-To: <CAKjmbcB_VoK7hUmkS0TZXUTuTiVUp-HuSnZEGoce_fM=3TCoFw@mail.gmail.com>
Ah! sorry, let me begin again:
Right now I am working on a window manager extension system in Guile and
GOOPs, and I want to eliminate the boilerplate for generating class slots,
with a syntax-case macro like:
#+begin_example scheme
(define-syntax slot-machine
(λ (form)
(syntax-case form ()
((_ category quality value)
#'(let* ((sym (symbol-append category '- quality))
(set-sym! (symbol-append 'set- sym '!))
(get-sym (symbol-append 'get- sym))
(acc-sym (symbol-append 'acc- sym)))
(if (or (symbol? value) (string? value) (number? value))
(quasiquote (,sym #:init-value value
#:setter ,set-sym!
#:getter ,get-sym
#:accessor ,acc-sym))
(quasiquote (,sym #:init-form value
#:setter ,set-sym!
#:getter ,get-sym
#:accessor ,acc-sym))))))))
#+end_example
With this I can call (slot-machine 'inner 'color "green") to produce what
looks like an acceptable slot definition:
=> (inner-color #:init-value "#BF3D52" #:setter set-inner-color! #:getter
get-inner-color #:accessor acc-inner-color)
Indeed, if I define a class with this slot definition in place, it works
fine:
#+begin_example scheme
(define-class <dummy> ()
(inner-color #:init-value "#BF3D52" #:setter set-inner-color! #:getter
get-inner-color #:accessor acc-inner-color))
(describe <dummy>)
=> <dummy> is a class. It's an instance of <class>
Superclasses are:
<object>
Directs slots are:
inner-color
(No direct subclass)
Class Precedence List is:
<dummy>
<object>
<top>
Class direct methods are:
Method #<<accessor-method> (<dummy> <top>) 7f7b27e10ac0>
Generic: setter:acc-inner-color
Specializers: <dummy> <top>
Method #<<accessor-method> (<dummy>) 7f7b27e10b00>
Generic: acc-inner-color
Specializers: <dummy>
Method #<<accessor-method> (<dummy> <top>) 7f7b27e10b40>
Generic: set-inner-color!
Specializers: <dummy> <top>
Method #<<accessor-method> (<dummy>) 7f7b27e10b80>
Generic: get-inner-color
Specializers: <dummy>
#+end_example
But if I try to use `slot-machine` inside a class definition i'm out of
luck:
(define-class <dummy> ()
(slot-machine 'inner 'color "green"))
=> While compiling expression:
Syntax error:
socket:7257:0: source expression failed to match any pattern in form
(define-class-pre-definition ((quote inner) (quote color) "green"))
I have tried to remedy this ina number of ways, using datum->syntax,
quasisyntax/unsyntax, make-variable and by defining a new syntax-case macro
to define classes, all without luck.
This is actually a recurring theme with my experience with Guile, working
on a project, needing to generate boilerplate, and then being unable to
find a result, so I figured its time I reach out to figure out what I'm
doing wrong in this situation.
Thanks for your help!
Best,
Blake
next prev parent reply other threads:[~2022-07-21 8:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 23:36 boiler plate generation with hygenic macros in guile Blake Shaw
2022-07-20 23:57 ` Blake Shaw [this message]
2022-07-25 12:35 ` Liliana Marie Prikler
2022-07-28 20:59 ` Blake Shaw
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKjmbcBOQ1P5=4Th7A4-j1DkhMtpqkCoJkgbO3OknP9rrpWSHA@mail.gmail.com' \
--to=blake@sweatshoppe.org \
--cc=help-guix@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).