Revised 7 Report on the Algorithmic Language Scheme

Size: px
Start display at page:

Download "Revised 7 Report on the Algorithmic Language Scheme"

Transcription

1 Revised 7 Report on Algorithmic Language Scheme ALEX SHINN, JOHN COWAN, AND ARTHUR A. GLECKLER (Edirs) STEVEN GANZ ALEXEY RADUL OLIN SHIVERS AARON W. HSU JEFFREY T. READ ALARIC SNELL-PYM BRADLEY LUCIER DAVID RUSH GERALD J. SUSSMAN EMMANUEL MEDERNACH BENJAMIN L. RUSSEL RICHARD KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Edirs, Revised 5 Report on Algorithmic Language Scheme) MICHAEL SPERBER, R. KENT DYBVIG, MATTHEW FLATT, AND ANTON VAN STRAATEN (Edirs, Revised 6 Report on Algorithmic Language Scheme) 8 August 2011 Dedicated memory John McCarthy

2 2 Revised 7 Scheme SUMMARY report gives a defining description programming language Scheme. Scheme is a statically scoped properly tail recursive dialect Lisp programming language invented by Guy Lewis Steele Jr. Gerald Jay Sussman. It was designed have an exceptionally clear simple semantics few different ways form expressions. A wide variety programming paradigms, including imperative, functional, object-oriented styles, find convenient expression in Scheme. introduction fers a brief hisry language report. first three chapters present fundamental ideas language describe notational conventions used for describing language for writing programs in language. Chapters 4 5 describe syntax semantics expressions, definitions, programs, libraries. Chapter 6 describes Scheme s built-in s, which include all language s data manipulation input/output primitives. Chapter 7 provides a formal syntax for Scheme written in extended BNF, along with a formal denotational semantics. An example use language follows formal syntax semantics. Appendix A provides a list stard libraries identifiers that y export. Appendix B provides a list optional but stardized implementation feature names. report concludes with a list references an alphabetic index. *** DRAFT*** December 18, 2011 CONTENTS Introduction Overview Scheme Semantics Syntax Notation terminology Lexical conventions Identifiers Identifiers Whitespace comments Or notations Datum labels Basic concepts Variables, syntactic keywords, regions Disjointness types External representations Srage model Proper tail recursion Expressions Primitive expression types Derived expression types Macros Program structure Programs Definitions Syntax definitions Record type definitions Libraries Stard s Equivalence predicates Numbers Booleans Pairs lists Symbols Characters Strings Vecrs Bytevecrs Control features Exceptions Eval Input output Formal syntax semantics Formal syntax Formal semantics Derived expression types A Stard Libraries B Stard Feature Identifiers Notes Additional material Example References Alphabetic index definitions concepts, keywords, s

3 Introduction 3 INTRODUCTION Programming languages should be designed not by piling feature on p feature, but by removing weaknesses restrictions that make additional features appear necessary. Scheme demonstrates that a very small number rules for forming expressions, with no restrictions on how y are composed, suffice form a practical efficient programming language that is flexible enough support most major programming paradigms in use day. Scheme was one first programming languages incorporate first class s as in lambda calculus, reby proving usefulness static scope rules block structure in a dynamically typed language. Scheme was first major dialect Lisp distinguish s from lambda expressions symbols, use a single lexical environment for all variables, evaluate operar position a call in same way as an oper position. By relying entirely on calls express iteration, Scheme emphasized fact that tail recursive calls are essentially GOTO s that pass arguments, thus allowing a programming style that is both coherent efficient. Scheme was first widely used programming language embrace first class escape s, from which all previously known sequential control structures can be synsized. A subsequent version Scheme introduced concept exact inexact numbers, an extension Common Lisp s generic arithmetic. More recently, Scheme became first programming language support hygienic macros, which permit syntax a block-structured language be extended in a consistent reliable manner. Background first description Scheme was written in 1975 [34]. A revised report [31] appeared in 1978, which described evolution language as its MIT implementation was upgraded support an innovative compiler [32]. Three distinct projects began in use variants Scheme for courses at MIT, Yale, Indiana University [27, 23, 15]. An introducry computer science textbook using Scheme was published in 1984 [3]. As Scheme became more widespread, local dialects began diverge until students researchers occasionally found it difficult underst code written at or sites. Fifteen representatives major implementations Scheme refore met in Ocber 1984 work ward a better more widely accepted stard for Scheme. ir report, RRRS [7], was published at MIT Indiana University in summer Furr revision ok place in spring 1986, resulting in R 3 RS [29]. Work in spring 1988 resulted in R 4 RS [9], which became basis for IEEE Stard for Scheme Programming Language in 1991 [18]. In 1998, several additions IEEE stard, including high-level hygienic macros, multiple return values eval, were finalized as R 5 RS [2]. In fall 2006, work began on a more ambitious stard, including many new improvements stricter requirements made in interest improved portability. resulting stard, R 6 RS, was completed in August 2007 [1], was organized as a core language set mary stard libraries. size goals R 6 RS, however, were controversial, adoption new stard was not as widespread as had been hoped. In consequence, Scheme Steering Committee decided in August 2009 divide stard in two separate but compatible languages a small language, suitable for educars, researchers embedded languages, focused on R 5 RScompatibility, a large language focused on practical needs mainstream stware development which would evolve become a replacement for R 6 RS. present report describes small language that effort. We intend this report belong entire Scheme community, so we grant permission copy it in whole or in part without fee. In particular, we encourage implemenrs Scheme use this report as a starting point for manuals or documentation, modifying it as necessary. Acknowledgements We would like thank members Steering Committee, William Clinger, Marc Feeley, Chris Hanson, Jonathan Rees, Olin Shivers, for ir support guidance. We d like thank following people for ir help: Per Bothner, Taylor Campbell, Ray Dillinger, Brian Harvey, Shiro Kawai, Jonathan Kraut, Thomas Lord, Vincent Manis, Jeronimo Pellegrini, Jussi Piitulainen, Alex Queiroz, Jim Rees, Jay Reynolds Freeman, Malcolm Tredinnick, Denis Washingn, Andy Wingo, Andre van Tonder. In addition we would like thank all past edirs, people who helped m in turn: Hal Abelson, Norman Adams, David Bartley, Alan Bawden, Michael Blair, Gary Brooks, George Carrette, Andy Cromarty, Pavel Curtis, Jeff Daln, Olivier Danvy, Ken Dickey, Bruce Duba, Robert Findler, Andy Freeman, Richard Gabriel, Yekta Gürsel, Ken Haase, Robert Halstead, Robert Hieb, Paul Hudak, Morry Katz, Eugene Kohlbecker, Chris Lindblad, Jacob Matws, Mark Meyer, Jim Miller, Don Oxley, Jim Philbin, Kent Pitman, John Ramsdell, Guillermo Rozas, Mike Shaff, Jonathan Shapiro, Guy Steele, Julie Sussman, Perry Wagle, Mitchel W, Daniel Weise, Henry Wu,

