From: HiPhish <hiphish@posteo.de>
To: guile-user@gnu.org
Subject: A macro containing a mini-macro?
Date: Fri, 14 Sep 2018 00:04:04 +0200 [thread overview]
Message-ID: <2093628.1NtSHukUaa@aleksandar-ixtreme-m5740> (raw)
Hello Schemers,
I have written a small macro for writing test specifications:
(define-syntax test-cases
(syntax-rules ()
((_ title
(given (byte byte* ...))
...)
(begin
(test-begin title)
(call-with-values (λ () (open-bytevector-output-port))
(λ (out get-bv)
(pack given out)
(let ((received (get-bv))
(expected (u8-list->bytevector '(byte byte* ...))))
(test-assert (bytevector=? received expected)))))
...
(test-end title)))))
The idea is that I can specify a series of test cases where each case consists
of an object and a sequence of bytes which this object is to be serialized to:
(test-cases "Single precision floating point numbers"
(+3.1415927410125732 (#xCA #b01000000 #b01001001 #b00001111 #b11011011))
(-3.1415927410125732 (#xCA #b11000000 #b01001001 #b00001111
#b11011011)))
This works fine, but sometimes there is a sequence of the same bytes and it
would be more readable if I could write something like this:
((make-vector 16 0) (#xDC (16 #x00)))
instead of writing out 16 times `#x00`. This would require being able to make
a distinction in the pattern whether `byte` is of the pattern
byte
or
(count byte)
and if it's the latter construct a list of `count` `byte`s (via `(make-list
count byte)` for example) and splice it in. This distinction needs to be made
for each byte specification because I want to mix actual bytes and these "RLE-
encoded" byte specifications.
So I guess what I'm looking for is to have a `syntax-rules` inside a `syntax-
rules` in a way. Can this be done?
next reply other threads:[~2018-09-13 22:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-13 22:04 HiPhish [this message]
2018-09-13 22:24 ` A macro containing a mini-macro? rain1
2018-09-15 22:21 ` HiPhish
2018-09-29 0:28 ` Mark H Weaver
2018-09-29 0:58 ` Mark H Weaver
2018-09-29 7:37 ` Arne Babenhauserheide
2018-11-02 22:32 ` HiPhish
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://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2093628.1NtSHukUaa@aleksandar-ixtreme-m5740 \
--to=hiphish@posteo.de \
--cc=guile-user@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).