4

I've seen many instances of cons taking two numbers as arguments, and I've been told to pass pass two numbers as arguments into cons in a lab, but whenever I do I get the following error:

> (cons 1 2)
cons: second argument must be a list, but received 1 and 2

If I do the following, I get the same error:

> (cons '1 '2)
cons: second argument must be a list, but received 1 and 2

I'm very new to Scheme, and I don't understand why this is happening.

Christian Baker
  • 375
  • 2
  • 7
  • 22
  • This is not Scheme behavior; suggest removing the Scheme tag as you've got it properly tagged as Racket. – GoZoner Mar 20 '14 at 15:09

1 Answers1

6

That's because of the teaching language in use, it's probable that you're working with a student language with certain limitations. To solve the problem, make sure that this line is at the beginning of the file:

#lang racket

And choose the option "Determine language from source" in the bottom-left corner of DrRacket's window. Now this should work as expected:

(cons 1 2)
=> '(1 . 2)
Óscar López
  • 232,561
  • 37
  • 312
  • 386