Next: Launchers Up: Interface Essentials Previous: Errors

## Languages

DrScheme supports four languages:

- Beginning Student is a small version of Scheme that is tailored for beginning computer science students.
- Intermediate Student extends Beginning Student with programmer-defined datatypes and lexically-scoped bindings.
- Advanced Student extends Intermediate Student with mutable state.
- Full Scheme refers to two main options: Graphical (MrEd) and Textual (MzScheme). Each comes with and without debugging support.

  MzScheme is a practical dialect of Scheme, essentially a superset of R5RS Scheme (except for macros). In addition to the the base Scheme language, MzScheme provides exceptions, threads, objects, components, regular expressions, TCP support, filesystem utilities, and process control operations. See also PLT MzScheme: Language Manual.

  MrEd extends MzScheme with a graphical toolbox for creating GUI applications (with special support for editor applications, hence the Ed in MrEd). See also PLT MrEd: Graphical Toolbox Manual.

  Debugging support refers to source highlighting when an error occurs. The non-debugging options are faster and support exactly those languages that you can run outside of DrScheme (as stand-alone applications or scripts, for example).

Programs written in standard Scheme generally require the Full Scheme language. This language level offers options to access graphics libraries, and to provide source location information for syntax and run-time errors (with a small performance cost).

DrScheme always shows the current evaluation language in the top of the interactions window. To choose a different language, select the Language`|`Choose Language... menu item. After changing the language, click Execute to reset the language in the interactions window.

The following table summarizes the syntactic forms and procedures built into each language. `Text` indicates Full Scheme/Textual, and `Graph` indicates Full Scheme/Graphical.

                                                 Beg Int Adv Text Graph
    ===================================================================
    define (*), define-struct                     X   X   X   X    X
    lambda (**)                                   X   X   X   X    X
    cond, if, and, or                             X   X   X   X    X
    nand, nor                                     X   X   X   a    a
    quote'd symbols                               X   X   X   X    X
    MrSpidey annotations                          X   X   X   b    b

    quote'd lists, quasiquote, unquote                X   X   X    X
    let (*), let* (*), letrec (*)                     X   X   X    X
    let-struct                                        X   X   X    X
    local                                             X   X   a    a

    set! (*), fluid-let                                   X   X    X
    begin, begin0                                         X   X    X
    implicit begin                                            X    X
    when, unless, if without else                         X   X    X
    Named let, delay, do, case                            X   X    X
    recur, rec, evcase                                    X   a    a
    Turtles, split, split*, tprompt                       X        c

    require-library                               X   X   X   X    X
    define-macro, begin-elaboration-time          X   X   X   X    X
    time                                              X   X   X    X
    let/cc, let/ec, parameterize, with-handlers           X   X    X
    Other MzScheme syntax                                     X    X
    ===================================================================
    Scheme and MzScheme procedures                X   X   X   X    X
    MzLib core library procedures                 X   X   X   d    d
    MrEd GUI classes                                               X
    ===================================================================
    Case-sensitive identifiers and symbols        X   X   X
    Procedures must take at least 1 argument      X   X
    Identifier required at function-call position X   X
    Top-level required at function-call position  X
    lambda allowed only in definitions            X
    quote works only on symbols                   X
    Unmatched cond/case is an error               X   X   X
    Conditional values must be #t or #f           X   X
    =, ..., +, *, and / take at least 2 arguments X   X   X
    and, or, nand, nor require at least 2 exprs   X   X   X
    Improper lists disallowed                     X   X   X
    set! disallowed on arguments                          X
    structures omit supertype, mutators           X   X
    ===================================================================
    Constructor-style output                      X   X   X
    write output                                              X    X
    Abbreviate cons constructor with list             X   X
    Show sharing in values                                X
    Decimal numbers read as exact                 X   X   X
    Print inexact numbers with #i                 X   X   X
    ===================================================================
     *: including -values forms
     **: including case-lambda
     a: Use (require-library "macro.ss")
     b: Use (require-library "spidey.ss")
     c: Use (require-library "turtle.ss" "graphics")
     d: Use (require-library "core.ss")

Most lines in the table specify the syntactic forms and procedures that each language provides. Lines in the next-to-last section specify deviations from the standard Scheme language:

