hectometrocuadrado
2021-6-17 15:25:48

I want to do a macro helper that returns a positive integer. Suppose that function has to return the integer n. What is the best option, n or #’n?


soegaard2
2021-6-17 15:30:03

A syntax transformer must return a syntax object. You can do something like: #lang racket (require (for-syntax syntax/parse)) (define-syntax (add1 stx) (syntax-parse stx [(_add1 n:integer) ; compute output value (define n+1 (+ (syntax->datum #'n) 1)) ; turn the value into syntax (with-syntax ([n+1 n+1]) #'n+1)])) (add1 41)


hectometrocuadrado
2021-6-17 15:35:18

The problem is I want a procedure (in fase 1) that I will use to do a macro. Specifically, I want to calculate the length of a syntax object (where its datum is a list)


soegaard2
2021-6-17 15:36:06

There is a syntax-length ready to use in …


hectometrocuadrado
2021-6-17 15:36:15

really?


soegaard2
2021-6-17 15:36:34

unstable/syntax


soegaard2
2021-6-17 15:36:57

Maybe (length (syntax->list stx)) is better?


hectometrocuadrado
2021-6-17 15:37:48

It is what I was looking for. Thank you!