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.
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)