Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Racket macro for expanding code

I want to be able to write:

(nota E2 82)

instead of:

(define E2
  (network ()
           [sunet <= sine-wave 82]
           [out = (+ sunet)]))

I know I can do this using macros and tried to write this:

(define-syntax (nota stx)
  (syntax-case stx ()
    [(nota x) #'(network ()
                         [sunet <= sine-wave x]
                         [out = (+ sunet)])]))

But I get this error:

nota: bad syntax in: (nota E2 82)
like image 770
Theodor Berza Avatar asked Feb 07 '23 23:02

Theodor Berza


1 Answers

The simplest solution would be

(define-syntax-rule (nota x y)
  (define x
    (network ()
             [sunet <= sine-wave y]
             [out = (+ sunet)])))
like image 64
uselpa Avatar answered May 16 '23 10:05

uselpa