PLT-scheme - Supplementary PLT Scheme 1 Purpose and...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Supplementary: PLT Scheme 1 Purpose and background This document covers some features of PLT Scheme for CS 136 students interested in going be- yond what is covered in lecture. It can be read at any time during the course or afterwards, but some topics may assume preparation from certain CS 136 lectures. It assumes that stu- dents know the basics of the dialects of Scheme known as the “teaching languages” from CS 135 and the How To Design Programs textbook ( http://www.htdp.org ). Other useful ref- erences include the Guide and Reference in DrScheme’s Help Desk, the R5RS (Scheme stan- dard) document (in DrScheme’s Help Desk or http://www.schemers.org ), the SRFI docu- ments describing standard libraries (in Help Desk, or http://srfi.schemers.org ) and the book The Scheme Programming Language (TSPL), by Kent Dybvig (available in paperback or at http://www.tspl.org ). 2 PLT Scheme v4 PLT Scheme is R5RS plus many useful extensions. The starting point for use of the full language is to choose the Module language in DrScheme, and to make sure that the following line is the first line of the program. #lang scheme This is “syntactic sugar” that wraps the entire file in a module declaration and loads all bindings for the full PLT Scheme language. There are other options for the first line. For example, using scheme/base instead of scheme loads a smaller “core” language. A module is a way of packaging code to control what bindings are imported and exported. (provide my-fn1 ...) (require "myfile.ss") module bindings If the program is saved in myfile.ss , then the #lang scheme line is equivalent to ( module myfile scheme . . . ) The program myfile.ss can then be run on the command line in the following fashion: mzscheme myfile.ss mzscheme is included with the DrScheme distribution, but you may need to set up your shell so that its search path includes the directory it is in (or an alias to it). This is particularly convenient for testing that involves I/O, as file redirection can be used. 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
There are many optional command-line flags for mzscheme , including one which gives you a basic read-evaluate-print loop (REPL) after running your program. See the PLT Scheme documen- tation for more details. Any additional command-line arguments are put into a vector (see below) that is the value of the expression ( current-command-line-arguments ). 3 Conditionals The basic conditional construct used in CS 135 is cond , which is in standard Scheme. In R5RS, cond is built on top of if using a macro (macros are described in a later section). ( if test true-exp false-exp ) evaluates test and, depending on its value, evaluates either true-exp or false-exp . PLT Scheme also provides one-armed versions of if called when and unless . #f and false are the only things that if and cond tests consider to be false; any other value is considered to be true. This can simplify some tests.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern