Theodor Berza
Theodor Berza

Reputation: 583

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)

Upvotes: 4

Views: 97

Answers (2)

John Clements
John Clements

Reputation: 17203

Okay, that's just awful. You really shouldn't need to write this macro; there should be a form that supplies fixed inputs to a network.

In fact, there is. But... it's not documented, and it's not well named. It's currently called fixed-inputs, but I'm going to rename it as network-const, and document it.

Thanks for prompting me on this!

John

Upvotes: 3

uselpa
uselpa

Reputation: 18917

The simplest solution would be

(define-syntax-rule (nota x y)
  (define x
    (network ()
             [sunet <= sine-wave y]
             [out = (+ sunet)])))

Upvotes: 5

Related Questions