简体   繁体   中英

Scheme cons won't take two number arguments

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM