Dr. Jozo J. Dujmović
SCHEME REFERENCE CARD ARITHMETIC OPERATORS AND FUNCTIONS
(+
(1+
(sub1
(-1+
(minus
(*
Change the sign of
Raises
Convert
A variable initially set to 3.1415927 [M-] Integer division
Larger integer <=
Nearest integer of
Integer part of
pi
(quotient
(remainder
(ceiling
(floor
(round
(truncate
(modulo
(gcd
LIBRARY FUNCTIONS
(abs
(max
RELATIONAL OPERATORS
(=
The greatest common divisor The least common multiple
Absolute value of
Square root of nonnegative
Maximum of
Minimum of
The exponential of
Natural logarithm of
The trigonometric sine of
The arc cosine of
The arc tangent of
True if
True if
True if
True if
1
RECOGNIZERS
(number?
TESTS
(zero?
EQUIVALENCE PREDICATES
(eq?
(equal?
LOGICAL VALUES AND OPERATORS
#t#T tT ()#f#FNIL TRUE
FALSE
(not
(and
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
True if
and value (this test causes evaluation of expr.)
True if
values (same or dif. type), strings, and other atoms
True
False
A variable that some Schemes initially set to #T A variable that some Schemes initially set to #F Negation of
2
CHARACTERS
#\a #\B #\newline #\space (char->integer
(char->upcase
(char-alphabetic?
(char=?
#\tab #\TAB
Characters (printable and non printable)
Decimal ASCII value of
Return a character corresponding to the ASCII code
Return the upper case version of
Return the lower case version of
True if
True if
True if
True if
True if
True if
A string of characters
String containing
Append all strings in the sequence
A new copy of an existing
is bound to a new copy of
Fills an existing
Create a string whose value is “
Convert a character to string
ASCII to decimal number conv. of
Number to ASCII string conversion
True if
True if
(char-ci=?
STRINGS
“
(make-string
(define (string-copy
(string-fill!
(string->symbol
(symbol->string
(string->list
(list->string )
(string->number
(number->string
(string->number
(string-null?
3
(string
(string-ci=?
PAIRS AND LISTS
True if
True if
Return the given
Return the first element of pair (or the head of list) Return the second element of pair or the tail of list Empty list; both (car ‘()) and (cdr ‘()) return ‘() [M-] Combinationofupto4carandcdr(x={a|d})
Make a dotted pair (
Make a list of objects
Proper list ‘(
Length of a list. (length
Return a list with reversed order of elements Returns the zero-based element , assuming 0 <= index <= length-1. If index<0 it returns the car element, and if index>=length it returns ().
Returns a tail-sublist from . Replaces the head of
with the value of
with the value of
Create a vector containing given elements Definition of vector (‘ is sometimes omitted) Vector having
Returns vector[index]; 0 <= index <= length-1 vector[index] := value
Vector to list conversion
List to vector conversion
Define
Define
quote
(car
(cdr
‘( )
(cxxxxr )
(cons
‘(
(length )
(append )
(list-ref
(member ) (set-car!
VECTORS
(vector
(define v ‘#(
(make-vector
(vector-ref
(list->vector )
DEFINITIONS AND BINDINGS
(define
abbreviated: ‘
4
(set!
(let ( (
(let* ( (
(letrec ( (
FUNCTIONS
(lambda (
(define
(define
(map )
(andmap ) (for-each
)
(apply ) (eval
CONTROL STRUCTURES
(begin
(if
(cond
(
…………… (
be previously defined. The returned value is unspecified (some implementations, including pcs, return the value of
Local bindings var1:=expr1,… and then the application of these values to the expression1, expression2 … (the returned value is the value of the last expression)
A version of let where variables are bound in sequence from the first to the last (different from let)
A version of let allowing for mutual recursion
Anonymous function definition (lambda expression) Function definition (binding fname and lambda expr.) Abbreviated form of function definition.
Equivalent to (let ((
Function of an arbitrary number of arg’s Abbreviated form of the above func. of any # of arg. and return the list of resulting values Application of and to the results of map [MT-] Left-to-right application of function to list elements for side effect(s) only (the returned value is implementation-specific)
Exec.
Evaluate all expressions and return the value of the last expression in the sequence.
Evaluate all expressions and return the value of
Conditional execution: it returns the value of
Conditional execution: evaluate tests and execute either the sequence of expressions following the first that is nonnull, or the expressions in the last line.
It returns the value of the last executed expression.
5
(else
(case
(
…………… (
(case
(
…………… . (
Else clause can be omitted (but in such a case the result of cond for all false tests is unspecified.)
Conditional execution: evaluate
Conditional execution: evaluate
(do ((
(exit)
INPUT AND OUTPUT
(transcript-on “
(transcript-off) (load “
(display
termination test fails, the sequence of statements (the body of the loop) is executed.
After the execution the do variables are updated in unspecified order. The update is optional (can be omitted in some cases). If the termination-test is true then the termination expressions are evaluated from first to last and the last value is returned (if expressions are not specified then the returned value of do loop is the value of the
Close the transcript file and return to the level of the operating system.
Open for append (create if nonexistent) and begin echoing the terminal interaction to
Read and evaluate the contents of
Display the value of a single expression (in the case of pcs the cursor remains in the same line).
Same as (display “”)
Definition of input and output ports associated with
*the-non-printing-object*
(define inport (open-input-file “fname1”))
(define outport (open-output-file “fname2”)) files named “fname1” and “fname2” respectively
(read inport)
(display
(writeln
Scan and return next lexical element from input port Append the output string to file defined by outport Close input file related to
Print a sequence of expressions using display followed by a newline [M-]
6
(writeln (eval (read))) (display (eval (read))) (write
(pp
Read-evaluate-print sequence
Read-evaluate-print sequence
Write expression in machine-readable form, e.g. strings have double quotes (display and writeln use the human- readable form)
Pretty print the specified procedure (in the case of pcs it must be preceded by setting the debug mode)
(define (WL lst)
(cond ((null? lst) (display “”))
(else (display (car lst)) (display ” “) (WL (cdr lst)))))
(define W (lambda lst (WL lst)))
INTERNALS
scheme.ini patch.pcs
(edwin)
PCS-DEGUB-MODE
(set! PCS-DEBUG-MODE true)
[Inspect] ?
Display of a sequence of arguments (W
A file in the current working directory that is loaded and executed after the start of pcs (TI PC Scheme)
A file in the Scheme home directory that is loaded and executed after the start of pcs (TI PC Scheme). It is used to customize the initialization of Scheme.
Invoke the pcs EDWIN editor
An environmental pcs variable that must be set to #T to enable full tracing, inspecting, and pp
frame bindings
?
! ctrl-A — ctrl-B — ctrl-C — ctrl-D — ctrl-E — ctrl-G — ctrl-I — ctrl-L — ctrl-M — ctrl-P — ctrl-Q — ctrl-R — ctrl-S — ctrl-U — ctrl-V — ctrl-W —
TI Scheme Inspect Commands summary
— display this
— reinitialize
display All environment
display procedure call Backtrace
display Current environment frame bindings move Down to callee’s stack frame
Edit variable binding
Go (resume execution)
evaluate one expression and Inspect the result List current procedure
repeat the breakpoint Message
move to Parent environment’s frame
Quit (RESET to top level)
Return from BREAK with a value
move to Son environment’s frame
move Up to caller’s stack frame
eValuate one expression in current environment (Where) Display current stack frame
command INSPECT
Display of list elements (in cases without writeln)
To enter `ctrl-A’, press both `CTRL’ and `A’. [Inspect] Quit
[8] (exit)
NOTE: Some of the presented functions are implementation-dependent and may be unavailable in some Scheme implementations. Similarly, some Scheme implementations may have additional functions and features not included in this Reference Card. Features that are not available using Texas Instruments pcs are denoted by [T-], and those not available using MIT Scheme (installed on Libra) are denoted by [M-].
7