Version: 4.2.2
1 Common Scheme Utilities
(require (planet orseau/lazy-doc:1:0/common)) |
This module provides some useful functions and forms
that are common to most of the files of this package.
(++ var) |
Increments var.
(-- var) |
Decrements var.
Puts val in the box b and returns val.
Useful to return a value and box it as a side effect.
Returns only the first of the parameters.
(symetric fxy) → procedure? |
fxy : procedure? |
Returns the symetric function of fxy.
(to-proc x) → procedure? |
x : any/c |
Returns a procedure that accepts any number of arguments and returns x.
If x was already a procedure, returns x without change.
(get-type x) → (listof procedure?) |
x : any/c |
Retuns (some of) the types that x matches.
1.1 Lists
Transposes a list of lists.
Example: |
> (transpose '((a b c) (0 1 2))) |
((a 0) (b 1) (c 2)) |
(list-choose l) → any |
l : list? |
Chooses one element from l.
Returns the average value of the n.
Returns the same list l where element at position n
is replaced by v.
(list->lines l sep) → (listof? list?) |
l : list? |
sep : any/c |
Splits a list into "lines" (list of lists).
Example: |
> (list->lines '(a b c x d e x x f g h x o) 'x) |
((a b c) (d e) () (f g h) (o)) |
1.2 Functions and Applications
(argbest proc lst) → any |
proc : procedure? |
lst : list? |
Returns the best element of lst.
Each challenger is compared to the best value with proc.
If proc returns #t, the best wins.
Examples: | ||||
> (argbest < '(5 2 5 7 8 1 5)) | ||||
1 | ||||
> (argbest > '(5 2 5 7 8 1 5)) | ||||
8 | ||||
| ||||
(3 5) |
(map/apply proc ll ...) → list? |
proc : procedure? |
ll : (listof list?) |
Applies proc to each list element of ll.
(for-each/apply proc ll ...) → void? |
proc : procedure? |
ll : (listof list?) |
(ntimes n proc) → void? |
n : number? |
proc : procedure? |
Does proc n times.
(times n val-max body ...) |
Binds n to the values from 0 to val-max while doing body ...
1.3 Vectors
(with-vector lst-id body ...) |
Temporarily turns lst-id into a vector, does body ...
then turns it back to a list
(vector-clone v) → any |
v : any/c |
1.4 Strings
Turns any value into a string.
(protect-string x) → string? |
x : any/c |
Turns any value into a string.
If x is already a string, quotes its quotes.
Removes left and right characters from s.
(string-reverse str) → string? |
str : string? |
Reverses str.
(string->lines str [sep]) → (listof string?) |
str : string? |
sep : string? = "\n" |
Splits str at sep.
(regexp-matcher re) → procedure? |
re : (or/c string? pregexp? regpexp?) |
Returns a procedure that matches re.
(comment-section text [#:pre pre #:post post]) → void? |
text : string? |
pre : string? = ";;; " |
post : string? = (string-reverse pre) |
Displays a comment string that can be copied into the source file.
The width of the result depends on the with of text.
Example: | |||
> (comment-section "And now for something completly different") | |||
|
(comment-chapter text [pre post #:width width]) → void? |
text : string? |
pre : string? = " " |
post : string? = (string-reverse pre) |
width : number? = 80 |
Similar to comment-section but the width of the result
does not depend on the width of text.
Example: | |||||
| |||||
|
(proc->string proc) → string? |
proc : procedure? |
Example: |
> (proc->string proc->symbol) |
"proc->symbol" |
(proc->symbol proc) → symbol? |
proc : procedure? |
Example: |
> (proc->symbol proc->symbol) |
proc->symbol |
1.5 Files and Directories
(directory-list-rec [path]) → (listof (or/c string? path?)) |
path : path-string? = (current-directory) |
Returns the list of files and directory contained in path,
recursively including sub-directories.
The files are returned with their full path.
(filter-file-list re [files]) → (listof (or/c string? path?)) |
re : (or/c string? pregexp? regpexp?) |
files : (listof (or/c string? path?)) = (directory-list) |
Filters the list of files files with the regexp re.
Example: |
> (filter-file-list "parser\\.ss$" (directory-list)) |
(#<path:defs-parser.ss> #<path:simple-parser.ss>) |
(file->lines/latin-1 file) → (listof string?) |
file : path-string? |
(file->name-ext file) → any |
file : path-string? |
Returns two values: the name part of the file and the extension part, without the dot.
Example: |
> (file->name-ext "common.scm.ss") |
"common.scm" |
"ss" |
1.6 Classes and Objects
(map/send message obj ...) | ||||||||||
|
Sends method along with its arguments
to each object and returns the list of results.
For example
is equivalent to
and
is equivalent to
(for-each/send method obj ...) |