
I saw sfri–19 mentioned earlier, and gregor. I only recently saw gregor. It looks nice. But I have all this other code that uses sfri–19. And then there is racket/date. I’m trying to figure out if gregor is something people really are using more and more, i.e., whether I should consider moving my code to gregor.

I now exclusively use gregor, so there’s one data point. :)

I’d say Gregor is considered the preferred choice in racket - but if you have to rewrite old code so you can use Gregor in new code that’s not good

@notjack I don’t know that I have to rewrite old code. I recognize the conflict between racket/date and gregor date, I have a bunch of stuff that uses srfi–19, and I want to keep adding to that code, which makes me wonder if I should tack, jibe or NOP.

Hello everyone, anyone here good with macros/ willing to offer some help and guidance?

& I have gone through some guides, but am stuck on a particular transformation.

@plotnus etiquette suggests just asking your question, and if anyone can/wants to answer, they will.

Given (defbitarray special-bits ( bit-a bit-b bit-c ))
how could we transform from :bits 'bit-a 'bit-b
to :bits (special-bits bit-a bit-b)
or better yet have it evaluate to :bits 3
for (define-syntax (foo stx)
(syntax-case stx ()
[(_ bit0 bit ...)
???]))

I’m not sure I understand your question. Where is :bits 'bit-a 'bit-b
appearing? At the top level of a module? Inside something else?

@lexi.lambda is is a field in a larger structure that will also need some define-syntax.

@lexi.lambda When I go through the major transformation this macro will be called for the :bits field. E.g. where make-list-of-stuff is the high level macro (make-list-of-stuff big-list
(name-of-a
:bits 'bit-a 'bit-b
:some-symbols 'symbol-a 'symbol-b
:some-key-value-list-pairs
('key-a 'value-a 'value-b 'value-c)
('key-b 'value-1 'value-2 'value-3
...
)
(name-of-b
more-data....
)
etc...
)
so this is just one piece of a larger puzzle

@plotnus It’s hard for me to understand what your constraints are without knowing the bigger picture, but maybe this will point you in the appropriate direction: #lang racket
(require (for-syntax syntax/parse
syntax/parse/class/local-value))
(define-syntax defbitarray
(syntax-parser
[(_ bits-name:id (bit-name:id ...))
#:with [bit-index ...] (build-list (length (attribute bit-name)) values)
#'(begin (define-syntax bit-name 'bit-index) ...)]))
(begin-for-syntax
(define-splicing-syntax-class bits-option
#:attributes [mask]
[pattern {~seq #:bits [{~var bit-name (local-value exact-nonnegative-integer?)} ...+]}
#:attr mask (apply + (map (λ (x) (expt 2 x)) (attribute bit-name.local-value)))]))
(define-syntax some-macro-that-uses-bits-option
(syntax-parser
[(_ bits:bits-option)
#`(quote #,(attribute bits.mask))]))
(defbitarray special-bits (bit-a bit-b bit-c))
(some-macro-that-uses-bits-option
#:bits [bit-a bit-b])
The program produces 3
as output.

Oh, and you’ll need to install the syntax-classes
package for syntax/parse/class/local-value
.

@lexi.lambda thank you. I’ll take a look :slightly_smiling_face: