On this page:
+ +
--
box-me
identity
symetric
to-proc
get-type
1.1 Lists
transpose
list-choose
mean
list-set
list->lines
1.2 Functions and Applications
argbest
map/ apply
for-each/ apply
ntimes
times
1.3 Vectors
with-vector
vector-clone
1.4 Strings
to-string
protect-string
trim
string-reverse
string->lines
regexp-matcher
comment-section
comment-chapter
proc->string
proc->symbol
1.5 Files and Directories
directory-list-rec
filter-file-list
file->lines/ latin-1
file->name-ext
1.6 Classes and Objects
map/ send
for-each/ send
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.

(box-me b val)  (one-of/c val)
  b : box?
  val : any/c
Puts val in the box b and returns val. Useful to return a value and box it as a side effect.

(identity x r ...)  (one-of/c x)
  x : any/c
  r : any/c
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

(transpose ll)  (listof list?)
  ll : (listof list?)
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.

(mean n ...)  number?
  n : number?
Returns the average value of the n.

(list-set l n v)  list?
  l : list?
  n : number?
  v : any/c
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

  > (argbest (λ(best chall)
               (and (<= (first best) (first chall))
                    (< (second best) (second chall))))
             '((3 6)(7 2)(8 3)(3 5)(3 7)))

  (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?)
Like map/apply but with for-each.

(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

(to-string x)  string?
  x : any/c
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.

(trim s [left right])  string?
  s : string?
  left : number? = 0
  right : number? = left
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")

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;   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:

  > (comment-chapter "The Show Sets Sales"
      #:width 60)

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;   The Show Sets Sales   ;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(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 ...)
 
message = method
  | (method arg ...)
Sends method along with its arguments to each object and returns the list of results.

For example
  (map/send my-method (list obj1 obj2 obj3))
is equivalent to
  (map (λ(x)(send x my-method)) (list obj1 obj2 obj3))
and
  (map/send (my-method 3 5) (list obj1 obj2 obj3))
is equivalent to
  (map (λ(x)(send x my-method 3 5)) (list obj1 obj2 obj3))
(for-each/send method obj ...)
Like map/send but returns (void).