程序代写代做代考 scheme Dr. Jozo J. Dujmović

Dr. Jozo J. Dujmović
SCHEME REFERENCE CARD
ARITHMETIC OPERATORS AND FUNCTIONS
(pair? )
(null? ) (eof-object? ) (vector? ) (procedure? )
TESTS
(zero? ) (positive? ) (negative? ) (even? ) (odd? )
EQUIVALENCE PREDICATES
(eq? )
(equal? ) (eqv? )
True if is a dotted pair True if is an empty list True if is end-of-file marker True if is a vector
True if is a procedure (function)
True if = 0
True if > 0
True if < 0 True if is even True if is odd
True if is pointer-identical to , i.e.
bound to the same memory location (this test of physical sameness can be implementation-dependent) True if and have the same type and
(+ …) (- …) (add1 )
(1+ )
(sub1 )
(-1+ )
(minus )
(* …) (/ …) (expt ) (float )
pi
(quotient )
(remainder )
(ceiling )
(floor )
(round )
(truncate )
(modulo ) (gcd )
(lcm )
LIBRARY FUNCTIONS
(abs )
(sqrt )
(max …) (min …) (exp )
(log )
(sin )
(cos )
(tan )
(asin )
(acos )
(atan )
RELATIONAL OPERATORS
(= ) (<> ) (< ) (<= ) (> ) (>= )
RECOGNIZERS
(number? ) (boolean? ) (char? ) (string? ) (symbol? ) (list? ) (integer? ) (float? ) (real? ) (rational? ) (atom? )
+ + … – …
+ 1
+ 1
– 1
– 1
Change the sign of [M-] * * … / / …
Raises to the power Convert to floating point
A variable initially set to 3.1415927 Integer division / (sign())(fraction(/) Smallest integer >=
Larger integer <= Nearest integer of Integer part of
modulo The greatest common divisor
The least common multiple
Absolute value of
Square root of nonnegative
Maximum of , , …
Minimum of , , …
The exponential of (base = e)
Natural logarithm of
The trigonometric sine of in radians The trigonometric cosine of in radians The trigonometric tangent of in radians The arc sine of
The arc cosine of
The arc tangent of
True if = (numerical expr.) True if <>
True if <
True if <=
True if > True if >=
True if is a number
True if is Boolean
True if is a character
True if is a string
True if is a symbol
True if is a list [T-] True if is an integer
True if is floating point True if is a real number True if is a rational number True if is an atom
[MT-] [M-]

(make-string )
(string-length )
(string-append …) Append all strings in the sequence (string-copy ) A new copy of an existing
[M-] [M-]
[M-]
LOGICAL VALUES AND OPERATORS
#t #T t T ()#f#FNIL TRUE
FALSE
(not )
(and …) [(and) yields #T]
True
False
A variable that some Schemes initially set to #T A variable that some Schemes initially set to #F Negation of ; (procedure? not) yields #T Short-circuit conjunction of any # of … Short-circuit disjunction of any # of … (and and or don’t have the procedure status [recognized by procedure?])
(or …)
[(or) yields #F]
CHARACTERS
value (this test causes evaluation of expr.) True if and are equal numeric (same or dif. type), strings, and other atoms
values
#\a #\B #\newline #\space #\tab #\TAB Characters (printable and non printable) (char->integer ) Decimal ASCII value of (integer->char ) Return a character corresponding to the ASCII code (char->upcase ) Return the upper case version of
(char->downcase ) (char-alphabetic? ) (char-numeric? ) (char-whitespace? ) (char-upper-case? ) (char-lower-case? ) (char=? ) (char ) (char<=? ) (char>? ) (char>=? ) (char-ci=? ) (char-ci ) (char-ci<=? ) (char-ci>? ) (char-ci>=? )
STRINGS
Return the lower case version of
True if is an alphabetic character
True if is a numeric character
True if is space, newline, tab, page, return True if belongs to {A, B, …, Z}
True if belongs to {a, b, …, z}
True if = (case sensitive) True if < (case sensitive) True if <= (case sensitive) True if > (case sensitive) True if >= (case sensitive) True if = (case insensitive) True if < (case insensitive) True if <= (case insensitive) True if > (case insensitive) True if >= (case insensitive)
A string of characters
String containing copies of Length of string (number of elements)

(define (string-copy )) (define )
(string-fill! ) (string-set! ) (string-ref ) (substring )
is bound to a new copy of and are synonyms that point to the same data object
Fills an existing with ‘s string[index]:=char; 0 <= index <= length-1 Returns string[index]; 0<=index<=length-1 Extracts elements string[start]..string[end-1]; the length of substring = end - start Create a symbol whose name is Create a string whose value is “” Convert to list of characters
Convert a character to string
ASCII to decimal number conv. of [T-] Dec. number to ASCII string conversion [T-]
DEFINITIONS AND BINDINGS
(define )
(define )
(set! )
(let ( ( ) …) … )
(let* ( ( ) …) … )
(letrec ( ( ) …) … )
FUNCTIONS
(lambda (…) …) (define )
(define ( …) …) ((lambda (…) ) …)
(string->symbol )
(symbol->string )
(string->list )
(list->string )
(string->number )
(number->string )
(string->number ) ASCII string to number conversion (number->string Number to ASCII string conversion
Define without binding.
Define and assign it the value of . The returned value is the symbol (e.g. (symbol? (define a 1)) returns #T)
:= ; must 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
(string-null? )
(string=? ) (string ) (string<=? ) (string>? ) (string-ci=? ) (string-ci ) (string-ci<=? ) (string-ci>? ) (string-ci>=? )
PAIRS AND LISTS
True if is an empty string
True if = (case sensitive) True if < (case sensitive) True if <= (case sensitive) True if >= (case sensitive) True if = (case insensitive) True if < (case insensitive) True if <= (case insensitive) True if > (case insensitive) True if >= (case insensitive)
Return the given unevaluated
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 ‘( )
Anonymous function definition (lambda expression) Function definition (binding fname and
quote (car ) (cdr ) ‘()
abbreviated: ‘
(define (lambda …))
(define(.)…) Abbreviated form of the above func. of any # of arg. ( …) is bound to the list ( …) (map ) Apply sequentially to each element of
(cxxxxr )
(cons )
(list …)
‘( . ( . ( . ())))
‘(.(.)) Improperlist'(.)
(andmap ) (for-each )
(apply ) (eval )
CONTROL STRUCTURES (begin …)
the 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. using list elements as arguments Evaluation of
Evaluate all expressions and return the value of the
last expression in the sequence.
Evaluate all expressions and return the value of
(length )
(append …) (reverse )
(list-ref )
(member ) (set-car! ) (set-cdr! ) VECTORS
Length of a list. (length ) => 0.
Append lists
Return a list with reversed order of elements Returns the zero-based element from the , assuming 0 <= index <= length-1. If index<0 it returns the car element, and if index>=length it returns ().
Returns a tail-sublist from to the end of
list, or () if is not in the .
Replaces the head of with the value of
(the returned value is implementation-dep.)
Replaces the tail of with the value of (thevalueofisusuallyalist) ……………
(vector …)Create a vector containing given elements
( …) (else …) )
(case
( …) ( …)
(define v ‘#( …))
(make-vector )
(make-vector )
(vector-length )
(vector-ref )Returns vector[index]; 0 <= index <= length-1 (vector-set! ) vector[index] := value
(vector->list ) Vector to list conversion (list->vector ) List to vector conversion
…………… Evaluateallexpressionsintheselectedlistand ( …) return the value of the last executed expression
(else …) )
Definition of vector (‘ is sometimes omitted) Vector having unspecified elements Vector containing copies of Returns the length of
(begin0 …)
(if )
Conditional execution: it returns the value of in cases where =#T. If =#F then the returned value is ; in cases where is not specified the result of if expression is unspecified
(some implementations, including pcs, return ( ) ).
Conditional execution: evaluate tests and execute either the sequence of expressions following the first thatisnonnull,ortheexpressionsinthelastline.
It returns the value of the last executed expression. Else clause can be omitted (but in such a case the result of cond for all false tests is unspecified.)
Conditional execution: evaluate and compare its value with , , … until the eqv? comparison returns true.
(cond
( …) ( …)
.
lambda expr.)
Abbreviated form of function definition. Equivalent to(let (( )…) ) are local varibles
Function of an arbitrary number of arg’s

(case
( …) ( …)
Conditional execution: evaluate and compare its value with , , … until the memv? comparison
[Inspect] ? TI Scheme Inspect Commands ? — display this command summary
! — reinitialize INSPECT
ctrl-A — display All environment frame bindings ctrl-B — display procedure call Backtrace
ctrl-C — display Current environment frame bindings ctrl-D — move Down to callee’s stack frame
ctrl-E — Edit variable binding
ctrl-G — Go (resume execution)
ctrl-I — evaluate one expression and Inspect the result ctrl-L — List current procedure
ctrl-M — repeat the breakpoint Message
ctrl-P — move to Parent environment’s frame
ctrl-Q — Quit (RESET to top level)
ctrl-R — Return from BREAK with a value
ctrl-S — move to Son environment’s frame
ctrl-U — move Up to caller’s stack frame
ctrl-V — eValuate one expression in current environment ctrl-W — (Where) Display current stack frame
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-].
……………. returnstrue.Evaluateallexpressionsin ( …) the selected list and return the value of the (else …) ) last executed expression.
(do (( ) …) ( …)
…)
Initial values are bound to corresponding variables in unspecified order. If the 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 ).
(exit) Close the transcript file and return to the level of the operating system.
INPUT AND OUTPUT
(transcript-on ““)
(transcript-off) (load ““) (read)
(display )
Open for append (create if nonexistent) and begin echoing the terminal interaction to . Close the transcript file
Read and evaluate the contents of . Read operator returns a scanned value from the keyboard.
Display the value of a single expression (in the case of pcs the cursor remains in the same line).
Same as (display “”)
*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 outport) (close-input-port ) (close-output-port ) (newline)
(writeln …)
(writeln (eval (read))) (display (eval (read))) (write )
(pp )
Scan and return next lexical element from input port Append the output string to file defined by outport Close input file related to Close output file related to New line (LF+CR)
Print a sequence of expressions using display followed by a newline [M-] 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)
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
Definition of input and output ports associated with
Display of list elements (in cases without writeln)