213

Racket is a descendant of Scheme. How is Racket different than R6RS? What did it add, or take away, or is just different?

I understand that Racket is more than a language, it's a platform for languages. But I'm referring to the main Racket dialect.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
mudgen
  • 7,213
  • 11
  • 46
  • 46

6 Answers6

148

Racket is ultimately based on R5RS, and not R6RS and not a strict superset of either. I don't think it can be called 'Scheme' because it's not backwards compatible with any Scheme standard.

Most implementations offer extensions, but are otherwise backwards compatible, of course, the compiler that comes with Racket can also run in R5RS or R6RS mode. Valid R5/6RS Scheme that runs in racket mode may either be rejected, cause runtime errors, or behave differently than it should. With that said, the main points where it is not backwards compatible are:

  • Racket has no set-cdr! and set-car!, rather set-mcar! which only works on pairs specifically created as mutable.
  • What Racket calls letrec is called letrec* in R6RS and doesn't exist in R5RS, what R5RS and R6RS call letrec doesn't exist in Racket.
  • In Racket, a lot of things are self-evaluating which would raise an error in R5RS, most importantly the empty list.
  • Racket is case sensitive, though R6RS is also case sensitive
  • Racket treats ( ... ) and [ ... ] as equivalent, R5RS does not, but R6RS does.

There are probably more, but on most other parts racket is a superset of Scheme.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Zorf
  • 6,334
  • 2
  • 29
  • 24
  • 25
    In Racket `()` is invalid, not self-evaluating. Also, Racket *does* have the more restricted `letrec` -- for example, the one in the `r5rs` language; it's an intentional choice to use the `letrec*`-like version in the default language. – Eli Barzilay Jul 31 '10 at 15:57
  • 10
    @ Eli, whoops, you're right, racket running in Swindle mode seems to consider `()` self evaluating, I was confused with that one. I never really got why `()` was not self-evaluating in Scheme as it is in Common Lisp though. – Zorf Aug 01 '10 at 12:12
  • 2
    @Zorf It can easily be changed by overloading `#%app`, though: `#lang racket (require (rename-in racket [#%app old])) (define-syntax #%app (syntax-rules () [(_) '()] [(_ . rest) (old . rest)])) (null? ()) ;; => #t` – Suzanne Soy Nov 22 '16 at 16:20
  • 5
    This answer should be updated. Racket's feature set far outweighs Scheme's now, with modules and language definitions, etc. – CinchBlue Dec 11 '17 at 02:57
  • @VermillionAzure You mean, like the feature set of any practical implementation of Scheme outweighs standard Scheme? – Mali Remorker Feb 28 '18 at 08:05
  • 1
    @MaliRemorker I don't understand exactly what you mean, but Scheme is currently on R7RS and was on R6RS. But Racket still out-dos the R6RS feature set. – CinchBlue Mar 01 '18 at 00:44
45

It contains immutable lists, as mentioned above. It also contains a structure system that is a bit cleaner than the R6RS record system. It has an object oriented class and object system. It has native support for design by contract. It has a unit system reminiscent of the ML module system, as well as a module system much like the R6RS module system. I'm sure I've forgotten as many things as I've mentioned.

I'm not sure that the rename was useful as anything other than a marketing gimmick, but racket is definitely a distinct dialect of scheme.

deinst
  • 18,402
  • 3
  • 47
  • 45
  • 26
    I think the rename was because they didn't want to be some dialect of Scheme with a bunch of nonstandard additions — they wanted to be a Scheme-based language with a bunch more stuff standard. Classifying PLT Scheme as "just" a dialect of Scheme is like classifying Ruby as a dialect of Mirah — it's not inaccurate, but it kind of downplays the language's strengths. – Chuck Jul 27 '10 at 17:13
  • 8
    I think using a different name is a wise decision: using the same name for different languages that have a common origin is IMO confusing. I would change the name even if the language contained Scheme as a subset but contained so many additions that it would encourage a very different programming style. – Giorgio Aug 03 '12 at 14:57
26

The rationale for the name-change from PLT Scheme to Racket is discussed on the Racket site.

Norman Gray
  • 11,978
  • 2
  • 33
  • 56
23

The language specification R5RS on the Scheme programming language is based on consensus between the multiple Scheme implementors. This imply that the language is very stable. It also implies that many useful features are not part of the R5RS standard.

Racket has built upon R5RS and extended it greatly. Some extensions are defined as macros, but some features require the support of the runtime system.

Features in Racket not implementable by macros alone:

  • delimited continuations (more general than call/cc)
  • continuation marks
  • threads
  • places
  • ffi

The module and macro system are much more general than the RnRS specification. Together with #lang reader/language specification makes it possible to define custom languages (with custom syntax) and use them with normal Racket programs.

In a few cases Racket has constructs whose behaviour deviates from R5RS. The most obvious one is making cons construct an immutable pair (mcons constructs a mutable pair). One advantage of a having immutable pairs, is that length now runs in O(1) amortized time.

soegaard
  • 30,661
  • 4
  • 57
  • 106
20

Racket includes a lot of really nice language constructs not included in R6RS scheme, like "match".

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Gautam
  • 1,732
  • 4
  • 18
  • 26
  • 4
    Why would "match" be a nice feature? At least, when you express an opinion, you should give a brief explanation of it, so that people not familiar well with Racket can understand why "match" is theoretically beneficial. – nbro Aug 07 '17 at 23:07
  • 2
    Pattern Matching is a really desired feature on many languages with functional programming backgrounds, unfortunately don't even R6RS or Common Lisp implements this by default, so yes this is a really nice and differential feature which Racket provide. For example languages like Haskell, Elixir, Rust and F# provide that type of constructions and are heavily used. I personally make Lisp programming mostly in Common Lisp and I miss in much cases the lack of pattern matching implementation. – Manoel Vilela Aug 11 '17 at 09:53
  • 2
    `match` is very nice but fortunately it's just a macro so it can be easily added to Lisps that don't have it. Common Lisp can do light pattern matching on lists via `destructuring-bind`. It's simple to write a `destructuring-case` macro based on it, and many people have. For Scheme there are portable `match` libraries. Clojure has `core.match`. – Lassi May 13 '19 at 16:15
  • 1
    Macros can make code hard to read as they often have special semantics, therefore the language should always standardize all general purpose macros so that everyone doesn't build their own macros. Pattern matching should be the default just like in Arc & Clojure & Racket & Ocaml & Haskell as it more directly specifies intent. Caddr is too low level. – aoeu256 Oct 01 '19 at 10:55
15

For one big example, Racket lists are immutable by default whereas Scheme's are mutable. Racket also includes a lot of standard libraries (e.g. Web Server) that other Schemes do not.

Chuck
  • 234,037
  • 30
  • 302
  • 389