first stage in documentation reorg
This commit is contained in:
parent
92c62d7417
commit
5fbb660a56
|
@ -1,40 +0,0 @@
|
|||
If we eliminate char from HtDP/I, we need to add re-think the following
|
||||
functions:
|
||||
|
||||
integer->char -- 1string version
|
||||
|
||||
char->integer -- 1string version
|
||||
|
||||
string->list -- explode
|
||||
|
||||
list->string -- implode
|
||||
|
||||
char-numeric? -- in a sense string->number is enough
|
||||
(number? (string->number s))
|
||||
|
||||
char-alphabetic? --
|
||||
(andmap (lambda (c)
|
||||
(or (string<=? "A" x "Z") (string<=? "a" x "z")))
|
||||
(string->list s))
|
||||
|
||||
char-whitespace? -- (andmap char-whitespace? s)
|
||||
|
||||
char-upper-case? -- (string<=? "A" x "Z")
|
||||
|
||||
char-lower-case? -- (string<=? "a" x "z")
|
||||
|
||||
char-upcase string-upcase
|
||||
|
||||
char-downcase string-downcase
|
||||
|
||||
make-string : Nat Char -> String
|
||||
Nat String1 -> String
|
||||
|
||||
string : Char ... -> String
|
||||
delete, string-append is enough
|
||||
|
||||
string-ref : String Nat -> Char
|
||||
ith
|
||||
|
||||
NOTE:
|
||||
substring consumes 2 or 3 arguments
|
|
@ -1,4 +1,4 @@
|
|||
(module advanced-funs scheme/base
|
||||
#lang at-exp scheme/base
|
||||
(require "teachprims.rkt"
|
||||
mzlib/etc
|
||||
mzlib/list
|
||||
|
@ -9,172 +9,144 @@
|
|||
"../posn.rkt"
|
||||
(for-syntax scheme/base))
|
||||
|
||||
(define pp
|
||||
(let ([pretty-print (lambda (v)
|
||||
(pretty-write v))])
|
||||
pretty-print))
|
||||
(require "provide-and-scribble.rkt" scribble/manual)
|
||||
|
||||
(define pp (let ([pretty-print (lambda (v) (pretty-write v))]) pretty-print))
|
||||
|
||||
(provide-and-document
|
||||
;; somehow null got lost during the scribblization
|
||||
(provide null)
|
||||
|
||||
(provide-and-scribble
|
||||
procedures
|
||||
|
||||
("Numbers: Integers, Rationals, Reals, Complex, Exacts, Inexacts"
|
||||
(random (case->
|
||||
(integer -> integer)
|
||||
(-> (and/c real inexact? (>/c 0) (</c 1))))
|
||||
"Generates a random natural number less than some given integer, or to generate a random inexact number between 0.0 and 1.0 exclusive."))
|
||||
|
||||
@defproc[(random [x integer]) integer]{Generates a random natural number less than some given integer, or to generate a random inexact number between 0.0 and 1.0 exclusive.}
|
||||
)
|
||||
|
||||
("Reading and Printing"
|
||||
(with-input-from-file (string (-> any) -> any)
|
||||
"Opens the named input file and to extract all input from there.")
|
||||
(with-output-to-file (string (-> any) -> any)
|
||||
"Opens the named output file and to put all output there.")
|
||||
(with-input-from-string (string (-> any) -> any)
|
||||
"Turns the given string into input for read* operations.")
|
||||
(with-output-to-string (string (-> any) -> any)
|
||||
"Produces a string from all write/display/print operations.")
|
||||
@defproc[(with-input-from-file [f string] [p (-> any)]) any]{Opens the named input file and to extract all input from there.}
|
||||
@defproc[(with-output-to-file [f string] [p (-> any)]) any]{Opens the named output file and to put all output there.}
|
||||
@defproc[(with-input-from-string [s string] [p (-> any)]) any]{Turns the given string into input for read* operations.}
|
||||
@defproc[(with-output-to-string [s string] [p (-> any)]) any]{Produces a string from all write/display/print operations.}
|
||||
|
||||
|
||||
(print (any -> void)
|
||||
"Prints the argument as a value to stdout.")
|
||||
(display (any -> void)
|
||||
"Prints the argument to stdout (without quotes on symbols and strings, etc.).")
|
||||
(write (any -> void)
|
||||
"Prints the argument to stdout (in a traditional style that is somewhere between print and display).")
|
||||
((pp pretty-print) (any -> void)
|
||||
"Like write, but with standard newlines and indentation.")
|
||||
(printf (string any ... -> void)
|
||||
"Formats the rest of the arguments according to the first argument and print it to stdout.")
|
||||
(newline (-> void)
|
||||
"Prints a newline to stdout.")
|
||||
(read (-> sexp) "Reads input from the user."))
|
||||
@defproc[(print [x any]) void]{Prints the argument as a value to stdout.}
|
||||
@defproc[(display [x any]) void]{Prints the argument to stdout (without quotes on symbols and strings, etc.).}
|
||||
@defproc[(write [x any]) void]{Prints the argument to stdout (in a traditional style that is somewhere between print and display).}
|
||||
@defproc[((pp pretty-print) [x any]) void]{Like write, but with standard newlines and indentation.}
|
||||
@defproc[(printf [f string] [x any] ...) void]{Formats the rest of the arguments according to the first argument and print it to stdout.}
|
||||
@defproc[(newline) void]{Prints a newline to stdout.}
|
||||
@defproc[(read) sexp]{Reads input from the user.})
|
||||
|
||||
("Lists"
|
||||
(list? (any -> boolean)
|
||||
"Determines whether some value is a list.")
|
||||
|
||||
((advanced-list* list*) (any ... (listof any) -> (listof any))
|
||||
"Constructs a list by adding multiple items to a list.")
|
||||
|
||||
((advanced-cons cons) (X (listof X) -> (listof X))
|
||||
"Constructs a list.")
|
||||
|
||||
((advanced-append append) ((listof any) ... -> (listof any))
|
||||
"Creates a single list from several.")
|
||||
|
||||
(assoc
|
||||
(any (listof any) -> (listof any) or false)
|
||||
"Produces the first element on the list whose first is equal? to v; otherwise it produces false."))
|
||||
@defproc[(list? [x any]) boolean]{Determines whether some value is a list.}
|
||||
@defproc[((advanced-list* list*) [x any] ... [l (listof any)]) (listof any)]{Constructs a list by adding multiple items to a list.}
|
||||
@defproc[((advanced-cons cons) [x X] [l (listof X)]) (listof X)]{Constructs a list.}
|
||||
@defproc[((advanced-append append) [l (listof any)] ...) (listof any)]{Creates a single list from several.}
|
||||
@defproc[(assoc [x any] [l (listof any)]) (union (listof any) false)]{Produces the first element on the list whose first is equal? to v; otherwise it produces false.})
|
||||
|
||||
("Misc"
|
||||
(gensym (-> symbol?)
|
||||
"Generates a new symbol, different from all symbols in the program.")
|
||||
(sleep (-> positive-number void)
|
||||
"Causes the program to sleep for the given number of seconds.")
|
||||
(current-milliseconds (-> exact-integer)
|
||||
"Returns the current “time” in fixnum milliseconds (possibly negative).")
|
||||
|
||||
(force (delay -> any) "Finds the delayed value; see also delay.")
|
||||
(promise? (any -> boolean) "Determines if a value is delayed.")
|
||||
(void (-> void) "Produces a void value.")
|
||||
(void? (any -> boolean) "Determines if a value is void."))
|
||||
@defproc[(gensym) symbol?]{Generates a new symbol, different from all symbols in the program.}
|
||||
@defproc[(sleep [sec positive-num]) void]{Causes the program to sleep for the given number of seconds.}
|
||||
@defproc[(current-milliseconds) exact-integer]{Returns the current “time” in fixnum milliseconds (possibly negative).}
|
||||
@defproc[(force [v any]) any]{Finds the delayed value; see also delay.}
|
||||
@defproc[(promise? [x any]) boolean?]{Determines if a value is delayed.}
|
||||
@defproc[(void) void?]{Produces a void value.}
|
||||
@defproc[(void? [x any]) boolean?]{Determines if a value is void.})
|
||||
|
||||
("Posns"
|
||||
(set-posn-x! (posn any -> void) "Updates the x component of a posn.")
|
||||
(set-posn-y! (posn any -> void) "Updates the y component of a posn."))
|
||||
@defproc[(set-posn-x! [p posn] [x any]) void?]{Updates the x component of a posn.}
|
||||
@defproc[(set-posn-y! [p posn] [x any]) void]{Updates the y component of a posn.})
|
||||
|
||||
("Vectors"
|
||||
(vector (X ... -> (vector X ...)) "Constructs a vector.")
|
||||
(make-vector (number X -> (vectorof X)) "Constructs a vector.")
|
||||
(build-vector (nat (nat -> X) -> (vectorof X)) "Constructs a vector.")
|
||||
(vector-ref ((vector X) nat -> X) "Extracts an element from a vector.")
|
||||
(vector-length ((vector X) -> nat) "Determines the length of a vector.")
|
||||
(vector-set! ((vectorof X) nat X -> void) "Updates a vector.")
|
||||
(vector->list ((vectorof X) -> (listof X)) "creates a list of values from the vector of values.")
|
||||
(vector? (any -> boolean) "Determines if a value is a vector."))
|
||||
@defproc[(vector [x X] ...) (vector X ...)]{Constructs a vector.}
|
||||
@defproc[(make-vector [n number] [x X]) (vectorof X)]{Constructs a vector.}
|
||||
@defproc[(build-vector [n nat] [f (nat -> X)]) (vectorof X)]{Constructs a vector.}
|
||||
@defproc[(vector-ref [v (vector X)] [n nat]) X]{Extracts an element from a vector.}
|
||||
@defproc[(vector-length [v (vector X)]) nat]{Determines the length of a vector.}
|
||||
@defproc[(vector-set! [v (vectorof X)][n nat][x X]) void]{Updates a vector.}
|
||||
@defproc[(vector->list [v (vectorof X)]) (listof X)]{creates a list of values from the vector of values.}
|
||||
@defproc[(vector? [x any]) boolean]{Determines if a value is a vector.})
|
||||
|
||||
("Boxes"
|
||||
(box (any -> box)
|
||||
"Constructs a box.")
|
||||
(unbox (box -> any)
|
||||
"Extracts the boxed value.")
|
||||
(set-box! (box any -> void)
|
||||
"Updates a box.")
|
||||
(box? (any -> boolean)
|
||||
"Determines if a value is a box."))
|
||||
@defproc[(box [x any/c]) box?]{Constructs a box.}
|
||||
@defproc[(unbox [b box?]) any]{Extracts the boxed value.}
|
||||
@defproc[(set-box! [b box?][x any/c]) void]{Updates a box.}
|
||||
@defproc[(box? [x any/c]) boolean?]{Determines if a value is a box.})
|
||||
|
||||
("Hash Tables"
|
||||
((advanced-make-hash make-hash)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs a mutable hash table from an optional list of mappings that uses equal? for comparisions.")
|
||||
((advanced-make-hasheq make-hasheq)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs a mutable hash table from an optional list of mappings that uses eq? for comparisions.")
|
||||
((advanced-make-hasheqv make-hasheqv)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs a mutable hash table from an optional list of mappings that uses eqv? for comparisions.")
|
||||
((advanced-make-immutable-hash make-immutable-hash)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs an immutable hash table from an optional list of mappings that uses equal? for comparisions.")
|
||||
((advanced-make-immutable-hasheq make-immutable-hasheq)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs an immutable hash table from an optional list of mappings that uses eq? for comparisions.")
|
||||
((advanced-make-immutable-hasheqv make-immutable-hasheqv)
|
||||
(case->
|
||||
(-> (hash X Y))
|
||||
((listof (list X Y)) -> (hash X Y)))
|
||||
"Constructs an immutable hash table from an optional list of mappings that uses eqv? for comparisions.")
|
||||
(hash-set! ((hash X Y) X Y -> void)
|
||||
"Updates a mutable hash table with a new mapping.")
|
||||
(hash-set ((hash X Y) X Y -> (hash X Y))
|
||||
"Constructs an immutable hash table with one new mapping from an existing immutable hash table.")
|
||||
(hash-ref (case->
|
||||
((hash X Y) X -> Y)
|
||||
((hash X Y) X Y -> Y)
|
||||
((hash X Y) X (-> Y) -> Y))
|
||||
"Extracts the value associated with a key from a hash table; the three argument case allows a default value or default value computation.")
|
||||
(hash-ref! (case->
|
||||
((hash X Y) X Y -> Y)
|
||||
((hash X Y) X (-> Y) -> Y))
|
||||
"Extracts the value associated with a key from a mutable hash table; if the key does not have an mapping, the third argument is used as the value (or used to compute the value) and is added to the hash table associated with the key.")
|
||||
(hash-update! (case->
|
||||
((hash X Y) X (Y -> Y) -> void)
|
||||
((hash X Y) X (Y -> Y) Y -> void)
|
||||
((hash X Y) X (Y -> Y) (-> Y) -> void))
|
||||
"Composes hash-ref and hash-set! to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref.")
|
||||
(hash-update (case->
|
||||
((hash X Y) X (Y -> Y) -> (hash X Y))
|
||||
((hash X Y) X (Y -> Y) Y -> (hash X Y))
|
||||
((hash X Y) X (Y -> Y) (-> Y) -> (hash X Y)))
|
||||
"Composes hash-ref and hash-set to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref.")
|
||||
(hash-has-key? ((hash X Y) X -> boolean)
|
||||
"Determines if a key is associated with a value in a hash table.")
|
||||
(hash-remove! ((hash X Y) X -> void)
|
||||
"Removes an mapping from a mutable hash table.")
|
||||
(hash-remove ((hash X Y) X -> (hash X Y))
|
||||
"Constructs an immutable hash table with one less mapping than an existing immutable hash table.")
|
||||
(hash-map ((hash X Y) (X Y -> A) -> (listof A))
|
||||
"Constructs a new list by applying a function to each mapping of a hash table.")
|
||||
(hash-for-each ((hash X Y) (X Y -> any) -> void)
|
||||
"Applies a function to each mapping of a hash table for effect only.")
|
||||
(hash-count (hash -> integer)
|
||||
"Determines the number of keys mapped by a hash table.")
|
||||
(hash-copy (hash -> hash)
|
||||
"Copies a hash table.")
|
||||
(hash? (any -> boolean)
|
||||
"Determines if a value is a hash table.")
|
||||
(hash-equal? (hash -> boolean)
|
||||
"Determines if a hash table uses equal? for comparisions.")
|
||||
(hash-eq? (hash -> boolean)
|
||||
"Determines if a hash table uses eq? for comparisions.")
|
||||
(hash-eqv? (hash -> boolean)
|
||||
"Determines if a hash table uses eqv? for comparisions."))))
|
||||
@defproc[((advanced-make-hash make-hash)) (hash X Y)]{Constructs a mutable hash table from an optional list of mappings that uses equal? for comparisions.}
|
||||
@defproc[((advanced-make-hasheq make-hasheq)) (hash X Y)]{Constructs a mutable hash table from an optional list of mappings that uses eq? for comparisions.}
|
||||
@defproc[((advanced-make-hasheqv make-hasheqv)) (hash X Y)]{Constructs a mutable hash table from an optional list of mappings that uses eqv? for comparisions.}
|
||||
@defproc[((advanced-make-immutable-hash make-immutable-hash)) (hash X Y)]{Constructs an immutable hash table from an optional list of mappings that uses equal? for comparisions.}
|
||||
@defproc[((advanced-make-immutable-hasheq make-immutable-hasheq)) (hash X Y)]{Constructs an immutable hash table from an optional list of mappings that uses eq? for comparisions.}
|
||||
@defproc[((advanced-make-immutable-hasheqv make-immutable-hasheqv)) (hash X Y)]{Constructs an immutable hash table from an optional list of mappings that uses eqv? for comparisions.}
|
||||
@defproc[(hash-set! [h (hash X Y)] [k X] [v Y]) void?]{Updates a mutable hash table with a new mapping.}
|
||||
@defproc[(hash-set [h (hash X Y)] [k X] [v Y]) (hash X Y)]{Constructs an immutable hash table with one new mapping from an existing immutable hash table.}
|
||||
@defproc[(hash-ref [h (hash X Y)] [k X]) Y]{Extracts the value associated with a key from a hash table; the three argument case allows a default value or default value computation.}
|
||||
@defproc[(hash-ref! [h (hash X Y)] [k X] [v Y]) Y]{Extracts the value associated with a key from a mutable hash table; if the key does not have an mapping, the third argument is used as the value (or used to compute the value) and is added to the hash table associated with the key.}
|
||||
@defproc[(hash-update! [h (hash X Y)] [k X] [f (Y -> Y)]) void?]{Composes hash-ref and hash-set! to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref.}
|
||||
@defproc[(hash-update [h (hash X Y)] [k X] [f (Y -> Y)]) (hash X Y)]{Composes hash-ref and hash-set to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref.}
|
||||
@defproc[(hash-has-key? [h (hash X Y)] [x X]) boolean]{Determines if a key is associated with a value in a hash table.}
|
||||
@defproc[(hash-remove! [h (hash X Y)] [x X]) void]{Removes an mapping from a mutable hash table.}
|
||||
@defproc[(hash-remove [h (hash X Y)] [k X]) (hash X Y)]{Constructs an immutable hash table with one less mapping than an existing immutable hash table.}
|
||||
@defproc[(hash-map [h (hash X Y)] [f (X Y -> Z)]) (listof Z)]{Constructs a new list by applying a function to each mapping of a hash table.}
|
||||
@defproc[(hash-for-each [h (hash X Y)] [f (X Y -> any)]) void?]{Applies a function to each mapping of a hash table for effect only.}
|
||||
@defproc[(hash-count [h hash]) integer]{Determines the number of keys mapped by a hash table.}
|
||||
@defproc[(hash-copy [h hash]) hash]{Copies a hash table.}
|
||||
@defproc[(hash? [x any]) boolean]{Determines if a value is a hash table.}
|
||||
@defproc[(hash-equal? [h hash?]) boolean]{Determines if a hash table uses equal? for comparisons.}
|
||||
@defproc[(hash-eq? [h hash]) boolean]{Determines if a hash table uses eq? for comparisons.}
|
||||
@defproc[(hash-eqv? [h hash]) boolean]{Determines if a hash table uses eqv? for comparisons.}))
|
||||
|
||||
|
||||
|
||||
|
||||
#|
|
||||
@defproc[(random (case-> (integer -> integer) (-> (and/c real inexact? (>/c 0) (</c 1)))]{
|
||||
Generates a random natural number less than some given integer, or to
|
||||
generate a random inexact number between 0.0 and 1.0 exclusive.}
|
||||
|
||||
@defproc[((advanced-make-hash make-hash) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs a mutable hash table from an optional list of mappings that
|
||||
uses equal? for comparisions.}
|
||||
|
||||
@defproc[((advanced-make-hasheq make-hasheq) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs a mutable hash table from an optional list of mappings that
|
||||
uses eq? for comparisions.}
|
||||
|
||||
@defproc[((advanced-make-hasheqv make-hasheqv) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs a mutable hash table from an optional list of mappings that
|
||||
uses eqv? for comparisions.}
|
||||
|
||||
@defproc[((advanced-make-immutable-hash make-immutable-hash) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs an immutable hash table from an optional list of mappings that
|
||||
uses equal? for comparisions.}
|
||||
|
||||
@defproc[((advanced-make-immutable-hasheq make-immutable-hasheq) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs an immutable hash table from an optional list of mappings that
|
||||
uses eq? for comparisions.}
|
||||
|
||||
@defproc[((advanced-make-immutable-hasheqv make-immutable-hasheqv) (case-> (-> (hash X Y)) ((listof (list X Y)) -> (hash X Y))]{
|
||||
Constructs an immutable hash table from an optional list of mappings that
|
||||
uses eqv? for comparisions.}
|
||||
|
||||
@defproc[(hash-ref (case-> ((hash X Y) X -> Y) ((hash X Y) X Y -> Y) ((hash X Y) X (-> Y) -> Y))]{
|
||||
Extracts the value associated with a key from a hash table; the three
|
||||
argument case allows a default value or default value computation.}
|
||||
|
||||
@defproc[(hash-ref! (case-> ((hash X Y) X Y -> Y) ((hash X Y) X (-> Y) -> Y))]{
|
||||
Extracts the value associated with a key from a mutable hash table; if the
|
||||
key does not have an mapping, the third argument is used as the value (or
|
||||
used to compute the value) and is added to the hash table associated with
|
||||
the key.}
|
||||
|
||||
@defproc[(hash-update! (case-> ((hash X Y) X (Y -> Y) -> void) ((hash X Y) X (Y -> Y) Y -> void) ((hash X Y) X (Y -> Y) (-> Y) -> void))]{
|
||||
Composes hash-ref and hash-set! to update an existing mapping; the third
|
||||
argument is used to compute the new mapping value; the fourth argument is
|
||||
used as the third argument to hash-ref.}
|
||||
|
||||
@defproc[(hash-update (case-> ((hash X Y) X (Y -> Y) -> (hash X Y)) ((hash X Y) X (Y -> Y) Y -> (hash X Y)) ((hash X Y) X (Y -> Y) (-> Y) -> (hash X Y)))]{
|
||||
Composes hash-ref and hash-set to update an existing mapping; the third
|
||||
argument is used to compute the new mapping value; the fourth argument is
|
||||
used as the third argument to hash-ref.}
|
||||
|#
|
||||
|
|
|
@ -1,499 +1,301 @@
|
|||
#lang scheme
|
||||
(require mzlib/etc mzlib/list mzlib/math syntax/docprovide)
|
||||
#lang at-exp racket
|
||||
|
||||
;; weed out: string-copy, eqv?, struct? -- no need for beginners, move to advanced
|
||||
;; eq? is questionable, but okay if someone uses BSL to teach not out of HtDP
|
||||
;;
|
||||
|
||||
|
||||
(require mzlib/etc mzlib/list mzlib/math syntax/docprovide
|
||||
(for-syntax "firstorder.rkt")
|
||||
(for-syntax syntax/parse)
|
||||
"provide-and-scribble.rkt")
|
||||
|
||||
;; Implements the procedures:
|
||||
(require "teachprims.rkt"
|
||||
"../posn.rkt"
|
||||
"../imageeq.rkt")
|
||||
(require "teachprims.rkt" "teach.rkt" lang/posn lang/imageeq scribble/manual)
|
||||
|
||||
(define-syntax (provide-and-wrap stx)
|
||||
(syntax-parse stx
|
||||
[(provide-and-wrap wrap doc-tag:id (title (defproc (name args ...) range w ...) ...) ...)
|
||||
(with-syntax ([((f ...) ...) (map generate-temporaries (syntax->list #'((name ...) ...)))]
|
||||
[((internal-name ...) ...)
|
||||
(map (lambda (x)
|
||||
(map (lambda (n)
|
||||
(syntax-parse n
|
||||
[(internal-name:id external-name:id) #'internal-name]
|
||||
[n:id #'n]))
|
||||
(syntax->list x)))
|
||||
(syntax->list #'((name ...) ...)))]
|
||||
[((external-name ...) ...)
|
||||
(map (lambda (x)
|
||||
(map (lambda (n)
|
||||
(syntax-parse n
|
||||
[(internal-name:id external-name:id) #'external-name]
|
||||
[n:id #'n]))
|
||||
(syntax->list x)))
|
||||
(syntax->list #'((name ...) ...)))])
|
||||
#'(begin ;; create two modules:
|
||||
;; one that makes definitions first-order
|
||||
(module+ with-wrapper
|
||||
(wrap f internal-name) ... ...
|
||||
(provide-and-scribble
|
||||
doc-tag (title (defproc ((f external-name) args ...) range w ...) ...) ...))
|
||||
;; and one that doesn't
|
||||
(module+ without-wrapper
|
||||
(provide-and-scribble
|
||||
doc-tag (title (defproc (name args ...) range w ...) ...) ...))))]))
|
||||
|
||||
(define-syntax (in-rator-position-only stx)
|
||||
(syntax-case stx ()
|
||||
[(_ new-name orig-name)
|
||||
(let ([new (syntax new-name)]
|
||||
[orig (syntax orig-name)])
|
||||
(cond
|
||||
;; Some things are not really functions:
|
||||
[(memq (syntax-e orig) '(pi e null eof))
|
||||
#'(define new-name orig-name)]
|
||||
[else
|
||||
#'(define-syntax new-name
|
||||
(make-first-order
|
||||
(lambda (stx)
|
||||
(syntax-case stx ()
|
||||
[(id . args) (syntax/loc stx (beginner-app orig-name . args))]
|
||||
[_else
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"expected a function call but there is no open parenthesis before this function"
|
||||
stx)]))
|
||||
#'orig-name))]))]))
|
||||
|
||||
;; procedures with documentation:
|
||||
(provide-and-document
|
||||
(provide-and-wrap
|
||||
in-rator-position-only
|
||||
procedures
|
||||
|
||||
("Numbers: Integers, Rationals, Reals, Complex, Exacts, Inexacts"
|
||||
(number? (any -> boolean)
|
||||
"Determines whether some value is a number.")
|
||||
(= (number number number ... -> boolean)
|
||||
"Compares numbers for equality.")
|
||||
(< (real real real ... -> boolean)
|
||||
"Compares real numbers for less-than.")
|
||||
(> (real real real ... -> boolean)
|
||||
"Compares real numbers for greater-than.")
|
||||
(<= (real real real ... -> boolean)
|
||||
"Compares real numbers for less-than or equality.")
|
||||
(>= (real real real ... -> boolean)
|
||||
"Compares real numbers for greater-than or equality.")
|
||||
|
||||
((beginner-+ +) (number number number ... -> number)
|
||||
"Evaluates the sum of the input numbers.")
|
||||
(- (number number ... -> number)
|
||||
"subtracts the second (and following) number(s) from the first; negate the number if there is only one argument.")
|
||||
((beginner-* *) (number number number ... -> number)
|
||||
"Evaluates the product of all of the input numbers.")
|
||||
((beginner-/ /) (number number number ... -> number)
|
||||
"Divides the first by the second (and all following) number(s); try (/ 3 4) and (/ 3 2 2)"
|
||||
" only the first number can be zero.")
|
||||
(max (real real ... -> real)
|
||||
"Determines the largest number.")
|
||||
(min (real real ... -> real)
|
||||
"Determines the smallest number.")
|
||||
(quotient (integer integer -> integer)
|
||||
"Divides the second integer---also called divisor---into the first---known as dividend---to obtain the quotient; try (quotient 3 4) and (quotient 4 3).")
|
||||
(remainder (integer integer -> integer)
|
||||
"Determines the remainder of dividing the first by the second integer (exact or inexact).")
|
||||
(modulo (integer integer -> integer)
|
||||
"Finds the remainder of the division of the first number by the second; try (modulo 4 3) (modulo 4 -3).")
|
||||
((beginner-sqr sqr) (number -> number)
|
||||
"Evaluates the square of a number.")
|
||||
(sqrt (number -> number)
|
||||
"Evaluates the square root of a number.")
|
||||
(integer-sqrt (number -> integer)
|
||||
"Evaluates the integer (exact or inexact) square root of a number.")
|
||||
(expt (number number -> number)
|
||||
"Evaluates the power of the first to the second number.")
|
||||
(abs (real -> real)
|
||||
"Evaluates the absolute value of a real number.")
|
||||
(sgn (real -> (union 1 #i1.0 0 #i0.0 -1 #i-1.0))
|
||||
"Evaluates the sign of a real number.")
|
||||
@defproc[(number? [n any/c]) boolean?]{Determines whether some value is a number.}
|
||||
@defproc[(= [x number][y number][z number] ...) boolean?]{Compares numbers for equality.}
|
||||
@defproc[(< [x real][y real][z real] ...) boolean?]{Compares real numbers for less-than.}
|
||||
@defproc[(> [x real][y real][z real] ...) boolean?]{Compares real numbers for greater-than.}
|
||||
@defproc[(<= [x real][y real][z real] ...) boolean?]{Compares real numbers for less-than or equality.}
|
||||
@defproc[(>= [x real][y real][z real] ...) boolean?]{Compares real numbers for greater-than or equality.}
|
||||
@defproc[((beginner-+ +) [x number][y number][z number] ...) number]{Evaluates the sum of the input numbers.}
|
||||
@defproc[(- [x number][y number] ...) number]{subtracts the second (and following) number(s) from the first ; negate the number if there is only one argument.}
|
||||
@defproc[((beginner-* *) [x number][y number][z number] ...) number]{Evaluates the product of all of the input numbers.}
|
||||
@defproc[((beginner-/ /) [x number][y number][z number] ...) number]{
|
||||
Divides the first by the second (and all following) number(s) ;
|
||||
try (/ 3 4) and (/ 3 2 2) only the first number can be zero.}
|
||||
@defproc[(max [x real][y real] ...) real]{Determines the largest number.}
|
||||
@defproc[(min [x real][y real] ...) real]{Determines the smallest number. }
|
||||
@defproc[(quotient [x integer][y integer]) integer]{
|
||||
Divides the second integer---also called divisor---into the first---known as
|
||||
dividend---to obtain the quotient; try (quotient 3 4) and (quotient 4 3).}
|
||||
@defproc[(remainder [x integer][y integer]) integer]{Determines the remainder of dividing the first by the second integer (exact or inexact).}
|
||||
@defproc[(modulo [x integer][y integer]) integer]{Finds the remainder of the division of the first number by the second ; try (modulo 4 3) (modulo 4 -3).}
|
||||
@defproc[((beginner-sqr sqr) [x number]) number]{Evaluates the square of a number.}
|
||||
@defproc[(sqrt [x number]) number]{Evaluates the square root of a number.}
|
||||
@defproc[(integer-sqrt [x number]) integer]{Evaluates the integer (exact or inexact) square root of a number.}
|
||||
@defproc[(expt [x number][y number]) number]{Evaluates the power of the first to the second number.}
|
||||
@defproc[(abs [x real]) real]{Evaluates the absolute value of a real number.}
|
||||
@defproc[(sgn [x real]) (union 1 #i1.0 0 #i0.0 -1 #i-1.0)]{Evaluates the sign of a real number.}
|
||||
|
||||
;; fancy numeric
|
||||
(exp (number -> number)
|
||||
"Evaluates e raised to a number.")
|
||||
(log (number -> number)
|
||||
"Evaluates the base-e logarithm of a number.")
|
||||
@defproc[(exp [x number]) number]{Evaluates e raised to a number.}
|
||||
@defproc[(log [x number]) number]{Evaluates the base-e logarithm of a number.}
|
||||
|
||||
;; trigonometry
|
||||
(sin (number -> number)
|
||||
"Evaluates the sine of a number (radians).")
|
||||
(cos (number -> number)
|
||||
"Evaluates the cosine of a number (radians).")
|
||||
(tan (number -> number)
|
||||
"Evaluates the tangent of a number (radians).")
|
||||
(asin (number -> number)
|
||||
"Evaluates the arcsine (inverse of sin) of a number.")
|
||||
(acos (number -> number)
|
||||
"Evaluates the arccosine (inverse of cos) of a number.")
|
||||
(atan (number [number] -> number)
|
||||
"Evaluates the arctan of the given number or the ratio of the two given numbers.")
|
||||
@defproc[(sin [x number]) number]{Evaluates the sine of a number (radians).}
|
||||
@defproc[(cos [x number]) number]{Evaluates the cosine of a number (radians).}
|
||||
@defproc[(tan [x number]) number]{Evaluates the tangent of a number (radians).}
|
||||
@defproc[(asin [x number]) number]{Evaluates the arcsine (inverse of sin) of a number.}
|
||||
@defproc[(acos [x number]) number]{Evaluates the arccosine (inverse of cos) of a number.}
|
||||
@defproc[(atan [x number] [y number]) number]{Evaluates the arctan of the given number or the ratio of the two given numbers.}
|
||||
@defproc[(sinh [x number]) number]{Evaluates the hyperbolic sine of a number.}
|
||||
@defproc[(cosh [x number]) number]{Evaluates the hyperbolic cosine of a number.}
|
||||
|
||||
(sinh (number -> number)
|
||||
"Evaluates the hyperbolic sine of a number.")
|
||||
(cosh (number -> number)
|
||||
"Evaluates the hyperbolic cosine of a number.")
|
||||
@defproc[(exact? [x number]) boolean?]{Determines whether some number is exact.}
|
||||
|
||||
(exact? (number -> boolean)
|
||||
"Determines whether some number is exact.")
|
||||
@defproc[(integer? [x any/c]) boolean?]{Determines whether some value is an integer (exact or inexact).}
|
||||
|
||||
(integer? (any -> boolean)
|
||||
"Determines whether some value is an integer (exact or inexact).")
|
||||
@defproc[(zero? [x number]) boolean?]{Determines if some value is zero or not. }
|
||||
@defproc[(positive? [x number]) boolean?]{Determines if some value is strictly larger than zero.}
|
||||
@defproc[(negative? [x number]) boolean?]{Determines if some value is strictly smaller than zero.}
|
||||
@defproc[(odd? [x integer]) boolean?]{Determines if some integer (exact or inexact) is odd or not.}
|
||||
@defproc[(even? [x integer]) boolean?]{Determines if some integer (exact or inexact) is even or not.}
|
||||
|
||||
(zero? (number -> boolean)
|
||||
"Determines if some value is zero or not.")
|
||||
(positive? (number -> boolean)
|
||||
"Determines if some value is strictly larger than zero.")
|
||||
(negative? (number -> boolean)
|
||||
"Determines if some value is strictly smaller than zero.")
|
||||
(odd? (integer -> boolean)
|
||||
"Determines if some integer (exact or inexact) is odd or not.")
|
||||
(even? (integer -> boolean)
|
||||
"Determines if some integer (exact or inexact) is even or not.")
|
||||
|
||||
(add1 (number -> number)
|
||||
"Evaluates a number one larger than a given number.")
|
||||
(sub1 (number -> number)
|
||||
"Evaluates a number one smaller than a given number.")
|
||||
|
||||
(lcm (integer integer ... -> integer)
|
||||
"Evaluates the least common multiple of two integers (exact or inexact).")
|
||||
|
||||
(gcd (integer integer ... -> integer)
|
||||
"Evaluates the greatest common divisior of two integers (exact or inexact).")
|
||||
|
||||
(rational? (any -> boolean)
|
||||
"Determines whether some value is a rational number.")
|
||||
|
||||
(numerator (rat -> integer)
|
||||
"Evaluates the numerator of a rational.")
|
||||
|
||||
(denominator (rat -> integer)
|
||||
"Evaluates the denominator of a rational.")
|
||||
|
||||
(inexact? (number -> boolean)
|
||||
"Determines whether some number is inexact.")
|
||||
|
||||
(real? (any -> boolean)
|
||||
"Determines whether some value is a real number.")
|
||||
|
||||
(floor (real -> integer)
|
||||
"Determines the closest integer (exact or inexact) below a real number.")
|
||||
|
||||
(ceiling (real -> integer)
|
||||
"Determines the closest integer (exact or inexact) above a real number.")
|
||||
|
||||
(round (real -> integer)
|
||||
"Rounds a real number to an integer (rounds to even to break ties).")
|
||||
|
||||
(complex? (any -> boolean)
|
||||
"Determines whether some value is complex.")
|
||||
|
||||
(make-polar (real real -> number)
|
||||
"Creates a complex from a magnitude and angle.")
|
||||
|
||||
(make-rectangular (real real -> number)
|
||||
"Creates a complex from a real and an imaginary part.")
|
||||
|
||||
(real-part (number -> real)
|
||||
"Extracts the real part from a complex number.")
|
||||
|
||||
(imag-part (number -> real)
|
||||
"Extracts the imaginary part from a complex number.")
|
||||
|
||||
(magnitude (number -> real)
|
||||
"Determines the magnitude of a complex number.")
|
||||
|
||||
(angle (number -> real)
|
||||
"Extracts the angle from a complex number.")
|
||||
|
||||
(conjugate (number -> number)
|
||||
"Evaluates the conjugate of a complex number.")
|
||||
|
||||
(exact->inexact (number -> number)
|
||||
"Converts an exact number to an inexact one.")
|
||||
|
||||
(inexact->exact (number -> number)
|
||||
"Approximates an inexact number by an exact one.")
|
||||
|
||||
; "Odds and ends"
|
||||
|
||||
(number->string (number -> string)
|
||||
"Converts a number to a string.")
|
||||
|
||||
(integer->char (integer -> char)
|
||||
"Lookups the character that corresponds to the given integer (exact only!) in the ASCII table (if any).")
|
||||
|
||||
((beginner-random random) (integer -> integer)
|
||||
"Generates a random natural number less than some given integer (exact only!).")
|
||||
|
||||
(current-seconds (-> integer)
|
||||
"Evaluates the current time in seconds elapsed"
|
||||
" (since a platform-specific starting date).")
|
||||
|
||||
(e real
|
||||
"Euler's number.")
|
||||
(pi real
|
||||
"The ratio of a circle's circumference to its diameter."))
|
||||
@defproc[(add1 [x number]) number]{Evaluates a number one larger than a given number.}
|
||||
@defproc[(sub1 [x number]) number]{Evaluates a number one smaller than a given number.}
|
||||
@defproc[(lcm [x integer][y integer] ...) integer]{Evaluates the least common multiple of two integers (exact or inexact).}
|
||||
@defproc[(gcd [x integer][y integer] ...) integer]{Evaluates the greatest common divisior of two integers (exact or inexact).}
|
||||
@defproc[(rational? [x any/c]) boolean?]{Determines whether some value is a rational number.}
|
||||
@defproc[(numerator [x rational?]) integer]{Evaluates the numerator of a rational.}
|
||||
@defproc[(denominator [x rational?]) integer]{Evaluates the denominator of a rational.}
|
||||
@defproc[(inexact? [x number]) boolean?]{Determines whether some number is inexact.}
|
||||
@defproc[(real? [x any/c]) boolean?]{Determines whether some value is a real number.}
|
||||
@defproc[(floor [x real]) integer]{Determines the closest integer (exact or inexact) below a real number.}
|
||||
@defproc[(ceiling [x real]) integer]{Determines the closest integer (exact or inexact) above a real number.}
|
||||
@defproc[(round [x real]) integer]{Rounds a real number to an integer (rounds to even to break ties).}
|
||||
@defproc[(complex? [x any/c]) boolean?]{Determines whether some value is complex.}
|
||||
@defproc[(make-polar [x real real]) number]{Creates a complex from a magnitude and angle.}
|
||||
@defproc[(make-rectangular [x real][y real]) number]{Creates a complex from a real and an imaginary part.}
|
||||
@defproc[(real-part [x number]) real]{Extracts the real part from a complex number.}
|
||||
@defproc[(imag-part [x number]) real]{Extracts the imaginary part from a complex number.}
|
||||
@defproc[(magnitude [x number]) real]{Determines the magnitude of a complex number.}
|
||||
@defproc[(angle [x number]) real]{Extracts the angle from a complex number.}
|
||||
@defproc[(conjugate [x number]) number]{Evaluates the conjugate of a complex number.}
|
||||
@defproc[(exact->inexact [x number]) number]{Converts an exact number to an inexact one.}
|
||||
@defproc[(inexact->exact [x number]) number]{Approximates an inexact number by an exact one.}
|
||||
@defproc[(number->string [x number]) string]{Converts a number to a string.}
|
||||
@defproc[(integer->char [x integer]) char]{Lookups the character that corresponds to the given integer (exact only!) in the ASCII table (if any).}
|
||||
@defproc[((beginner-random random) [x integer]) integer]{Generates a random natural number less than some given integer (exact only!).}
|
||||
@defproc[(current-seconds) integer]{Evaluates the current time in seconds elapsed (since a platform-specific starting date).}
|
||||
@defproc[(e) real]{Euler's number.}
|
||||
@defproc[(pi) real]{The ratio of a circle's circumference to its diameter.})
|
||||
|
||||
("Booleans"
|
||||
(boolean? (any -> boolean)
|
||||
"Determines whether some value is a boolean.")
|
||||
|
||||
(boolean=? (boolean boolean -> boolean)
|
||||
"Determines whether two booleans are equal.")
|
||||
|
||||
(false? (any -> boolean)
|
||||
"Determines whether a value is false.")
|
||||
|
||||
((beginner-not not) (boolean -> boolean)
|
||||
"Evaluates the negation of a boolean value."))
|
||||
("Booleans"
|
||||
@defproc[(boolean? [x any/c]) boolean?]{Determines whether some value is a boolean.}
|
||||
@defproc[(boolean=? [x boolean?][y boolean?]) boolean?]{Determines whether two booleans are equal.}
|
||||
@defproc[(false? [x any/c]) boolean?]{Determines whether a value is false.}
|
||||
@defproc[((beginner-not not) [x boolean?]) boolean?]{Evaluates the negation of a boolean value.})
|
||||
|
||||
("Symbols"
|
||||
(symbol? (any -> boolean)
|
||||
"Determines whether some value is a symbol.")
|
||||
|
||||
(symbol=? (symbol symbol -> boolean)
|
||||
"Determines whether two symbols are equal.")
|
||||
|
||||
(symbol->string (symbol -> string)
|
||||
"Converts a symbol to a string.") )
|
||||
@defproc[(symbol? [x any/c]) boolean?]{Determines whether some value is a symbol.}
|
||||
@defproc[(symbol=? [x symbol][y symbol]) boolean?]{Determines whether two symbols are equal.}
|
||||
@defproc[(symbol->string [x symbol]) string]{Converts a symbol to a string. })
|
||||
|
||||
("Lists"
|
||||
(cons? (any -> boolean)
|
||||
"Determines whether some value is a constructed list.")
|
||||
#;
|
||||
(pair? (any -> boolean)
|
||||
"Determines whether some value is a constructed list.")
|
||||
(empty? (any -> boolean)
|
||||
"Determines whether some value is the empty list.")
|
||||
(null? (any -> boolean)
|
||||
"Determines whether some value is the empty list.")
|
||||
|
||||
((beginner-cons cons) (X (listof X) -> (listof X))
|
||||
"Constructs a list.")
|
||||
|
||||
(null empty
|
||||
"The empty list.")
|
||||
|
||||
((beginner-first first) ( (cons Y (listof X)) -> Y )
|
||||
"Selects the first item of a non-empty list.")
|
||||
((beginner-car car) ( (cons Y (listof X)) -> Y )
|
||||
"Selects the first item of a non-empty list.")
|
||||
((beginner-rest rest) ((cons Y (listof X)) -> (listof X))
|
||||
"Selects the rest of a non-empty list.")
|
||||
((beginner-cdr cdr) ((cons Y (listof X)) -> (listof X))
|
||||
"Selects the rest of a non-empty list.")
|
||||
|
||||
(second ( (cons Z (cons Y (listof X))) -> Y )
|
||||
"Selects the second item of a non-empty list.")
|
||||
(cadr ( (cons Z (cons Y (listof X))) -> Y )
|
||||
"Selects the second item of a non-empty list.")
|
||||
(cdar ( (cons (cons Z (listof Y)) (listof X)) -> (listof Y) )
|
||||
"Selects the rest of a non-empty list in a list.")
|
||||
(caar ( (cons (cons Z (listof Y)) (listof X)) -> Z )
|
||||
"Selects the first item of the first list in a list.")
|
||||
(cddr ( (cons Z (cons Y (listof X))) -> (listof X) )
|
||||
"Selects the rest of the rest of a list.")
|
||||
(third ( (cons W (cons Z (cons Y (listof X)))) -> Y )
|
||||
"Selects the third item of a non-empty list.")
|
||||
(caddr ( (cons W (cons Z (cons Y (listof X)))) -> Y )
|
||||
"Selects the third item of a non-empty list.")
|
||||
(caadr ( (cons (cons (cons W (listof Z)) (listof Y)) (listof X)) -> (listof Z) )
|
||||
"Selects the rest of the first list in the first list of a list.")
|
||||
(caaar ( (cons (cons (cons W (listof Z)) (listof Y)) (listof X)) -> W )
|
||||
"Selects the first item of the first list in the first list of a list.")
|
||||
(cdaar ( (cons (cons (cons W (listof Z)) (listof Y)) (listof X)) -> (listof Z) )
|
||||
"Selects the rest of the first list in the first list of a list.")
|
||||
(cdadr ( (cons W (cons (cons Z (listof Y)) (listof X))) -> (listof Y) )
|
||||
"Selects the rest of the first list in the rest of a list.")
|
||||
(cadar ( (cons (cons W (cons Z (listof Y))) (listof X)) -> Z )
|
||||
"Selects the second item of the first list of a list.")
|
||||
(cddar ( (cons (cons W (cons Z (listof Y))) (listof X)) -> (listof Y) )
|
||||
"Selects the rest of the rest of the first list of a list.")
|
||||
(cdddr ( (cons W (cons Z (cons Y (listof X)))) -> (listof X) )
|
||||
"Selects the rest of the rest of the rest of a list.")
|
||||
(fourth ( (listof Y) -> Y ) ; domain: (cons V (cons W (cons Z (cons Y (listof X)))))
|
||||
"Selects the fourth item of a non-empty list.")
|
||||
(cadddr ( (listof Y) -> Y ) ; domain: (cons V (cons W (cons Z (cons Y (listof X)))))
|
||||
"Selects the fourth item of a non-empty list.")
|
||||
(fifth ( (listof Y) -> Y ) ; domain: (cons U (cons V (cons W (cons Z (cons Y (listof X))))))
|
||||
"Selects the fifth item of a non-empty list.")
|
||||
(sixth ( (listof Y) -> Y ) ; domain: (cons T (cons U (cons V (cons W (cons Z (cons Y (listof X)))))))
|
||||
"Selects the sixth item of a non-empty list.")
|
||||
(seventh ( (listof Y) -> Y ) ; domain: (cons S (cons T (cons U (cons V (cons W (cons Z (cons Y (listof X))))))))
|
||||
"Selects the seventh item of a non-empty list.")
|
||||
(eighth ( (listof Y) -> Y ) ; domain: (cons R (cons S (cons T (cons U (cons V (cons W (cons Z (cons Y (listof X)))))))))
|
||||
"Selects the eighth item of a non-empty list.")
|
||||
|
||||
(list-ref ((listof X) natural-number -> X )
|
||||
"Extracts the indexed item from the list.")
|
||||
|
||||
(list (any ... -> (listof any)) "Constructs a list of its arguments.")
|
||||
|
||||
(make-list (natural-number any -> (listof any))
|
||||
"Constructs a list of k (the first argument) copies of x (the second argument).")
|
||||
|
||||
((beginner-list* list*) (any ... (listof any) -> (listof any))
|
||||
"Constructs a list by adding multiple items to a list.")
|
||||
((beginner-range range) (number number number -> (listof number))
|
||||
"(range start end step) constructs a list of numbers by _step_ping from _start_ to _end_ list.")
|
||||
|
||||
((beginner-append append) ((listof any) (listof any) (listof any) ... -> (listof any))
|
||||
"Creates a single list from several, by juxtaposition of the items.")
|
||||
(length ((listof any) -> number)
|
||||
"Evaluates the number of items on a list.")
|
||||
(memq (any (listof any) -> (union false list))
|
||||
"Determines whether some value is on some list"
|
||||
" if so, it produces the suffix of the list that starts with x"
|
||||
" if not, it produces false."
|
||||
" (It compares values with the eq? predicate.)")
|
||||
(memv (any (listof any) -> (union false list))
|
||||
"Determines whether some value is on the list"
|
||||
" if so, it produces the suffix of the list that starts with x"
|
||||
" if not, it produces false."
|
||||
" (It compares values with the eqv? predicate.)")
|
||||
((beginner-member? member?) (any (listof any) -> boolean)
|
||||
"Determines whether some value is on the list"
|
||||
" (comparing values with equal?).")
|
||||
((beginner-member member) (any (listof any) -> boolean)
|
||||
"Determines whether some value is on the list"
|
||||
" (comparing values with equal?).")
|
||||
((beginner-remove remove) (any (listof any) -> (listof any))
|
||||
"Constructs a list like the given one with the first occurrence of the given item removed"
|
||||
" (comparing values with equal?).")
|
||||
(reverse ((listof any) -> list)
|
||||
"Creates a reversed version of a list.")
|
||||
(assq (X (listof (cons X Y)) -> (union false (cons X Y)))
|
||||
"Determines whether some item is the first item of a pair"
|
||||
" in a list of pairs."))
|
||||
|
||||
@defproc[(cons? [x any/c]) boolean?]{Determines whether some value is a constructed list.}
|
||||
@defproc[(empty? [x any/c]) boolean?]{Determines whether some value is the empty list.}
|
||||
@defproc[(null? [x any/c]) boolean?]{Determines whether some value is the empty list.}
|
||||
@defproc[((beginner-cons cons) [x any/x][y list?]) list?]{Constructs a list.}
|
||||
@defproc[((beginner-first first) [x cons?]) any/c]{Selects the first item of a non-empty list.}
|
||||
@defproc[((beginner-car car) [x cons?]) any/c]{Selects the first item of a non-empty list.}
|
||||
@defproc[((beginner-rest rest) [x cons?]) any/c]{Selects the rest of a non-empty list.}
|
||||
@defproc[((beginner-cdr cdr) [x cons?]) any/c]{Selects the rest of a non-empty list.}
|
||||
@defproc[(second [x list?]) any/c]{Selects the second item of a non-empty list.}
|
||||
@defproc[(cadr [x list?]) any/c]{Selects the second item of a non-empty list.}
|
||||
@defproc[(cdar [x list?]) list?]{Selects the rest of a non-empty list in a list. }
|
||||
@defproc[(caar [x list?]) any/c]{Selects the first item of the first list in a list.}
|
||||
@defproc[(cddr [x list?]) list? ]{Selects the rest of the rest of a list.}
|
||||
@defproc[(third [x list?]) any/c]{Selects the third item of a non-empty list.}
|
||||
@defproc[(caddr [x list?]) any/c]{Selects the third item of a non-empty list.}
|
||||
@defproc[(caadr [x list?]) any/c]{Selects the rest of the first list in the first list of a list.}
|
||||
@defproc[(caaar [x list?]) any/c]{Selects the first item of the first list in the first list of a list.}
|
||||
@defproc[(cdaar [x list?]) any/c]{Selects the rest of the first list in the first list of a list.}
|
||||
@defproc[(cdadr [x list?]) any/c]{Selects the rest of the first list in the rest of a list.}
|
||||
@defproc[(cadar [x list?]) any/c]{Selects the second item of the first list of a list.}
|
||||
@defproc[(cddar [x list?]) any/c]{Selects the rest of the rest of the first list of a list.}
|
||||
@defproc[(cdddr [x list?]) any/c]{Selects the rest of the rest of the rest of a list.}
|
||||
@defproc[(fourth [x list?]) any/c]{Selects the fourth item of a non-empty list.}
|
||||
@defproc[(cadddr [x list?]) any/c]{Selects the fourth item of a non-empty list.}
|
||||
@defproc[(fifth [x list?]) any/c]{Selects the fifth item of a non-empty list.}
|
||||
@defproc[(sixth [x list?]) any/c]{Selects the sixth item of a non-empty list.}
|
||||
@defproc[(seventh [x list?]) any/c]{Selects the seventh item of a non-empty list.}
|
||||
@defproc[(eighth [x list?]) any/c]{Selects the eighth item of a non-empty list.}
|
||||
@defproc[(list-ref [x list?][i natural?]) any/c]{Extracts the indexed item from the list.}
|
||||
@defproc[(list [x any/c] ... ) list?]{Constructs a list of its arguments.}
|
||||
@defproc[(make-list [i natural-number] [x any/c]) list?]{Constructs a list of k (the first argument) copies of x (the second argument).}
|
||||
@defproc[((beginner-list* list*) [x any/c] ... [l list?]) list?]{Constructs a list by adding multiple items to a list.}
|
||||
@defproc[((beginner-range range) [x number][y number][z number]) list?]{(range start end step) constructs a list of numbers by _step_ping from _start_ to _end_ list.}
|
||||
@defproc[((beginner-append append) [x list?][y list?][z list?] ...) list?]{Creates a single list from several, by juxtaposition of the items.}
|
||||
@defproc[(length (l list?)) natural-number?]{Evaluates the number of items on a list.}
|
||||
@defproc[(memq [x any/c][l list?]) (or/c false list?)]{Determines whether some value is on some list if so, it produces the
|
||||
suffix of the list that starts with x if not, it produces false. (It
|
||||
compares values with the eq? predicate.)}
|
||||
@defproc[(memv [x any/c][l list?]) (or/c false list)]{Determines whether some value is on the list if so, it produces the
|
||||
suffix of the list that starts with x if not, it produces false. (It
|
||||
compares values with the eqv? predicate.)}
|
||||
@defproc[((beginner-member? member?) [x any/c][l list?]) boolean?]{Determines whether some value is on the list (comparing values with equal?).}
|
||||
@defproc[((beginner-member member) [x any/c][l list?]) boolean?]{Determines whether some value is on the list (comparing values with equal?).}
|
||||
@defproc[((beginner-remove remove) [x any/c][l list?]) list?]{Constructs a list like the given one with
|
||||
the first occurrence of the given item removed (comparing values with equal?).}
|
||||
@defproc[(reverse [l list?]) list]{Creates a reversed version of a list.}
|
||||
@defproc[(assq [x any/c][l list?]) (union false cons?)]{Determines whether some item is the first item of a pair in a list of pairs.})
|
||||
|
||||
("Posns"
|
||||
(posn signature "Signature for posns.")
|
||||
(make-posn (any any -> posn) "Constructs a posn from two arbitrary values.")
|
||||
(posn? (any -> boolean) "Determines if its input is a posn.")
|
||||
(posn-x (posn -> any) "Extracts the x component of a posn.")
|
||||
(posn-y (posn -> any) "Extracts the y component of a posn."))
|
||||
@defproc[(posn) signature]{Signature for posns.}
|
||||
@defproc[(make-posn [x any/c][y any/c]) posn]{Constructs a posn from two arbitrary values.}
|
||||
@defproc[(posn? [x any/c]) boolean?]{Determines if its input is a posn.}
|
||||
@defproc[(posn-x [p posn]) any]{Extracts the x component of a posn.}
|
||||
@defproc[(posn-y [p posn]) any]{Extracts the y component of a posn.})
|
||||
|
||||
("Characters"
|
||||
(char? (any -> boolean)
|
||||
"Determines whether a value is a character.")
|
||||
(char=? (char char char ... -> boolean)
|
||||
"Determines whether two characters are equal.")
|
||||
(char<? (char char char ... -> boolean)
|
||||
"Determines whether a character precedes another.")
|
||||
(char>? (char char char ... -> boolean)
|
||||
"Determines whether a character succeeds another.")
|
||||
(char<=? (char char char ... -> boolean)
|
||||
"Determines whether a character precedes another"
|
||||
" (or is equal to it).")
|
||||
(char>=? (char char char ... -> boolean)
|
||||
"Determines whether a character succeeds another"
|
||||
" (or is equal to it).")
|
||||
|
||||
(char-ci=? (char char char ... -> boolean)
|
||||
"Determines whether two characters are equal"
|
||||
" in a case-insensitive manner.")
|
||||
(char-ci<? (char char char ... -> boolean)
|
||||
"Determines whether a character precedes another"
|
||||
" in a case-insensitive manner.")
|
||||
(char-ci>? (char char char ... -> boolean)
|
||||
"Determines whether a character succeeds another"
|
||||
" in a case-insensitive manner.")
|
||||
(char-ci<=? (char char char ... -> boolean)
|
||||
"Determines whether a character precedes another"
|
||||
" (or is equal to it) in a case-insensitive manner.")
|
||||
(char-ci>=? (char char char ... -> boolean)
|
||||
"Determines whether a character succeeds another"
|
||||
" (or is equal to it) in a case-insensitive manner.")
|
||||
|
||||
(char-numeric? (char -> boolean)
|
||||
"Determines whether a character represents a digit.")
|
||||
(char-alphabetic? (char -> boolean)
|
||||
"Determines whether a character represents"
|
||||
" an alphabetic character.")
|
||||
(char-whitespace? (char -> boolean)
|
||||
"Determines whether a character represents space.")
|
||||
(char-upper-case? (char -> boolean)
|
||||
"Determines whether a character is an"
|
||||
" upper-case character.")
|
||||
(char-lower-case? (char -> boolean)
|
||||
"Determines whether a character is a"
|
||||
" lower-case character.")
|
||||
(char-upcase (char -> char)
|
||||
"Determines the equivalent upper-case character.")
|
||||
(char-downcase (char -> char)
|
||||
"Determines the equivalent lower-case character.")
|
||||
(char->integer (char -> integer)
|
||||
"Lookups the number that corresponds to the"
|
||||
" given character in the ASCII table (if any)."))
|
||||
@defproc[(char? [x any/c]) boolean?]{Determines whether a value is a character.}
|
||||
@defproc[(char=? [c char][d char][e char] ...) boolean?]{Determines whether two characters are equal.}
|
||||
@defproc[(char<? [x char][d char][e char] ...) boolean?]{Determines whether a character precedes another.}
|
||||
@defproc[(char>? [c char][d char][e char] ...) boolean?]{Determines whether a character succeeds another.}
|
||||
@defproc[(char<=? [c char][d char][e char] ...) boolean?]{Determines whether a character precedes another (or is equal to it).}
|
||||
@defproc[(char>=? [c char][d char][e char] ...) boolean?]{Determines whether a character succeeds another (or is equal to it).}
|
||||
@defproc[(char-ci=? [c char][d char][e char] ...) boolean?]{Determines whether two characters are equal in a case-insensitive manner.}
|
||||
@defproc[(char-ci<? [c char][d char][e char] ...) boolean?]{Determines whether a character precedes another in a case-insensitive manner.}
|
||||
@defproc[(char-ci>? [c char][d char][e char] ...) boolean?]{Determines whether a character succeeds another in a case-insensitive manner.}
|
||||
@defproc[(char-ci<=? [c char][d char][e char] ...) boolean?]{Determines whether a character precedes another (or is equal to it) in a case-insensitive manner.}
|
||||
@defproc[(char-ci>=? [c char][d char][e char] ...) boolean?]{Determines whether a character succeeds another (or is equal to it) in a case-insensitive manner.}
|
||||
@defproc[(char-numeric? [c char]) boolean?]{Determines whether a character represents a digit.}
|
||||
@defproc[(char-alphabetic? [c char]) boolean?]{Determines whether a character represents an alphabetic character.}
|
||||
@defproc[(char-whitespace? [c char]) boolean?]{Determines whether a character represents space.}
|
||||
@defproc[(char-upper-case? [c char]) boolean?]{Determines whether a character is an upper-case character.}
|
||||
@defproc[(char-lower-case? [c char]) boolean?]{Determines whether a character is a lower-case character.}
|
||||
@defproc[(char-upcase [c char]) char]{Determines the equivalent upper-case character.}
|
||||
@defproc[(char-downcase [c char]) char]{Determines the equivalent lower-case character.}
|
||||
@defproc[(char->integer [c char]) integer]{Lookups the number that corresponds to the given character in the ASCII table (if any).})
|
||||
|
||||
("Strings"
|
||||
(string? (any -> boolean)
|
||||
"Determines whether a value is a string.")
|
||||
(string-length (string -> nat)
|
||||
"Determines the length of a string.")
|
||||
|
||||
((beginner-string-ith string-ith) (string nat -> string)
|
||||
"Extracts the ith 1-letter substring from the given one.")
|
||||
((beginner-replicate replicate) (nat string -> string)
|
||||
"Replicates the given string.")
|
||||
((beginner-int->string int->string) (integer -> string)
|
||||
"Converts an integer in [0,55295] or [57344 1114111] to a 1-letter string.")
|
||||
((beginner-string->int string->int) (string -> integer)
|
||||
"Converts a 1-letter string to an integer in [0,55295] or [57344, 1114111].")
|
||||
((beginner-explode explode) (string -> (listof string))
|
||||
"Translates a string into a list of 1-letter strings.")
|
||||
((beginner-implode implode) ((listof string) -> string)
|
||||
"Concatenates the list of 1-letter strings into one string.")
|
||||
((beginner-string-numeric? string-numeric?) (string -> boolean)
|
||||
"Determines whether all 'letters' in the string are numeric.")
|
||||
((beginner-string-alphabetic? string-alphabetic?) (string -> boolean)
|
||||
"Determines whether all 'letters' in the string are alphabetic.")
|
||||
((beginner-string-whitespace? string-whitespace?) (string -> boolean)
|
||||
"Determines whether all 'letters' in the string are white space.")
|
||||
((beginner-string-upper-case? string-upper-case?) (string -> boolean)
|
||||
"Determines whether all 'letters' in the string are upper case.")
|
||||
((beginner-string-lower-case? string-lower-case?) (string -> boolean)
|
||||
"Determines whether all 'letters' in the string are lower case.")
|
||||
|
||||
(string (char ... -> string)
|
||||
"Builds a string of the given characters.")
|
||||
(make-string (nat char -> string)
|
||||
"Produces a string of given length"
|
||||
" from a single given character.")
|
||||
(string-ref (string nat -> char)
|
||||
"Extracts the i-the character from a string.")
|
||||
|
||||
(substring (string nat nat -> string)
|
||||
"Extracts the substring starting at a 0-based index"
|
||||
" up to the second 0-based index (exclusive).")
|
||||
(string-copy (string -> string)
|
||||
"Copies a string.")
|
||||
(string-append (string ... -> string)
|
||||
"Juxtaposes the characters of several strings.")
|
||||
|
||||
(string=? (string string string ... -> boolean)
|
||||
"Compares two strings character-wise.")
|
||||
(string<? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" precedes another.")
|
||||
(string>? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" succeeds another.")
|
||||
(string<=? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" precedes another (or is equal to it).")
|
||||
(string>=? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" succeeds another (or is equal to it).")
|
||||
|
||||
(string-ci=? (string string string ... -> boolean)
|
||||
"Compares two strings character-wise"
|
||||
" in a case-insensitive manner.")
|
||||
(string-ci<? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" precedes another in a case-insensitive manner.")
|
||||
(string-ci>? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" succeeds another in a case-insensitive manner.")
|
||||
(string-ci<=? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" precedes another (or is equal to it)"
|
||||
" in a case-insensitive manner.")
|
||||
(string-ci>=? (string string string ... -> boolean)
|
||||
"Determines whether one string alphabetically"
|
||||
" succeeds another (or is equal to it)"
|
||||
" in a case-insensitive manner.")
|
||||
|
||||
(string->symbol (string -> symbol)
|
||||
"Converts a string into a symbol.")
|
||||
(string->number (string -> (union number false))
|
||||
"Converts a string into a number,"
|
||||
" produce false if impossible.")
|
||||
(string->list (string -> (listof char))
|
||||
"Converts a string into a list of characters.")
|
||||
(list->string ((listof char) -> string)
|
||||
"Converts a s list of characters into a string.")
|
||||
|
||||
(format (string any ... -> string)
|
||||
"Formats a string, possibly embedding values."))
|
||||
|
||||
@defproc[(string? [x any/c]) boolean?]{Determines whether a value is a string.}
|
||||
@defproc[(string-length [s string]) nat]{Determines the length of a string.}
|
||||
@defproc[((beginner-string-ith string-ith) [s string][i natural-number]) string]{Extracts the ith 1-letter substring from the given one.}
|
||||
@defproc[((beginner-replicate replicate) [i natural-number][s string]) string]{Replicates the given string.}
|
||||
@defproc[((beginner-int->string int->string) [i integer]) string]{Converts an integer in [0,55295] or [57344 1114111] to a 1-letter string.}
|
||||
@defproc[((beginner-string->int string->int) [s string]) integer]{Converts a 1-letter string to an integer in [0,55295] or [57344, 1114111].}
|
||||
@defproc[((beginner-explode explode) [s string]) (listof string)]{Translates a string into a list of 1-letter strings.}
|
||||
@defproc[((beginner-implode implode) [l list?]) string]{Concatenates the list of 1-letter strings into one string.}
|
||||
@defproc[((beginner-string-numeric? string-numeric?) [s string]) boolean?]{Determines whether all 'letters' in the string are numeric.}
|
||||
@defproc[((beginner-string-alphabetic? string-alphabetic?) [s string]) boolean?]{Determines whether all 'letters' in the string are alphabetic.}
|
||||
@defproc[((beginner-string-whitespace? string-whitespace?) [s string]) boolean?]{Determines whether all 'letters' in the string are white space. }
|
||||
@defproc[((beginner-string-upper-case? string-upper-case?) [s string]) boolean?]{Determines whether all 'letters' in the string are upper case.}
|
||||
@defproc[((beginner-string-lower-case? string-lower-case?) [s string]) boolean?]{Determines whether all 'letters' in the string are lower case.}
|
||||
@defproc[((beginner-string-contains? string-contains?) [s string] [t string]) boolean?]{Determines whether the first string appears literally in the second one.}
|
||||
@defproc[(string [c char] ...) string?]{Builds a string of the given characters.}
|
||||
@defproc[(make-string [i natural-number][c char]) string]{Produces a string of given length from a single given character.}
|
||||
@defproc[(string-ref [s string][i natural-number]) char]{Extracts the i-the character from a string.}
|
||||
@defproc[(substring [s string][i natural-number][j natural-number]) string]{Extracts the substring starting at a 0-based index up to the second 0-based index (exclusive).}
|
||||
@defproc[(string-copy [s string]) string]{Copies a string.}
|
||||
@defproc[(string-append [s string] ...) string]{Juxtaposes the characters of several strings.}
|
||||
@defproc[(string=? [s string][t string][x string] ...) boolean?]{Compares two strings character-wise.}
|
||||
@defproc[(string<? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically precedes another.}
|
||||
@defproc[(string>? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically succeeds another.}
|
||||
@defproc[(string<=? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically precedes another (or is equal to it).}
|
||||
@defproc[(string>=? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically succeeds another (or is equal to it).}
|
||||
@defproc[(string-ci=? [s string][t string][x string] ...) boolean?]{Compares two strings character-wise in a case-insensitive manner.}
|
||||
@defproc[(string-ci<? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically precedes another in a case-insensitive manner.}
|
||||
@defproc[(string-ci>? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically succeeds another in a case-insensitive manner.}
|
||||
@defproc[(string-ci<=? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically precedes another (or is equal to it) in a case-insensitive manner.}
|
||||
@defproc[(string-ci>=? [s string][t string][x string] ...) boolean?]{Determines whether one string alphabetically succeeds another (or is equal to it) in a case-insensitive manner.}
|
||||
@defproc[(string->symbol [s string]) symbol]{Converts a string into a symbol.}
|
||||
@defproc[(string->number [s string]) (union number false)]{Converts a string into a number, produce false if impossible.}
|
||||
@defproc[(string->list [s string]) (listof char)]{Converts a string into a list of characters.}
|
||||
@defproc[(list->string [l list?]) string]{Converts a s list of characters into a string.}
|
||||
@defproc[(format [f string] [x any/c] ...) string]{Formats a string, possibly embedding values.})
|
||||
|
||||
("Images"
|
||||
(image? (any -> boolean)
|
||||
"Determines whether a value is an image.")
|
||||
(image=? (image image -> boolean)
|
||||
"Determines whether two images are equal."))
|
||||
@defproc[(image? [x any/c]) boolean?]{Determines whether a value is an image.}
|
||||
@defproc[(image=? [i image][j image]) boolean?]{Determines whether two images are equal.})
|
||||
|
||||
("Misc"
|
||||
(identity (any -> any)
|
||||
"Returns the argument unchanged.")
|
||||
((beginner-error error) (any ... -> void) "signals an error, combining the given values into an error message.\n\nIf any of the values' printed representations is too long, it is truncated and ``...'' is put into the string. If the first value is a symbol, it is treated specially; it is suffixed with a colon and a space (the intention is that the symbol is the name of the function signaling the error).")
|
||||
((beginner-struct? struct?) (any -> boolean)
|
||||
"Determines whether some value is a structure.")
|
||||
((beginner-equal? equal?) (any any -> boolean)
|
||||
"Determines whether two values are structurally equal"
|
||||
" where basic values are compared with the eqv? predicate.")
|
||||
(eq? (any any -> boolean)
|
||||
"Determines whether two values are equivalent from the"
|
||||
" computer's perspective (intensional).")
|
||||
(eqv? (any any -> boolean)
|
||||
"Determines whether two values are equivalent from the"
|
||||
" perspective of all functions that can be applied to it (extensional).")
|
||||
((beginner-=~ =~) (number number non-negative-real -> boolean)
|
||||
"Checks whether two numbers are within some amount (the third argument) of either other.")
|
||||
((beginner-equal~? equal~?) (any any non-negative-real -> boolean)
|
||||
"Compares like equal? on the first two arguments, except using =~ in the case of numbers.")
|
||||
(eof eof
|
||||
"The end-of-file value.")
|
||||
(eof-object? (any -> boolean)
|
||||
"Determines whether some value is the end-of-file value.")
|
||||
((beginner-exit exit) ( -> void)
|
||||
"Exits the running program.")))
|
||||
@defproc[(identity [x any/c]) any]{Returns the argument unchanged.}
|
||||
@defproc[((beginner-error error) [x any/c] ...) void?]{Signals an error, combining the given values
|
||||
into an error message. If any of the values'
|
||||
printed representations is too long, it is
|
||||
truncated and ``...'' is put into the string.
|
||||
If the first value is a symbol, it is treated
|
||||
specially ; it is suffixed with a colon and a
|
||||
space (the intention is that the symbol is the
|
||||
name of the function signaling the error).}
|
||||
@defproc[((beginner-struct? struct?) [x any/c]) boolean?]{Determines whether some value is a structure.}
|
||||
@defproc[((beginner-equal? equal?) [x any/c][y any/c]) boolean?]{Determines whether two values are structurally equal where basic values are compared with the eqv? predicate.}
|
||||
@defproc[(eq? [x any/c][y any/c]) boolean?]{Determines whether two values are equivalent from the computer's perspective (intensional).}
|
||||
@defproc[(eqv? [x any/c][y any/c]) boolean?]{Determines whether two values are equivalent from the perspective of all functions that can be applied to it (extensional).}
|
||||
@defproc[((beginner-=~ =~) [x number][y number][z non-negative-real]) boolean?]{Checks whether two numbers are within some amount (the third argument) of either other.}
|
||||
@defproc[((beginner-equal~? equal~?) [x any/c][y any/c][z non-negative-real]) boolean?]{Compares like equal? on the first two arguments, except using =~ in the case of numbers.}
|
||||
@defproc[(eof) eof-object?]{The end-of-file value.}
|
||||
@defproc[(eof-object? [x any/c]) boolean?]{Determines whether some value is the end-of-file value.}
|
||||
@defproc[((beginner-exit exit)) void]{Exits the running program.}))
|
||||
|
|
|
@ -1,64 +1,42 @@
|
|||
(module intermediate-funs scheme/base
|
||||
(require "teachprims.rkt" "and-or-map.rkt"
|
||||
mzlib/etc
|
||||
scheme/list
|
||||
syntax/docprovide
|
||||
(for-syntax scheme/base))
|
||||
#lang at-exp scheme/base
|
||||
|
||||
(provide-and-document
|
||||
procedures
|
||||
(all-from-except beginner: lang/private/beginner-funs procedures + * - / append)
|
||||
(require "teachprims.rkt" "and-or-map.rkt"
|
||||
mzlib/etc
|
||||
(only-in racket/list argmin argmax)
|
||||
syntax/docprovide
|
||||
(for-syntax scheme/base))
|
||||
|
||||
("Numbers (relaxed conditions)"
|
||||
|
||||
(+ (number ... -> number) "Adds all given numbers.")
|
||||
(* (number ... -> number) "Multiplys all given numbers.")
|
||||
(- (number ... -> number) "Subtracts from the first all remaining numbers.")
|
||||
(/ (number ... -> number) "Divides the first by all remaining numbers.")
|
||||
)
|
||||
(require "provide-and-scribble.rkt" scribble/manual)
|
||||
|
||||
("Lists"
|
||||
((intermediate-append append) ((listof any) ... -> (listof any))
|
||||
"Creates a single list from several, by juxtaposition of the items."))
|
||||
|
||||
("Higher-Order Functions"
|
||||
(map ((X ... -> Z) (listof X) ... -> (listof Z))
|
||||
"Constructs a new list by applying a function to each item on one or more existing lists.")
|
||||
(for-each ((any ... -> any) (listof any) ... -> void)
|
||||
"Applies a function to each item on one or more lists for effect only.")
|
||||
((intermediate-filter filter) ((X -> boolean) (listof X) -> (listof X))
|
||||
"Constructs a list from all those items on a list for which the predicate holds.")
|
||||
((intermediate-foldr foldr) ((X Y -> Y) Y (listof X) -> Y)
|
||||
"(foldr f base (list x-1 ... x-n)) = (f x-1 ... (f x-n base))")
|
||||
((intermediate-foldl foldl) ((X Y -> Y) Y (listof X) -> Y)
|
||||
"(foldl f base (list x-1 ... x-n)) = (f x-n ... (f x-1 base))")
|
||||
(build-list (nat (nat -> X) -> (listof X))
|
||||
"(build-list n f) = (list (f 0) ... (f (- n 1)))")
|
||||
((intermediate-build-string build-string) (nat (nat -> char) -> string)
|
||||
"(build-string n f) = (string (f 0) ... (f (- n 1)))")
|
||||
((intermediate-quicksort quicksort) ((listof X) (X X -> boolean) -> (listof X))
|
||||
"Constructs a list from all items on a list in an order according to a predicate.")
|
||||
((intermediate-sort sort) ((listof X) (X X -> boolean) -> (listof X))
|
||||
"Constructs a list from all items on a list in an order according to a predicate.")
|
||||
((intermediate-andmap andmap) ((X -> boolean) (listof X) -> boolean)
|
||||
"(andmap p (list x-1 ... x-n)) = (and (p x-1) ... (p x-n))")
|
||||
((intermediate-ormap ormap) ((X -> boolean) (listof X) -> boolean)
|
||||
"(ormap p (list x-1 ... x-n)) = (or (p x-1) ... (p x-n))")
|
||||
|
||||
(argmin ((X -> real) (listof X) -> X)
|
||||
"Finds the (first) element of the list that minimizes the output of the function.")
|
||||
|
||||
(argmax ((X -> real) (listof X) -> X)
|
||||
"Finds the (first) element of the list that maximizes the output of the function.")
|
||||
|
||||
(memf ((X -> any) (listof X) -> (union false (listof X)))
|
||||
"Produces false if the predicate given as the first argument
|
||||
produces false for all items on the given list. If the
|
||||
given predicate produces true for any of the items on the list,
|
||||
memf returns the sub-list starting from that element.")
|
||||
(apply ((X-1 ... X-N -> Y) X-1 ... X-i (list X-i+1 ... X-N) -> Y)
|
||||
"Applies a function using items from a list as the arguments.")
|
||||
(compose ((Y-1 -> Z) ... (Y-N -> Y-N-1) (X-1 ... X-N -> Y-N) -> (X-1 ... X-N -> Z))
|
||||
"Composes a sequence of procedures into a single procedure.")
|
||||
(procedure? (any -> boolean)
|
||||
"Produces true if the value is a procedure."))))
|
||||
(provide-and-scribble
|
||||
procedures
|
||||
(all-from-except beginner: (submod "beginner-funs.rkt" without-wrapper) procedures + * - / append)
|
||||
|
||||
("Numbers (relaxed conditions)"
|
||||
@defproc[(+ [x number] ...) number]{Adds all given numbers.}
|
||||
@defproc[(* [x number] ...) number]{Multiplies all given numbers.}
|
||||
@defproc[(- [x number] ...) number]{Subtracts from the first all remaining numbers.}
|
||||
@defproc[(/ [x number] ...) number]{Divides the first by all remaining numbers.}
|
||||
)
|
||||
|
||||
("Lists"
|
||||
@defproc[((intermediate-append append) [l (listof any)] ...) (listof any)]{Creates a single list from several, by juxtaposition of the items.})
|
||||
|
||||
("Higher-Order Functions"
|
||||
@defproc[(map [f (X ... -> Z)] [l (listof X)] ...) (listof Z)]{Constructs a new list by applying a function to each item on one or more existing lists.}
|
||||
@defproc[(for-each [f (any ... -> any)] [l (listof any)] ...) void?]{Applies a function to each item on one or more lists for effect only.}
|
||||
@defproc[((intermediate-filter filter) [p? (X -> boolean)] [l (listof X)]) (listof X)]{Constructs a list from all those items on a list for which the predicate holds.}
|
||||
@defproc[((intermediate-foldr foldr) [f (X Y -> Y)] [base Y] [l (listof X)]) Y]{(foldr f base (list x-1 ... x-n)) = (f x-1 ... (f x-n base))}
|
||||
@defproc[((intermediate-foldl foldl) [f (X Y -> Y)] [base Y] [l (listof X)]) Y]{(foldl f base (list x-1 ... x-n)) = (f x-n ... (f x-1 base))}
|
||||
@defproc[(build-list [n nat] [f (nat -> X)]) (listof X)]{(build-list n f) = (list (f 0) ... (f (- n 1)))}
|
||||
@defproc[((intermediate-build-string build-string) [n nat] [f (nat -> char)]) string]{(build-string n f) = (string (f 0) ... (f (- n 1)))}
|
||||
@defproc[((intermediate-quicksort quicksort) [l (listof X)] [comp (X X -> boolean)]) (listof X)]{Constructs a list from all items on a list in an order according to a predicate.}
|
||||
@defproc[((intermediate-sort sort) [l (listof X)] [comp (X X -> boolean)]) (listof X)]{Constructs a list from all items on a list in an order according to a predicate.}
|
||||
@defproc[((intermediate-andmap andmap) [p? (X -> boolean)] [l (listof X)]) boolean]{(andmap p (list x-1 ... x-n)) = (and (p x-1) ... (p x-n))}
|
||||
@defproc[((intermediate-ormap ormap) [p? (X -> boolean)] [l (listof X)]) boolean]{(ormap p (list x-1 ... x-n)) = (or (p x-1) ... (p x-n))}
|
||||
@defproc[(argmin [f (X -> real)] [l (listof X)]) X]{Finds the (first) element of the list that minimizes the output of the function.}
|
||||
@defproc[(argmax [f (X -> real)] [l (listof X)]) X]{Finds the (first) element of the list that maximizes the output of the function.}
|
||||
@defproc[(memf [p? (X -> any)] [l (listof X)]) (union false (listof X))]{Produces false if the predicate given as the first argument produces false for all items on the given list. If the given predicate produces true for any of the items on the list, memf returns the sub-list starting from that element.}
|
||||
@defproc[(apply [f (X-1 ... X-N -> Y)] [x-1 X-1] ... [l (list X-i+1 ... X-N)]) Y]{Applies a function using items from a list as the arguments.}
|
||||
@defproc[(compose [f (X -> Y)] [g (Y -> Z)]) (X -> Z)]{Composes a sequence of procedures into a single procedure.}
|
||||
@defproc[(procedure? [x any]) boolean?]{Produces true if the value is a procedure.}))
|
||||
|
|
Loading…
Reference in New Issue
Block a user