Version: 4.2.2
5 Common Scheme Utilities
This module provides some useful functions and forms
that are common to most of the files of this package
and other future packages.
Increments 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.
Returns the symetric function of fxy.
Returns a procedure that accepts any number of arguments and returns x.
If x was already a procedure, returns x without change.
Returns (some of) the types that x matches.
5.1 Lists
Transposes a list of lists.
Example: |
> (transpose '((a b c) (0 1 2))) |
((a 0) (b 1) (c 2)) |
Chooses one element from l.
Returns the first value of l that is not #f,
or returns #f if none is found.
Useful with functions that return a value or #f (like get-env).
A default value can be set as the last element.
Returns the average value of the n.
Returns the same list l where element at position n
is replaced by v.
Example: |
> (list-set '(a b c d e) 3 'huh?) |
(a b c huh? e) |
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)) |
5.2 Functions and Applications
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) |
Applies proc to each list element of ll.
Does proc n times.
(times n val-max body ...) |
Binds n to the values from 0 to val-max while doing body ...
5.3 Vectors
Temporarily turns lst-id into a vector, does body ...
then turns it back to a list
5.4 Strings
Turns any value into a string.
Turns any value into a string.
If x is already a string, quotes its quotes.
Example: |
> (protect-string "the string \"plop\" is a string.") |
"\"the string \\\"plop\\\" is a string.\"" |
Removes left and right characters from s.
Example: |
> (trim "abcdefghij" 3 1) |
"defghi" |
Reverses str.
Example: |
> (string-reverse "emordnilap a ton ma I") |
"I am not a palindrome" |
Splits str at sep.
Example: |
> (string->lines "One\nTwo Three\nFour") |
("One" "Two Three" "Four") |
Returns a procedure that matches re.
Example: |
> (map (regexp-matcher "pl(.)p") '("aplipa" "youp" "coplop")) |
(("plip" "i") #f ("plop" "o")) |
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 completely different") |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;; And now for something completely different ;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
Similar to
comment-section but the width of the result
does not depend on the width of
text.
Example: |
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;; The Show Sets Sales ;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
Returns the string corresponding to the procedure proc.
Returns the symbol corresponding to the procedure proc.
5.5 Files and Directories
Returns the list of files and directory contained in path,
recursively including sub-directories.
The files are returned with their full path.
Filters the list of files files with the regexp re.
Returns two values: the name part of the file and the extension part, without the dot.
Returns the path as a string, and surround it with double-quotes
if it contains spaces.
A parameter controlling the directory default explorer.
The command
explorer depends on the OS (default:
"konqueror file:"
for Unix,
"open " for Mac OS X,
"explorer " for Windows).
5.6 Classes and Objects
(map/send message obj ...) |
|
message | | = | | method | | | | | | (method arg ...) |
|
Sends method along with its arguments
to each object and returns the list of results.
For example
is equivalent to
and
is equivalent to