I’m trying to use define-syntax-parse-rule for the first time. The https://docs.racket-lang.org/syntax/Defining_Simple_Macros.html#%28form._%28%28lib._syntax%2Fparse%2Fdefine..rkt%29._define-syntax-parse-rule%29%29\|documentation says it comes from syntax/parse/define, but the program #lang racket/base
(require syntax/parse/define)
define-syntax-parse-rule
blows ; c:\sys\tolcom\current\eth\rpc3\macro8.rkt:3:0: define-syntax-parse-rule: unbound identifier
; in: define-syntax-parse-rule
I’m running Racket 7.9 BC. > (version) “7.9” What’s up?
It’s new in 8.0
In terms of macros, my knowledge is essentially just define-syntax-rule. I wrote the following macro, which defines a procedure whose name is given by the macro user. For example, (define-method x) defines a procedure called x. It works. Now that I have this macro that works as intended, I’d like to loop through a list of symbols and have each of these symbols become identifiers like x. I don’t know how to do that. What is the recommended approach? (define-syntax-rule (define-method name)
(define (name #:server [server default-network] . args)
(define rq (put-id (make-method-jsexpr 'name) (new-id)))
(when (not (null? args))
(hash-set! rq 'params args))
(define rp (post server #:json rq))
(define js (response-json rp))
js))
rpc.rkt> (define-method x)
rpc.rkt> x
#<procedure:x>
My list of symbols is present at run-time in a procedure called list-of-methods-sym. (It doesn’t have to be this way. I can rewrite it to anything.)
(define (list-of-methods-sym)
'(web3_clientVersion
web3_sha3
[...]))
If you have the symbols at runtime - then they are not available at compile time - and that means, you can’t use the names in a macro.
That makes sense. I think I can define this method at compile time by using define-syntax-rule once again #lang racket/base
(define-syntax-rule (list-of-methods-sym) (list 'a 'b 'c))
But how would I go from a symbol ’a to an identifier a at compile time?
(with-syntax ([(name …) (list ’a ’b ’x)]) …)
If you are interested, I am interested in feedback on a macro tutorial. I think section 6 and 7 covers what you looking into now.
Nice! I’m definitely interested. Thank you! I’ll try it right now.
I’m gonna need to read it from scratch and this will take me more time. I’ve read the first sections once and I really liked it, but trying to read sections 6 and 7 right now offered some difficulty, so I will start over and see what happens. I’ll give you a report of what I find.
I appreciate that.
@soegaard2 is there a canonical url for your tutorial?
Not yet. I think, it’ll end up on http://racket-stories.com\|racket-stories.com .
Ah sorry, let me be more clear; I was asking whether you wanted it for internal or external structs/functions.