views:

182

answers:

1

I tried doing this:

#lang scheme
(module duck scheme/base
      (provide num-eggs quack)
      (define num-eggs 2)
      (define (quack n)
        (unless (zero? n)
          (printf "quack\n")
          (quack (sub1 n)))))

But I get this error:

module: illegal use (not at top-level) in: 
(module duck scheme/base (provide num-eggs quack) (define num-eggs 2) (define (quack n) (unless (zero? n) (printf "quack\n") (quack (sub1 n)))))

what is the correct way?

+3  A: 

You should remove the (module duck scheme/base line (and the closing paren).

When you start your code with #lang scheme, it's effectively putting your code in a module that uses the scheme language. You can also use #lang scheme/base if you want the smaller language instead.

(To really get convinced, do this:

(parameterize ([read-accept-reader #t])
  (call-with-input-file "some file" read))

over some source file that uses #lang and see what you get.)

(And BTW, the title of your question is bad -- it should be "PLT Scheme", since this is not relevant to other implementations.)

Eli Barzilay