4 4 Revised 7 Scheme Ozan Yigit. We thank Carol Fessenden, Daniel Friedman, Chrispher Haynes for permission use text from Scheme 311 version 4 reference manual. We thank Texas Instruments, Inc. for permission use text from TI Scheme Language Reference Manual [36]. We gladly acknowledge influence manuals for MIT Scheme [23], T [28], Scheme 84 [16], Common Lisp [33], Algol 60 [24].

5 1. Overview Scheme 5 DESCRIPTION OF THE LANGUAGE 1. Overview Scheme 1.1. Semantics This section gives an overview Scheme s semantics. A detailed informal semantics is subject chapters 3 through 6. For reference purposes, section 7.2 provides a formal semantics Scheme. Following Algol, Scheme is a statically scoped programming language. Each use a variable is associated with a lexically apparent binding that variable. Scheme has latent as opposed manifest types a dynamically typed language. Types are associated with values (also called objects) rar than with variables. (Some authors refer languages with latent types as weakly typed or dynamically typed languages.) Or languages with latent types are APL, Snobol, or dialects Lisp. Languages with manifest types (sometimes referred as strongly typed or statically typed languages) include Algol 60, Pascal, C Statically typed languages, by contrast, associate types with variables expressions as well as with values. All objects created in course a Scheme computation, including s continuations, have unlimited extent. No Scheme object is ever destroyed. reason that implementations Scheme do not (usually!) run out srage is that y are permitted reclaim srage occupied by an object if y can prove that object cannot possibly matter any future computation. Or languages in which most objects have unlimited extent include APL or Lisp dialects. Implementations Scheme are required be properly tail-recursive tail recursive. This allows execution an iterative computation in constant space, even if iterative computation is described by a syntactically recursive. Thus with a properly tail-recursive tail recursive implementation, iteration can be expressed using ordinary -call mechanics, so that special iteration constructs are useful only as syntactic sugar. See section 3.5. Scheme s are objects in ir own right. Procedures can be created dynamically, sred in data structures, returned as results s, so on. Or languages with se properties include Common Lisp ML. One distinguishing feature Scheme is that continuations, which in most or languages only operate behind scenes, also have first-class status. Continuations are useful for implementing a wide variety advanced control constructs, including non-local exits, backtracking, coroutines. See section Arguments Scheme s are always passed by value, which means that actual argument expressions are evaluated before gains control, regardless wher needs result evaluationor not. ML, C, APL are three or languages that always pass arguments by value. This is distinct from lazy-evaluation semantics Haskell, or call-by-name semantics Algol 60, where an argument expression is not evaluated unless its value is needed by.. Scheme s model arithmetic is designed remain as independent as possible particular ways in which numbers are represented within a computer. In Scheme, every integer is a rational number, every rational is a real, every real is a complex number. Thus distinction between integer real arithmetic, so important many programming languages, does not appear in Scheme. In its place is a distinction between exact arithmetic, which corresponds mamatical ideal, inexact arithmetic on approximations. As in Common Lisp, exact Exact arithmetic is not limited integers Syntax Scheme, like most dialects Lisp, employs a fully parensized prefix notation for programs (or) data; grammar Scheme generates a sublanguage language used for data. An important consequence this simple, uniform representation is susceptibility that Scheme programs data uniform treatment c easily be treated uniformly by or Scheme programs. For example, eval evaluates a Scheme program expressed as data. read performs syntactic as well as lexical decomposition data it reads. read parses its input as data (section 7.1.2), not as program. formal syntax Scheme is described in section Notation terminology Primitive, library, Base optional features It is required that every implementation Scheme support all features that Every identifier defined in th report appears in one several libraries. Identifiers defined in base library are not marked as being. Implementations specially in body report. A summary all stard libraries features y provide given in Appendix A.

6 6 Revised 7 Scheme Implementations must provide base library all identifiers exported from it. Implementations are free omit optional features Scheme or add extensionsprovide or omit or libraries given in this report, but each library must eir be provided in its entirety, exporting no additional identifiers, or else omitted alger. Implementations may provide or libraries not described in th report. Implementations may also extend function any identifier in th report, provided extensions are not in conflict with language reported here. In particular, implementations must support portable code by providing a syntactic mode that preempts no lexical conventions this report. To aid in understing implementing Scheme, some features are marked as. se can be easily implemented in terms or, primitive, features. y are redundant in strict sense word, but y capture common patterns usage, are refore provided as convenient abbreviationsmode operation in which lexical syntax does not conflict with lexical syntax described in th report Error situations unspecified behavior When speaking an error situation, this report uses phrase an error is signalled indicate that implementations must detect report error. An error is signalled by raising non-continuable exception, as if by raise as described in section object raised implementation-dependent need not be newly allocated object every time. In addition errors signalled by situations described in th report, programmers may signal ir own errors hle signalled errors. If such wording does not appear in discussion an error, n implementations are not required detect or report error, though y are encouraged do so. An error situation that implementations are not required detect is usually referred simply as Such situation is sometimes, but not always, referred with phrase an error. For example, it is an error for a be passed an argument a type that is not explicitly specified hle, even though such domain errors are seldom mentioned in this report. Implementations may extend a s domain definition include such arguments. This report uses phrase may report a violation an implementation restriction indicate circumstances under which an implementation is permitted report that it is unable continue execution a correct program because some restriction imposed by implementation. Implementation restrictions are course discouraged, but implementations are encouraged report violations implementation restrictions. For example, an implementation may report a violation an implementation restriction if it does not have enough srage run a program, or arithmetic operation would produce exact number that o large for implementation represent. If value an expression is said be unspecified, n expression must evaluate some object without signalling an error, but value depends on implementation; this report explicitly does not say what value should be is returned. Finally, words phrases must, must not, shall, shall not, should, should not, may, required, recommended, optional, although not capitalized in th report, are be interpreted as described in RFC 2119 [12]. In particular, must must not are used only when absolute restrictions are placed on implementations Entry format Chapters 4 6 are organized in entries. Each entry describes one language feature or a group related features, where a feature is eir a syntactic construct or a built-in. An entry begins with one or more header lines form template for required, primitive features, identifiers library, or template category in base library category where is eir library or optional library short name library as defined in section Appendix A. If category is syntax,, entry describes an expression type, template gives syntax expression type. Components expressions are designated by syntactic variables, which are written using angle brackets, for example, expression, variable. Syntactic variables should be undersod are intended denote segments program text; for example, expression sts for any string characters which is a syntactically valid expression. notation thing 1... indicates zero or more occurrences a thing, thing 1 thing 2... indicates one or more occurrences a thing. If category is, auxiliary syntax, n entry describes syntax binding that occurs only as

