Question

I have downloaded Racket and following its manual, previously I worked with Plt Scheme and besides the authors say is the same; I have found some stuff that is not so straightforward

When I put the instruction

(list "red" "green" "blue")

and execute the program, it appears:

(list "red" "green" "blue")

and not '("red" "green" "blue"); that used to happen in Scheme. I have tried with all the languages (Beginner, Intermediate, Advanced) and nothing; why is that?

Also if I want to use cons like:

(cons 1 2)

the error I get is:

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

so why is that also? In scheme usually that expression printed '(1 2)

any help?

Was it helpful?

Solution

It looks like you're using one of the teaching languages. Try this: in the bottom-left corner of the window, select "Determine language from source" and in the editor write this as the first line:

#lang racket

Be careful though, Racket and Scheme are different languages and there are some differences w.r.t. standard Scheme. One of the first surprises will come when you try to mutate a cons cell, refer to this question for advice. Also bear in mind that in Racket if expressions must have both a consequent and an alternative. Make sure to take a look at this answer for more differences.

OTHER TIPS

First off DrRacket has vast number of languages supported so it might be that you just haven't chosen the correct one or that the default settings for the one you have choosen is not pleasing. I'll go though how to change langauge and how to change it's appearance:

Choosing language to program in

As you mentioned you have a dropdown menu at the bottom left in DrRacket IDE where you have some choices. Press that to select one of the languages already choosen before or use the "Choose language" option to select something else.

Another option that is quite handy is to select "Determine language from source" and put one of these as the first line:

#!r6rs    ; Scheme standard R6RS language
#!r5rs    ; Scheme standard R5RS language (legacy)
#!racket  ; Racket's own Scheme dialect != Scheme (racket can mean "A dirty scheme")

So DrRacket is like a IDE with support for lots of programming languages but they are mainly Scheme dialects. Before it was called Racket it was called DrScheme and the language was called PLT Scheme with #lang scheme as the default language. #!scheme is deprecated and can be removed so to make compatible programs for future versions of racket choose something else.

The actual change doesn't happen before you press Run. You'll see in the interactions window that the new language is in effect.

Change how the REPL displays evaluated expressions

What is printed in the interactions window (as in REPL) when you press RUN or expressions in the interactions window is not output so it's not covered by a standard.

You choose how the REPL should display results from the same bottom left select menu. Choose "Choose language" without making any choices and then press the bottom left "Show details". You have 3 different ways to show it. Here are the different options:

Input expression    Constructor      Quasiquote      write
(cons 1 2)          (cons 1 2)      `(1 . 2)         (1 . 2)
(list 1 2)          (list 1 2)      `(1 2)           (1 2)
add1                add1            add1             #<procedure:add1>

Be sure to understand that this is just representation in the REPL and that actually printing something in your program you need display or a similar printing procedure to actually get true output.

ok I found a nice way to do this, at the beginning of the program I should put:

#lang scheme

and then determine Language from source, thanks to the advice of @OscarLopez

Now at least I can use Scheme in Racket

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top