anything
2021-2-24 13:42:44

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?


samth
2021-2-24 14:10:49

It’s new in 8.0


anything
2021-2-24 15:25:31

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 [...]))


soegaard2
2021-2-24 15:27:37

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.


anything
2021-2-24 15:34:19

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?


soegaard2
2021-2-24 15:35:01

(with-syntax ([(name …) (list ’a ’b ’x)]) …)


soegaard2
2021-2-24 15:37:08

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.


anything
2021-2-24 15:37:48

Nice! I’m definitely interested. Thank you! I’ll try it right now.


anything
2021-2-24 16:12:08

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.


soegaard2
2021-2-24 16:12:31

I appreciate that.


samth
2021-2-24 17:18:46

@soegaard2 is there a canonical url for your tutorial?


soegaard2
2021-2-24 17:19:47

Not yet. I think, it’ll end up on http://racket-stories.com\|racket-stories.com .


yilin.wei10
2021-2-24 18:32:24

Ah sorry, let me be more clear; I was asking whether you wanted it for internal or external structs/functions.