7 2. Lexical conventions 7 part specific surrounding expressions. independent syntactic construct or identifier Any use as an error. If category, n entry describes a, header line gives a template for a call. Argument names in template are italicized. Thus header line (vecr-ref vecr k) indicates that built-in bound vecr-ref variable takes two arguments, a vecr vecr an exact non-negative integer k (see below). header lines (make-vecr k) (make-vecr k fill) indicate that make-vecr must be defined take eir one or two arguments. It is an error for an operation be presented with an argument that it is not specified hle. For succinctness, we follow convention that if an argument name is also name a type listed in section 3.2, n that argument must be it an error if that argument not named type. For example, header line for vecr-ref given above dictates that first argument vecr-ref must be is a vecr. following naming conventions also imply type restrictions: obj any object list, list 1,... list j,... list (see section 6.4) z, z 1,... z j,... complex number x, x 1,... x j,... real number y, y 1,... y j,... real number q, q 1,... q j,... rational number n, n 1,... n j,... integer k, k 1,... k j,... exact non-negative integer string string pair pair list list alist association list (list pairs) symbol symbol char character letter alphabetic character byte exact non-negative integer < 256 bytevecr bytevecr proc thunk zero-argument port port Evaluation examples symbol = used in program examples should be is read evaluates. For example, (* 5 8) = 40 means that expression (* 5 8) evaluates object 40. Or, more precisely: expression given by sequence characters (* 5 8) evaluates, in initial environment, an object that may can be represented externally by sequence characters 40.. See section 3.3 for a discussion external representations objects Naming conventions By convention,? final character names s that always return a boolean valueusually end in. Such s are called predicates. By convention, Similarly,! final character names s that sre values in previously allocated locations (see section 3.4)usually end in. Such s are called mutation s. By convention, value returned by a mutation is unspecified. By convention, -> appears within names s that take an object one type return an analogous object anor type. For example, list->vecr takes a list returns a vecr whose elements are same as those list. 2. Lexical conventions This section gives an informal account some lexical conventions used in writing Scheme programs. For a formal syntax Scheme, see section 7.1. Upper lower case forms a letter are never distinguished except within character string constants 2.1. Identifiers An identifier any sequence letters, digits, extended identifier characters provided that it does not have prefix which is a valid number. However,. ken (a single period) used in list syntax not identifier. All implementations Scheme must support following extended identifier characters:! $ % & * + -. / : < = ^ _ ~ In addition, any character supported by implementation can be used within identifier when specified using an inline hex escape. For example, Foo identifier H\x65;llo is same identifier as FOO, x1abas identifier Hello, in implementation that supports appropriate Unicode character identifier \x3bb; is same number as X1abas identifier λ.

8 8 Revised 7 Scheme 2.2. Identifiers #!fold-case directive causes read case-fold (as if by string-foldcase; see section 6.7) each Most identifiers allowed by or programming languages identifier character name subsequently read from are also acceptable Scheme. precise rules for same port. #!no-fold-case directive causes read forming identifiers vary among implementations Scheme, return default, non-folding behavior. but in all implementations As convenience, identifiers may also be written as a sequence letters, digits, extended alphabetic characters that begins with a 2.2. Whitespace comments character that cannot begin a number is zero or more characters enclosed within vertical bars ( ), analogous Whitespace characters are spaces newlines include string literals. Any character, including whitespace space newline characters. (Implementations typically characters, but excluding backslash vertical bar may provide additional whitespace characters such as tab characters, may appear verbatim in such an identifier. or page break.) Whitespace is used for improved readability as necessary separate kens from each or, a In addition,,, are identifiers. It is also possible include backslash vertical bar characters, as ken being an indivisible lexical unit such as an identifier well as any or character, in identifier with an or number, but is orwise insignificant. Whitespace may inline hex escape. Thus identifier foo bar can occur between any two kens, but not within a ken. Whitespace may also occur same as identifier foo\x20;bar. Note that is a valid occurring inside a string identifier that not equal any or identifier., where it or inside symbol delimited by vertical bars is Here are some examples identifiers: significant. lambda q lexical syntax includes several comment forms. list->vecr soup +soup+ + Comments are V17 treated exactly like whitespace. <=? a34ktmns A semicolon (;) indicates start a line comment. -word-recursion-has-many-meanings comment continues end line on which Extended alphabetic characters may be used within identifiers as ify were letters. following are extended alpha semicolon appears. Comments are invisible Scheme, but!* + -. / :< = string... two words two\ x20;words -word-recursion-has-many-m end line is visible as whitespace. This prevents a See section for a formal syntax identifiers. comment from appearing in middle an identifier or number. Identifiers have two uses within Scheme programs: Any identifier may be used as a variable or as a syntactic keyword (see sections ). When an identifier appears as a literal or within a literal (see section 4.1.2), it is being used denote a symbol (see section 6.5). In contrast with earlier revisions report [2], syntax distinguishes between upper lower case in identifiers in characters specified vi ir names, but not in numbers, nor in inline hex escapes used in syntax identifiers, characters, or strings. None identifiers defined in th report contain upper-case characters, even when y may appear do so as result English-language convention capitalizing word at beginning sentence. following directives give explicit control over case folding. ;;; Anor way indicate comment prefix a datum (cf. section 7.1.2) with # ; as well as possible whitespace before datum. comment consists comment prefix #;, space, datum ger. Th notation useful for commenting out sections code. Block comments are indicated with # pairs. properly nested # # FACT computes facrial ;;; a non-negative integer. # (define fact (lambda (n) (if (= n 0) # ;(= n 1 ) 1 ;Base case: return 1 (* n (fact (- n 1)))))) 2.3. Or notations #!fold-case #!no-fold-case se directives may appear anywhere comments are permitted (see section 2.2) are treated as comments, except that y affect reading subsequent data. For a description notations used for numbers, see section se are used in numbers, may also occur anywhere in an identifierexcept as first character. A