- Case-sensitive identifiers and symbols -- In a case-sensitive language, the variable names `x` and `X` are distinct, and the symbols `'x` and `'X` are also distinct. In a case-insensitive language, `x` and `X` are equivalent and `'x` and `'X` represent the same value.
- Procedures must take at least 1 argument -- In the Beginning Student and Advanced Student languages, defined procedures must consume at least one argument. Since the languages have no side-effects, zero-argument functions are not useful, and rejecting such function definitions helps detect confusing syntactic mistakes.
- Identifier required at function call position -- In the Beginning Student and Advanced Student languages, procedure calls must be of the form `(identifier ...)`. This restriction helps detect confusing misuses of parentheses, such as `(1)` or `((+ 3 4))`, which is a common mistake among beginners who are used to the optional parentheses of algebra.
- Top-level required at function call position -- In the Beginning Student language, procedure calls must be of the form `(top-level-identifier ...)`. This restriction helps detect confusing misuses of parentheses, such as `(x)` where x is a function argument. DrScheme can detect such mistakes syntactically because Beginning Student does not support higher-order procedures.
- `lambda` allowed only in definitions -- In the Beginning Student language, `lambda` (or `case-lambda`) may appear only in a definition and only as the value of the defined variable. This restriction is required by the evaluation rules used by the stepper tool.
- `quote` works only on symbols -- In the Beginning Student and Advanced Student languages, `quote` and `'` can specify only symbols. This restriction avoids the need to explain to beginners why `1` and `'1` are equivalent in standard Scheme.
- Unmatched `cond`/`case` is an error -- In the Beginning Student, Intermediate Student, and Advanced Student languages, falling through a `cond` or `case` expression without matching a clause signals a run-time error. This convention helps detect syntactic and logical errors in programs.
- Conditional values must be `#t` or `#f` -- In the Beginning Student and Advanced Student languages, an expression whose value is treated as a Boolean must return `#t` or `#f`. This restriction, which applies to `if`, `cond`, `and`, `or`, `nand`, and `nor` expressions, helps detect errors where a Boolean function application is omitted.
- `=`, `<=`, `<`, `>`, `>=`, `+`, `*`, and `/` take at least two arguments -- In the Beginning Student, Intermediate Student, and Advanced Student languages, mathematical operators that are infix in algebra notation require at least two arguments in DrScheme. This restriction helps detect missing arguments to an operator.
- `and`, `or`, `nand`, and `nor` require at least 2 expressions -- In the Beginning Student, Intermediate Student, and Advanced Student languages, the Boolean combination forms require at least two sub-expressions. This restriction helps detect missing or ill-formed sub-expressions in a Boolean expression.
- `set!` disallowed on arguments -- In the Advanced Student language, `set!` cannot be used to mutate variables bound by `lambda`. This restriction ensures that the substitution model of function application is consistent with Drscheme's evaluation.
- Improper lists disallowed -- A proper list is either an empty list or a list created by `cons`ing onto a proper list. In the Beginning Student through Advanced Student languages, `cons` constructs only proper lists, signaling an error if the second argument is not a proper list. Since beginning students do not need improper lists, this restriction help detect logical errors in recursive functions.
- `define-struct` omits supertype, mutators -- In Beginning Student and Intermediate Student, the `define-struct` syntactic form does not support the optional supertype expression. This restriction simplifies the syntax to help detect parenthesization mistakes. In addition, `define-struct` does not bind the names of structure mutators, since the languages do not support state in general.

Lines in the last section specify deviations from a traditional Scheme `read`-`eval`-`print` interface in the way that DrScheme reads and prints interaction results:

- Constructor-style output -- See Constructor-style Output.
- `write` output -- Prints interaction results with `write`.
- Abbreviate `cons` constructor with `list` -- Adjusts constructor-style output to print list values with `list` instead of a nested sequence of `cons`es.
- Show sharing in values -- Prints interaction results using the `shared` syntax, which exposes shared structure within a value. For example, the list created by `(let ([l (list 0)]) (list l l))` prints as `(shared ((-1- (list 0))) (list -1- -1-))`

  rather than `(list (list 0) (list 0))`.

- Decimal numbers read as exact -- Unless a number containing a decimal point or exponent includes `#i`, it is parsed as an exact number.
- Print inexact numbers with `#i` -- Prints inexact numbers with a leading `#i` to emphasize that they represent imprecise results (or even effectively incorrect results, depending on the intended calculation).

The Language`|`Choose Language... dialog contains a Show Details button that lets you configure certain details of the language specification. (Each option corresponds to one of the lines in the language table, but only a few of the lines in the figure have an option in the dialog.) Whenever the selected options do not match the default language specification, a Custom indicator appears next to the language-selection control at the top of the dialog.

Next: Launchers Up: Interface Essentials Previous: Errors