2

I am writing a function called annotate that uses match-lambda -- often with recursive calls to annotate. Here is one of the pattern matches:

(`(lambda (,<param1> . ,<params>) ,<stmts>)
 `(CLOSURE ENV (,<param1> . ,<params>) (lambda (ENV) ,(map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))))

However, when this pattern is matched this is what returns:

'(CLOSURE
  ENV
  (x)
  (lambda (ENV)
    ((CLOSURE
      ENV
      (x y)
      (lambda (ENV) ((+ x y))))))
  #<void>)

Specifically I can't figure out where "void" is coming from. In fact, if I include the line:

,(displayln (map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>))))

it prints:

((CLOSURE ENV (x y) (lambda (ENV) ((+ x y)))))

notably without "void".

If someone could tell me what the problem is it would be greatly appreciated.

Thanks.

Eli Barzilay
  • 29,301
  • 3
  • 67
  • 110
Schemer
  • 1,635
  • 4
  • 19
  • 39

1 Answers1

2

The #<void> is the return value from displayln. Output functions in some implementations of Scheme and Racket usually return that when there is nothing meaningful to return.

Jeremiah Willcock
  • 30,161
  • 7
  • 76
  • 78
  • *Scheme* has unspecified results for output functions; it's *Racket* that returns this `#` value in this case. – Eli Barzilay Feb 27 '11 at 07:26
  • @Eli: Yes, I guess; standard Scheme doesn't even have `#`, does it? I'll fix my answer. – Jeremiah Willcock Feb 27 '11 at 07:27
  • Yes, the standard just doesn't specify anything; some implementations choose a specific value for this unspecified result, and some choose to return some other value. – Eli Barzilay Feb 27 '11 at 07:28
  • I'm confused. When I include the displayln function it prints the results of map annotate without #void. Without the displayln function #void appears in the pattern match. – Schemer Feb 27 '11 at 07:35
  • @Schemer: How are you including the `displayln` function when it works? The Racket REPL will not print out `#` values. – Jeremiah Willcock Feb 27 '11 at 07:39
  • Jeremiah: S/He's using it inside a list, where it is visible. Try `(list (displayln "blah"))`. – Eli Barzilay Feb 27 '11 at 07:52
  • @Eli: I don't know that the "when I include the displayln function" comment refers to a case where `displayln` is in a list. I would imagine it should include a void there too, unless some later pattern match is removing it. – Jeremiah Willcock Feb 27 '11 at 07:57