9 3. Basic concepts 9 delimited plus or minus sign by itself is also an identifier. A delimited period (not occurring within a number or identifier) is used in notation for pairs (section 6.4), indicate a rest-parameter in a formal parameter list (section 4.1.4). A delimited sequence three successive periods is also Note that sequence two or more periods is an identifier. ( ) Parenses are used for grouping notate lists (section 6.4). single quote character is used indicate literal data (section 4.1.2). ` backquote character is used indicate almost-constant partly-constant data (section 4.2.8).,,@ character comma sequence comma atsign are used in conjunction with backquote (section 4.2.8). " double quote character is used delimit strings (section 6.7). \ Backslash is used in syntax for character constants (section 6.6) as an escape character within string constants (section 6.7) identifiers (section 7.1.1). [ ] { } Left right square brackets curly braces vertical bar are reserved for possible future extensions language. # Sharp sign is used for a variety purposes depending on character that immediately follows it: #t #f se are boolean constants (section 6.3.1), along with alternatives #true #false. #\ This introduces a character constant (section 6.6). #( This introduces a vecr constant (section 6.8). Vecr constants are terminated by ). #u8( Th introduces bytevecr constant (section 6.9). Bytevecr constants are terminated by ). #e #i #b #o #d #x se are used in notation for numbers (section 6.2.5). # n = # n # se are used for labeling or literal dat (section 2.4) Datum labels # n = datum # n # lexical syntax datum, but also results It is error if n referencing lexical syntax lexical syntax # n = datum reads same as in datum being labelled by n. not sequence digits. lexical syntax # n # serves as object labelled by # n =; result same # n = as compared with eqv? (see section 6.1). Toger, se syntaxes permit with shared or circular substructure. reference some object as notation structures (let ((x (list a b c))) (set-cdr! = # 0=(a (cddr b c. x) # 0# x) ) x) in scope datum label portion datum which it appears that right label. Consequently, reference # n # may occur only after a label # n =; it error attempt forward reference. In addition, it error if reference appears as labelled object itself (as in # n = # n #), because object labelled by # n = not well defined in th case. It error for a program or library references. In particular, it error (section 4.2.8) contain m. include circular for quasiquote # 1=(begin (display #\ x). #1# = ) error 3. Basic concepts 3.1. Variables, syntactic keywords, regions An identifier may name names eir a type syntax, or it may name or a location where a value can be sred. An identifier that names a type syntax is called a syntactic keyword is said be bound that syntax. An identifier that names a location is called a variable is said be bound that location. set all visible bindings in effect at some point in a program is known as environment in effect at that point. value sred in location which a variable is bound is called variable s value. By abuse terminology, variable is sometimes said name value or be bound value. This is not quite accurate, but confusion rarely results from this practice. Certain expression types are used create new kinds syntax bind syntactic keywords those new syntaxes, while or expression types create new locations bind variables those locations. se expression types are called binding constructs. Those that bind syntactic keywords are listed in section 4.3. most fundamental variable binding constructs is lambda expression, because all or variable binding constructs can be explained in terms lambda expressions. or variable binding constructs are let, let*, letrec, letrec*, let-values, let*-values, do expressions (see sections 4.1.4, 4.2.2, 4.2.4). Like Algol Pascal, unlike most or dialects Lisp except for Common Lisp, Scheme is a statically scoped language with block structure. To each place where an

10 10 Revised 7 Scheme identifier is bound in a program re corresponds a region program text within which binding is visible. region is determined by particular binding construct that establishes binding; if binding is established by a lambda expression, for example, n its region is entire lambda expression. Every mention an identifier refers binding identifier that established innermost regions containing use. If re is no binding identifier whose region contains use, n use refers binding for variable in p level environment, if any (chapters 4 6); if re is no binding for identifier, it is said be unbound Disjointness types No object satisfies more than one following predicates: boolean? symbol? char? vecr? null? pair? number? string? bytevecr? port? se predicates define types boolean, pair, symbol, number, char (or character), string, vecr, bytevecr, port,. empty list is a special objecf its own type; it satisfies none above predicates empty object. list Although re is a separate boolean type, any Scheme value can be used as a boolean value for purpose a conditional test. As explained in section 6.3.1, all values count as true in such a test except for #f. This report uses word true refer any Scheme value except #f, word false refer #f External representations An important concept in Scheme ( Lisp) is that external representation an object as a sequence characters. For example, an external representation integer 28 is sequence characters 28,, an external representation a list consisting integers 8 13 is sequence characters (8 13).. external representation an object is not necessarily unique. integer 28 also has representations #e #x1c,, list in previous paragraph also has representations ( ) (8. (13. ())) (see section 6.4). Many objects have stard external representations, but some, such as s, do not have stard representations (although particular implementations may define representations for m). An external representation may can be written in a program obtain corresponding object (see quote, section 4.1.2). External representations can also be used for input output. read (section ) parses external representations, write (section ) generates m. Toger, y provide an elegant powerful input/output facility. Note that sequence characters (+ 2 6) is not an external representation integer 8, even though it is an expression evaluating integer 8; rar, it is an external representation a three-element list, elements which are symbol + integers 2 6. Scheme s syntax has property that any sequence characters that is an expression is also external representation some object. This can lead confusion, since it may not be not always obvious out context wher a given sequence characters is intended denote data or program, but it is also a source power, since it facilitates writing programs such as interpreters compilers that treat programs as data (or vice versa).? syntax external representations various kinds objects accompanies description primitives for manipulating objects in appropriate sections chapter Srage model Variables objects such as pairs, vecrs, strings implicitly denote locations or sequences locations. A string, for example, denotes as many locations as re are characters in string. (se locations need not correspond a full machine word.) A new value may can be sred in one se locations using string-set!, but string continues denote same locations as before. An object fetched from a location, by a variable reference or by a such as car, vecr-ref, or string-ref, is equivalent in sense eqv? (section 6.1) object last sred in location before fetch. Every location is marked show wher it is in use. No variable or object ever refers a location that is not in use. Whenever this report speaks srage being allocated for a variable or object, what is meant is that an appropriate number locations are chosen from set locations that are not in use, chosen locations are marked indicate that y are now in use before variable or object is made denote m. In many systems it is desirable for constants(i.e. values literal expressions) reside in read-only-memory. To express this, it is convenient imagine that every Every object that denotes locations is associated with

11 3. Basic concepts 11 a flag telling wher that object eir mutable or immutable. In such systems literal constants Specifically: literal constants, strings returned by symbol->string, possibly environment returned by scheme-report-environment, are immutable objects, while all objects created by or s listed in this report are mutable. It is an error attempt sre a new value in a location that is denoted by an immutable object. se locations should be undersod as conceptual, not physical. Hence, y do not necessarily correspond memory addresses, even if y do, memory address may not be constant. Rationale: In many systems it desirable for constants (i.e. values literal expressions) reside in read-only memory. Making it an error alter constants permits this implementation strategy, while not requiring or systems distinguish between mutable immutable objects Proper tail recursion Implementations Scheme are required be properly tail-recursive tail recursive. Procedure calls that occur in certain syntactic contexts defined below are tail calls tail calls. A Scheme implementation is properly tail-recursive tail recursive if it supports an unbounded number active tail calls. A call is active if called may might still return. Note that this includes calls that may might be returned from eir by current continuation or by continuations captured earlier by call-with-current-continuation that are later invoked. In absence captured continuations, calls could return at most once active calls would be those that had not yet returned. A formal definition proper tail recursion can be found in [11]. Rationale: Intuitively, no space is needed for an active tail call because continuation that is used in tail call has same semantics as continuation passed containing call. Although an improper implementation might use a new continuation in call, a return this new continuation would be followed immediately by a return continuation passed. A properly tail-recursive tail recursive implementation returns that continuation directly. Proper tail recursion was one central ideas in Steele Sussman s original version Scheme. ir first Scheme interpreter implemented both functions acrs. Control flow was expressed using acrs, which differed from functions in that y passed ir results on anor acr instead returning a caller. In terminology this section, each acr finished with a tail call anor acr. Steele Sussman later observed that in ir interpreter code for dealing with acrs was identical that for functions thus re was no need include both in language. A tail call is a call that occurs in a tail context. Tail contexts are defined inductively. Note that a tail context is always determined with respect a particular lambda expression. last expression within body a lambda expression, shown as tail expression below, occurs in a tail context. same true bodies a case-lambda expression. (lambda formals definition * expression * tail expression ) If one following expressions is in a tail context, n subexpressions shown as tail expression are in a tail context. se were derived from rules in grammar given in chapter 7 by replacing some occurrences expression with tail expression. Only those rules that contain tail contexts are shown here. (if expression tail expression tail expression ) (if expression tail expression ) (cond cond clause + ) (cond cond clause * (else tail sequence )) (case expression case clause + ) (case expression case clause * (else tail sequence )) ( expression * tail expression ) (or expression * tail expression ) ( when test tail sequence ) (unless test tail sequence ) (let ( binding spec *) tail body ) (let variable ( binding spec *) tail body ) (let* ( binding spec *) tail body ) (letrec ( binding spec *) tail body ) (letrec* ( binding spec * ) tail body ) (let-values ( formals (let-syntax ( syntax spec *) tail body ) (letrec-syntax ( syntax spec *) tail body ) (begin tail sequence ) (do ( iteration spec *) ( test tail sequence ) expression *) where

12 12 Revised 7 Scheme cond clause ( test tail sequence ) case clause (( datum *) tail sequence ) tail body definition * tail sequence tail sequence expression * tail expression If a cond or case expression is in a tail context, has a clause form ( expression 1 => expression 2 ) n (implied) call that results from evaluation expression 2 is in a tail context. expression 2 itself is not in a tail context. Note that cond clause s appear in guard expressions 4.1. Primitive expression types Variable references variable syntax An expression consisting a variable (section 3.1) is a variable reference. value variable reference is value sred in location which variable is bound. It is an error reference an unbound variable. (define x 28) x = 28 as well as cond expressions. Certain built-in s are also required perform tail calls. first argument passed apply call-with-current-continuation, second argument passed call-with-values, must be called via a tail call. Similarly, eval must evaluate its first argument as if it were in tail position within eval. In following example only tail call is call f. None calls g or h are tail calls. reference x is in a tail context, but it is not a call thus is not a tail call. (lambda () (if (g) (let ((x (h))) x) ( (g) (f)))) Note: Implementations are allowed, but not required, recognize that some non-tail calls, such as call h above, can be evaluated as though y were tail calls. In example above, let expression could be compiled as a tail call h. ( possibility h returning an unexpected number values can be ignored, because in that case effect let is explicitly unspecified implementation-dependent.) 4. Expressions Expression types are categorized as primitive or derived. Primitive expression types include variables calls. Derived expression types are not semantically primitive, but can instead be defined as macros. With exception quasiquote, whose macro definition is complex, Suitable definitions some derived expressions are classified as library features. Suitable definitions are given in section 7.3. s also described in th associated with expression types. force, eager, make-parameter are chapter, because y are intimately delay, lazy, parameterize Literal expressions (quote datum ) datum constant syntax syntax syntax (quote datum ) evaluates datum. Datum may be any external representation a Scheme object (see section 3.3). This notation is used include literal constants in Scheme code. (quote a) = a (quote #(a b c)) = #(a b c) (quote (+ 1 2)) = (+ 1 2) (quote datum ) may be abbreviated as datum. two notations are equivalent in all respects. a = a #(a b c) = #(a b c) () = () (+ 1 2) = (+ 1 2) (quote a) = (quote a) a = (quote a) Numerical constants, string constants, character constants, bytevecr constants, boolean constants evaluate mselves mselves; y need not be quoted. "abc" = "abc" "abc" = "abc" = = #t = #t #t = #t As noted in section 3.4, it is an error alter a constant (i.e. value a literal expression) using a mutation like set-car! or string-set!.

13 4. Expressions Procedure calls ( operar oper 1... ) syntax A call is written by simply enclosing in parenses expressions for be called arguments be passed it. operar oper expressions are evaluated (in an unspecified order) resulting is passed resulting arguments. (+ 3 4) = 7 ((if #f + *) 3 4) = 12 A number s are available as values variables in initial environment; for example, addition multiplication s in above examples are values variables + *. New s are created by evaluating lambda expressions (see section 4.1.4). Procedure calls may return any number values (see values in section 6.10). With exception values s available in initial environment Most s defined in th report return one value or, for s such as apply, pass on values returned by a call one ir arguments. Exceptions are noted in individual descriptions. Procedure calls are also called combinations. Note: In contrast or dialects Lisp, order evaluation is unspecified, operar expression oper expressions are always evaluated with same evaluation rules. Note: Although order evaluation is orwise unspecified, effect any concurrent evaluation operar oper expressions is constrained be consistent with some sequential order evaluation. order evaluation may be chosen differently for each call. Note: In many dialects Lisp, empty combinationlist, (), is a legitimate expression evaluating itself. In Scheme, combinations must have at least one subexpression, so ()is not a syntactically valid expression. it error Procedures (lambda formals body ) syntax Syntax: Formals should be a formal arguments list as described below, body should be a sequence one or more expressions. Semantics: A lambda expression evaluates a. environment in effect when lambda expression was evaluated is remembered as part. When is later called with some actual arguments, environment in which lambda expression was evaluated will be extended by binding variables in formal argument list fresh locations, corresponding actual argument values will be sred in those locations, expressions in body lambda expression will be evaluated sequentially in extended environment. result(s) results last expression in body will be returned as result(s) results call. (lambda (x) (+ x x)) = a ((lambda (x) (+ x x)) 4) = 8 (define reverse-subtract (lambda (x y) (- y x))) (reverse-subtract 7 10) = 3 (define add4 (let ((x 4)) (lambda (y) (+ x y)))) (add4 6) = 10 Formals should have one following forms: ( variable 1... ): takes a fixed number arguments; when is called, arguments will be sred in bindings newly allocated locations that are bound corresponding variables. variable : takes any number arguments; when is called, sequence actual arguments is converted in a newly allocated list, list is sred in binding newly allocated location that bound variable. ( variable 1... variable n. variable n+1 ): If a space-delimited period precedes last variable, n takes n or more arguments, where n is number formal arguments before period (re must be it an error if re not at least one). value sred in binding last variable will be a newly allocated list actual arguments left over after all or actual arguments have been matched up against or formal arguments. It is an error for a variable appear more than once in formals. ((lambda x x) ) = ( ) ((lambda (x y. z) z) ) = (5 6) Each created as result evaluating a is (conceptually) tagged with a srage location, in order make work on s (see section 6.1) Conditionals (if test consequent alternate ) (if test consequent ) syntax syntax Syntax: Test, consequent, alternate may be arbitrary should be expressions.

14 14 Revised 7 Scheme Semantics: An if expression is evaluated as follows: first, test is evaluated. If it yields a true value (see section 6.3.1), n consequent is evaluated its value(s) is(are ) values are returned. Orwise alternate is evaluated its value(s) is(are ) values are returned. If test yields a false value no alternate is specified, n result expression is unspecified. (if (> 3 2) yes no) = yes (if (> 2 3) yes no) = no (if (> 3 2) (- 3 2) (+ 3 2)) = Assignments (set! variable expression ) syntax Expression is evaluated, resulting value is sred in location which variable is bound. must be It error if variable not bound eir in some region enclosing set! expression or at p level. result set! expression is unspecified. (define x 2) (+ x 1) = 3 (set! x 4) = unspecified (+ x 1) = Derived expression types constructs in this section are hygienic, as discussed in section 4.3. For reference purposes, section 7.3 gives macro definitions that will convert most constructs described in this section in primitive constructs described in previous section Conditionals (cond clause 1 clause 2... ) syntax else auxiliary syntax => auxiliary syntax Syntax: Each should be form Clauses take two forms, eir: ( test expression 1... ) one where test is any expression. Alternatively, a may be form, or ( test => expression ) last clause may be an else clause, which has form (else expression 1 expression 2... ). Semantics: A cond expression is evaluated by evaluating test expressions successive clause s in order until one m evaluates a true value (see section 6.3.1). When a test evaluates a true value, n remaining expression s in its clause are evaluated in order, result(s) results last expression in clause is(are ) are returned as result(s) results entire cond expression. If selected clause contains only test no expression s, n value test is returned as result. If selected clause uses => alternate form, n expression is evaluated. Its value must be It error if its value not a that accepts one argument; this. This is n called on value test value(s) values returned by this is(are ) are returned by cond expression. If all test s evaluate false values#f, re is no else clause, n result conditional expression is unspecified; if re is an else clause, n its expression s are evaluated in order, value(s) values last one is(are ) are returned. (cond ((> 3 2) greater) ((< 3 2) less)) = greater (cond ((> 3 3) greater) ((< 3 3) less) (else equal)) = equal (cond ((assv b ((a 1) (b 2))) => cadr) (else #f)) = 2 (case key clause 1 clause 2... ) syntax Syntax: Key may be any expression. Each clause should have form (( datum 1... ) expression 1 expression 2... ), where each datum is an external representation some object. All It is an error if any datum s must be distinct. are same anywhere in expression. Alternatively, a clause may be form (( datum 1... ) => expression ) last clause may be an else clause, which has form one forms or (else expression 1 expression 2... ) (else => expression ). Semantics: A case expression is evaluated as follows. Key is evaluated its result is compared against each datum. If result evaluating key is equivalent (in sense eqv?; see section 6.1) a datum, n expressions in corresponding clause are evaluated from left right result(s) in order results last expression in clause is(are ) are returned as result(s) results case expression.

15 If result evaluating key is different from every datum, n if re is an else clause its expressions are evaluated result(s) results last is(are ) result(s) are results case expression; orwise result case expression is unspecified. If selected clause or else clause uses => alternate form, n expression evaluated. It error if its value not accepting one argument. This n called on value key values returned by th are returned by case expression. ( (= 2 2) (> 2 1)) = #t ( (= 2 2) (< 2 1)) = #f ( 1 2 c (f g)) = (f g) () = #t (or test 1... ) syntax test expressions are evaluated from left right, value first expression that evaluates a true value (see section 6.3.1) is returned. Any remaining expressions are not evaluated. If all expressions evaluate false values, value last expression is returned. If #f or if re are no expressionsn, #f is returned. (or (= 2 2) (> 2 1)) = #t (or (= 2 2) (< 2 1)) = #t (or #f #f #f) = #f (or (memq b (a b c)) (/ 3 0)) = (b c) (when test expression 1 expression 2... ) a true value, expressions are evaluated in result when expression unspecified. following example outputs 12: syntax test expression evaluated, if it evaluates order. 4. Expressions 15 (when (= 1 1.0) (display "1") = (display unspecified "2") (unless test expression 1 expression 2... ) test expression evaluated, if it expressions are evaluated in order. unless expression unspecified. following example outputs nothing: syntax evaluates #f, result (unless (= 1 1.0) (display = "1") unspecified (display "2") (case (* 2 3) (( ) prime) (( ) composite)) = composite (case (car (c d)) Binding constructs ((a) a) ((b) b)) = unspecified three binding constructs let, let*, letrec, (case (car (c d)) letrec*, let-values, let*-values give Scheme a ((a e i o u) vowel) block structure, like Algol 60. syntax three ((w y) semivowel) first (else consonant) ) = consonant => (lambda four constructs is identical, but y differ in regions (x) x))) y establish for ir variable bindings. In a let expression, initial values are computed before any variables ( test 1... ) syntax become bound; in a let* expression, bindings test expressions are evaluated from left right, value first expression that evaluates a false evaluations are performed sequentially; while in a letrec expression letrec* expressions, all bindings are in value if any expression evaluates #f (see section 6.3.1), effect while ir initial values are being computed, thus #f is returned. Any remaining expressions are not evaluated. If all expressions evaluate true values, let*-values allowing mutually recursive definitions. let-values are analogous let let* respectively, value last expression is returned. If re are no but are designed hle multiple-valued expressions, expressions n #t is returned. binding different identifiers each returned value. (let bindings body ) Syntax: Bindings should have form (( variable 1 init 1 )... ), syntax where each init is an expression, body should be a sequence zero or more definitions followed by sequence one or more expressions as described in section It is an error for a variable appear more than once in list variables being bound. Semantics: init s are evaluated in current environment (in some unspecified order), variable s are bound fresh locations holding results, body is evaluated in extended environment, value(s) values last expression body is(are ) are returned. Each binding a variable has body as its region. (let ((x 2) (y 3)) (* x y)) = 6 (let ((x 2) (y 3)) (let ((x 7) (z (+ x y))) (* z x))) = 35

Revised 7 Report on the Algorithmic Language Scheme

Revised 7 Report on the Algorithmic Language Scheme Revised 7 Report on the Algorithmic Language Scheme ALEX SHINN, JOHN COWAN, AND ARTHUR A. GLECKLER (Editors) STEVEN GANZ ALEXEY RADUL OLIN SHIVERS AARON W. HSU JEFFREY T. READ ALARIC SNELL-PYM BRADLEY

More information

Revised 5 Report on the Algorithmic Language Scheme

Revised 5 Report on the Algorithmic Language Scheme HIGHER-ORDER AND SYMBOLIC COMPUTATION 11, 7 105 (1998) Revised 5 Report on the Algorithmic Language Scheme H. ABELSON, R.K. DYBVIG, C.T. HAYNES, G.J. ROZAS, N.I. ADAMS IV, D.P. FRIEDMAN, E. KOHLBECKER,

More information

Revised 5 Report on the Algorithmic Scheme. Language. Dedicated to the Memory of Robert Hieb CONTENTS

Revised 5 Report on the Algorithmic Scheme. Language. Dedicated to the Memory of Robert Hieb CONTENTS Revised 5 Report on the Algorithmic Scheme Language RICHARD KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Editors) H. ABELSON R.K. DYBVIG C.T. HAYNES G.J. ROZAS N. I. ADAMS IV D.P. FRIEDMAN E. KOHLBECKER

More information

MIT Scheme Reference Manual

MIT Scheme Reference Manual MIT Scheme Reference Manual Edition 1.95 for Scheme Release 7.6.0 26 November 2001 by Chris Hanson the MIT Scheme Team and a cast of thousands Copyright c 1988-2001 Massachusetts Institute of Technology

More information

2 Revised 5 Scheme INTRODUCTION Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and r

2 Revised 5 Scheme INTRODUCTION Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and r Revised 5 Report on the Algorithmic Language Scheme RICHARD KELSEY, WILLIAM CLINGER, AND JONATHAN REES (Editors) H. ABELSON R. K. DYBVIG C. T. HAYNES G. J. ROZAS N. I. ADAMS IV D. P. FRIEDMAN E. KOHLBECKER

More information

Organization of Programming Languages CS3200/5200N. Lecture 11

Organization of Programming Languages CS3200/5200N. Lecture 11 Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries

More information

Scheme Quick Reference

Scheme Quick Reference Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete

More information

Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten

Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten R6RS Status Report Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten February 24, 2006 1. Overview This status report describes the current state of the R 6 RS standardization

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

Implementing R7RS on an R6RS Scheme system

Implementing R7RS on an R6RS Scheme system Implementing R7RS on an R6RS Scheme system Takashi Kato Bell ID B.V. t.kato@bellid.com Abstract The Scheme language has three major standards; Revised 5 Report on the Algorithmic language Scheme (R5RS)

More information

Introduction to Scheme

Introduction to Scheme How do you describe them Introduction to Scheme Gul Agha CS 421 Fall 2006 A language is described by specifying its syntax and semantics Syntax: The rules for writing programs. We will use Context Free

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten

Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten R6RS Status Report Kent Dybvig, Will Clinger, Matthew Flatt, Mike Sperber, and Anton van Straaten June 21, 2006 1. Overview This status report describes the current state of the R 6 RS standardization

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

Revised 6 Report on the Algorithmic Language Scheme

Revised 6 Report on the Algorithmic Language Scheme JFP 19 (Supplement): 1 301, August 2009. c 2009 Cambridge University Press doi:10.1017/s0956796809990074 Printed in the United Kingdom 1 Revised 6 Report on the Algorithmic Language Scheme Abstract Programming

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

Scheme: Expressions & Procedures

Scheme: Expressions & Procedures Scheme: Expressions & Procedures CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, March 31, 2017 Glenn G. Chappell Department of Computer Science University

More information

Documentation for LISP in BASIC

Documentation for LISP in BASIC Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Notes on Higher Order Programming in Scheme. by Alexander Stepanov

Notes on Higher Order Programming in Scheme. by Alexander Stepanov by Alexander Stepanov August 1986 INTRODUCTION Why Scheme? Because it allows us to deal with: 1. Data Abstraction - it allows us to implement ADT (abstact data types) in a very special way. The issue of

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Revised 5.97 Report on the Algorithmic Language Scheme

Revised 5.97 Report on the Algorithmic Language Scheme Revised 5.97 Report on the Algorithmic Language Scheme MICHAEL SPERBER WILLIAM CLINGER, R. KENT DYBVIG, MATTHEW FLATT, ANTON VAN STRAATEN (Editors) RICHARD KELSEY, WILLIAM CLINGER, JONATHAN REES (Editors,

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

Functional Programming. Pure Functional Languages

Functional Programming. Pure Functional Languages Functional Programming Pure functional PLs S-expressions cons, car, cdr Defining functions read-eval-print loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

Functional programming in LISP

Functional programming in LISP Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of

More information

Class Structure. Prerequisites

Class Structure. Prerequisites Class Structure Procedural abstraction and recursion 6.037 - Structure and Interpretation of Computer Programs Mike Phillips, Benjamin Barenblat, Leon Shen, Ben Vandiver, Alex Vandiver, Arthur Migdal Massachusetts

More information

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

R6RSStatusReport. A brief history of Scheme. Guiding principles. Language overview. Design process. Public review

R6RSStatusReport. A brief history of Scheme. Guiding principles. Language overview. Design process. Public review R6RSStatusReport A brief history of Scheme Guiding principles Language overview Design process Public review BriefHistory 1975 First report on Scheme(Sussman/Steele) 1978 Revised report(steele/sussman)

More information

4.2 Variations on a Scheme -- Lazy Evaluation

4.2 Variations on a Scheme -- Lazy Evaluation [Go to first, previous, next page; contents; index] 4.2 Variations on a Scheme -- Lazy Evaluation Now that we have an evaluator expressed as a Lisp program, we can experiment with alternative choices in

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

C311 Lab #3 Representation Independence: Representation Independent Interpreters

C311 Lab #3 Representation Independence: Representation Independent Interpreters C311 Lab #3 Representation Independence: Representation Independent Interpreters Will Byrd webyrd@indiana.edu February 5, 2005 (based on Professor Friedman s lecture on January 29, 2004) 1 Introduction

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

More about Formatting. Olivier Danvy. Aarhus University. December Abstract

More about Formatting. Olivier Danvy. Aarhus University. December Abstract More about Formatting Olivier Danvy Computer Science Department Aarhus University (danvy@daimi.aau.dk) December 1993 Abstract This is an extension of the \format" example, in our POPL tutorial [2]. The

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

A Small Interpreted Language

A Small Interpreted Language A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter

6.037 Lecture 4. Interpretation. What is an interpreter? Why do we need an interpreter? Stages of an interpreter. Role of each part of the interpreter 6.037 Lecture 4 Interpretation Interpretation Parts of an interpreter Meta-circular Evaluator (Scheme-in-scheme!) A slight variation: dynamic scoping Original material by Eric Grimson Tweaked by Zev Benjamin,

More information

Handout 9: Imperative Programs and State

Handout 9: Imperative Programs and State 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 9: Imperative Programs and State Imperative

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP)

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

An Introduction to Scheme

An Introduction to Scheme An Introduction to Scheme Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Stéphane Ducasse 1 Scheme Minimal Statically scoped Functional Imperative Stack manipulation Specification

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Programming Languages

Programming Languages Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,

More information

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G. Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu

More information

Common Lisp Object System Specification. 1. Programmer Interface Concepts

Common Lisp Object System Specification. 1. Programmer Interface Concepts Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT Functional programming FP Foundations, Scheme (2 In Text: Chapter 15 LISP: John McCarthy 1958 MIT List Processing => Symbolic Manipulation First functional programming language Every version after the

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5 - The Meta-Circular

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XIII March 2 nd, 2006 1 Roadmap Functional Languages Lambda Calculus Intro to Scheme Basics Functions Bindings Equality Testing Searching 2 1 Functional Languages

More information

Functional Programming Lecture 1: Introduction

Functional Programming Lecture 1: Introduction Functional Programming Lecture 1: Introduction Viliam Lisý Artificial Intelligence Center Department of Computer Science FEE, Czech Technical University in Prague viliam.lisy@fel.cvut.cz Acknowledgements

More information

Optimizing Closures in O(0) time

Optimizing Closures in O(0) time Optimizing Closures in O(0 time Andrew W. Keep Cisco Systems, Inc. Indiana Univeristy akeep@cisco.com Alex Hearn Indiana University adhearn@cs.indiana.edu R. Kent Dybvig Cisco Systems, Inc. Indiana University

More information

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Modern Programming Languages. Lecture LISP Programming Language An Introduction Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CPS 506 Comparative Programming Languages. Programming Language Paradigm CPS 506 Comparative Programming Languages Functional Programming Language Paradigm Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages The First Functional Programming

More information

4/19/2018. Chapter 11 :: Functional Languages

4/19/2018. Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen

More information

Title. Authors. Status. 1. Abstract. 2. Rationale. 3. Specification. R6RS Syntax-Case Macros. Kent Dybvig

Title. Authors. Status. 1. Abstract. 2. Rationale. 3. Specification. R6RS Syntax-Case Macros. Kent Dybvig Title R6RS Syntax-Case Macros Authors Kent Dybvig Status This SRFI is being submitted by a member of the Scheme Language Editor s Committee as part of the R6RS Scheme standardization process. The purpose

More information

Project 2: Scheme Interpreter

Project 2: Scheme Interpreter Project 2: Scheme Interpreter CSC 4101, Fall 2017 Due: 12 November 2017 For this project, you will implement a simple Scheme interpreter in C++ or Java. Your interpreter should be able to handle the same

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

Essentials of Programming Languages Language

Essentials of Programming Languages Language Essentials of Programming Languages Language Version 5.3 August 6, 2012 The Essentials of Programming Languages language in DrRacket provides a subset of functions and syntactic forms of racket mostly

More information

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7 Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

More information

Software Paradigms (Lesson 4) Functional Programming Paradigm

Software Paradigms (Lesson 4) Functional Programming Paradigm Software Paradigms (Lesson 4) Functional Programming Paradigm Table of Contents 1 Introduction... 2 2 Evaluation of Functions... 3 3 Compositional (Construct) Operators... 4 4 Some Implementation Issues...

More information

CMSC 331 Final Exam Section 0201 December 18, 2000

CMSC 331 Final Exam Section 0201 December 18, 2000 CMSC 331 Final Exam Section 0201 December 18, 2000 Name: Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for

More information

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

Functional programming with Common Lisp

Functional programming with Common Lisp Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions

More information

Chapter 15. Functional Programming Languages

Chapter 15. Functional Programming Languages Chapter 15 Functional Programming Languages Copyright 2009 Addison-Wesley. All rights reserved. 1-2 Chapter 15 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages

More information

Essentials of Programming Languages Language

Essentials of Programming Languages Language Essentials of Programming Languages Language Version 6.90.0.26 April 20, 2018 The Essentials of Programming Languages language in DrRacket provides a subset of functions and syntactic forms of racket mostly

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

From Macrogeneration to Syntactic Abstraction

From Macrogeneration to Syntactic Abstraction From Macrogeneration to Syntactic Abstraction R. Kent Dybvig (dyb@cs.indiana.edu) Indiana University Computer Science Department Lindley Hall 215, Bloomington, IN 47408, USA October 1999 Abstract. In his

More information

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89

Symbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89 Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the

More information

COMPILER DESIGN LECTURE NOTES

COMPILER DESIGN LECTURE NOTES COMPILER DESIGN LECTURE NOTES UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing:

More information

Evaluating Scheme Expressions

Evaluating Scheme Expressions Evaluating Scheme Expressions How Scheme evaluates the expressions? (procedure arg 1... arg n ) Find the value of procedure Find the value of arg 1 Find the value of arg n Apply the value of procedure

More information

exp ::= (match exp clause :::) j clause :::) j * clause :::) j (match-let ([pat exp] :::) body) j (match-let* ([pat exp] :::) body) j (match-letrec ([

exp ::= (match exp clause :::) j clause :::) j * clause :::) j (match-let ([pat exp] :::) body) j (match-let* ([pat exp] :::) body) j (match-letrec ([ Pattern Matching for Scheme Andrew K. Wright and Bruce F. Duba Department of Computer Science Rice University Houston, TX 77251-1892 Version 1.12, May 24, 1995 Please direct questions or bug reports regarding

More information

15 Unification and Embedded Languages in Lisp

15 Unification and Embedded Languages in Lisp 15 Unification and Embedded Languages in Lisp Chapter Objectives Chapter Contents Pattern matching in Lisp: Database examples Full unification as required for Predicate Calculus problem solving Needed

More information

Reference Grammar Meta-notation: hfooi means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token.

Reference Grammar Meta-notation: hfooi means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token. Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2002 Handout 6 Decaf Language Definition Wednesday, September 4 The project for the 12-unit flavor

More information

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS 1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information