user3415513
user3415513

Reputation: 15

Define in scheme

I was trying to run this command on drracket:

(define #t #f)

and I get the following error messege:

define: bad syntax in: #t

I want to know what's the reason for that error, and why I can do: (define + 12) and not this.

Thanks a lot!

Upvotes: 2

Views: 199

Answers (3)

Justin Ethier
Justin Ethier

Reputation: 134255

define expects an identifier as it's first argument. In this case you are supplying #t which evaluates to the boolean value true. Hence the bad syntax error message.

Upvotes: 0

C. K. Young
C. K. Young

Reputation: 223183

The syntax of define is:

(define <variable> <expression>)

A variable is a special kind of identifier, and the format of identifiers is described here. As you can see from the description, #t (and more generally, anything that starts with a #) is not an identifier.

Upvotes: 4

keltar
keltar

Reputation: 18409

First argument to define must be a symbol. + is a symbol. foo is a symbol. #t is #t, not a symbol. 1 is not a symbol.

Upvotes: -2

Related Questions