4

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)
Theodor Berza
  • 573
  • 3
  • 12
  • 1
    Did you forget the `define`? – stchang Jan 20 '16 at 18:12
  • 2
    The reason you’ve gotten the “bad syntax” error is because `(nota x)` indicates your macro only takes a single “argument”, but you’ve given it two. As @stchang mentions, it looks like you want to add an extra argument and include the `define` in your expansion. – Alexis King Jan 20 '16 at 18:18

2 Answers2

5

The simplest solution would be

(define-syntax-rule (nota x y)
  (define x
    (network ()
             [sunet <= sine-wave y]
             [out = (+ sunet)])))
uselpa
  • 18,732
  • 2
  • 34
  • 52
3

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

John Clements
  • 16,895
  • 3
  • 37
  • 52
  • For future proofing this answer, can you link to the docs when you do? (And when the next version of Racket with it is released.) – Leif Andersen Jan 21 '16 at 21:34