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

Dr. Jozo J. Dujmović
SCHEME REFERENCE CARD ARITHMETIC OPERATORS AND FUNCTIONS
(+ …) (- …) (add1 )
(1+ )
(sub1 )
(-1+ )
(minus )
(* …) (/ …) (expt ) (float )
+ + …
– …
+ 1 [M-] + 1
– 1 [M-] – 1
Change the sign of [M-] * * …
/ / …
Raises to the power
Convert to floating point
A variable initially set to 3.1415927 [M-] Integer division / (sign())(fraction(/) Smallest integer >=
Larger integer <=
Nearest integer of
Integer part of
pi
(quotient )
(remainder )
(ceiling )
(floor )
(round )
(truncate )
(modulo ) modulo
(gcd ) (lcm )
LIBRARY FUNCTIONS
(abs ) (sqrt )
(max (min (exp ) (log ) (sin ) (cos ) (tan ) (asin ) (acos ) (atan )
RELATIONAL OPERATORS
(= ) (<> ) (< ) (<= ) (> ) (>= )
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 >=
…) …)
1

RECOGNIZERS
(number? ) (boolean? ) (char? ) (string? ) (symbol? ) (list? ) (integer? ) (float? ) (real? ) (rational? ) (atom? ) (pair? ) (null? ) (eof-object? ) (vector? ) (procedure? )
TESTS
(zero? ) (positive? ) (negative? ) (even? ) (odd? )
EQUIVALENCE PREDICATES
(eq? )
(equal? ) (eqv? )
LOGICAL VALUES AND OPERATORS
#t#T tT ()#f#FNIL TRUE
FALSE
(not )
(and …) [(and) yields #T] (or …) [(or) yields #F]
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 [MT-] True if is an atom [M-] 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 value (this test causes evaluation of expr.)
True if and are equal numeric
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 ; (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?])
2

CHARACTERS
#\a #\B #\newline #\space (char->integer ) (integer->char )
(char->upcase ) (char->downcase )
(char-alphabetic? ) (char-numeric? ) (char-whitespace? ) (char-upper-case? ) (char-lower-case? )
(char=? ) (char ) (char<=? ) (char>? ) (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 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)
Append all strings in the sequence
A new copy of an existing
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-] ASCII string to number conversion
Number to ASCII string conversion
True if is an empty string
True if = (case sensitive)
(char-ci=? ) (char-ci ) (char-ci<=? ) (char-ci>? ) (char-ci>=? )
STRINGS

(make-string ) (string-length ) (string-append …) (string-copy )
(define (string-copy )) (define )
(string-fill! ) (string-set! ) (string-ref ) (substring )
(string->symbol )
(symbol->string )
(string->list )
(list->string )
(string->number )
(number->string )
(string->number ) (number->string
(string-null? ) (string=? )
3

(string ) (string<=? ) (string>? )
(string-ci=? ) (string-ci ) (string-ci<=? ) (string-ci>? ) (string-ci>=? )
PAIRS AND LISTS
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 ‘( ) Improper list ‘( . )
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 (the value of is usually a list)
Create a vector containing given elements Definition of vector (‘ is sometimes omitted) Vector having unspecified elements Vector containing copies of Returns the length of
Returns vector[index]; 0 <= index <= length-1 vector[index] := value Vector to list conversion List to vector conversion Define without binding.
Define and assign it the value of . The returned value is the symbol
quote
(car )
(cdr )
‘( )
(cxxxxr )
(cons ) (list …)
‘( . ( . ( . ()))) ‘( . ( . ))
(length )
(append …) (reverse )
(list-ref )
(member ) (set-car! ) (set-cdr! )
VECTORS
(vector …)
(define v ‘#( …)) (make-vector )
(make-vector ) (vector-length )
(vector-ref ) (vector-set! ) (vector->list )
(list->vector )
DEFINITIONS AND BINDINGS
(define ) (define )
abbreviated: ‘
4

(set! )
(let ( ( ) …) … )
(let* ( ( ) …) … )
(letrec ( ( ) …) … )
FUNCTIONS
(lambda (…) …)
(define ) (define ( …) …) ((lambda (…) ) …)
(define (lambda …)) (define(.)…) ( …)
(map )
(andmap ) (for-each )
(apply ) (eval )
CONTROL STRUCTURES
(begin …) (begin0 …)
(if )
(cond
( …) ( …)
…………… ( …)
(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
Anonymous function definition (lambda expression) Function definition (binding fname and lambda expr.) Abbreviated form of function definition.
Equivalent to (let (( )…) ) are local varibles
Function of an arbitrary number of arg’s Abbreviated form of the above func. of any # of arg. is bound to the list ( …) Apply sequentially to each element of 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
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 that is nonnull, or the expressions in the last line.
It returns the value of the last executed expression.
5

(else …) )
(case
( …) ( …)
…………… ( …) (else …) )
(case
( …) ( …)
…………… . ( …) (else …) )
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. Evaluate all expressions in the selected list and return the value of the last executed expression.
Conditional execution: evaluate and compare its value with , , … until the memv? comparison returns true. Evaluate all expressions in the selected list and return the value of the last executed expression.
(do (( ( …)
…)
(exit)
INPUT AND OUTPUT
(transcript-on ““)
(transcript-off) (load ““) (read)
(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 . 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 “”)
Definition of input and output ports associated with
) …) Initial values are bound to corresponding variables in unspecified order. If the
*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 …)
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-]
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