SUtils - Various Utility Functions


  Welcome to MzScheme version 300, Copyright (c) 2004-2005 PLT Scheme Inc.
  > (require (planet "sutil.scm" ("oesterholt"  "ho-utils.plt"  1 0)))
  > (glob "d:/build/sutil/*.scm")
  ("d:/build/sutil/scfg.scm" "d:/build/sutil/sprefs.scm" "d:/build/sutil/sutil.scm" "d:/build/sutil/units.scm")
  > (glob "d:/build/sutil/*.pod")
  ("d:/build/sutil/index.pod" "d:/build/sutil/index.pod~")
  > (glob "d:/build/sutil/*.pod$")
  > (basename "d:/build/sutil/index.pod")
  > (basedir (build-path "d:/build/sutil/index.pod"))
  > (home)
  "C:\\Documents and Settings\\hdijkema\\."

  > (home "local" "test")
  "C:\\Documents and Settings\\hdijkema\\local\\test"

  > (mkdir-p (home "local" "test"))
  <executes make-directory* if directory doesn't exist already>
  > (define a 10)
  > (post++ a)
  > a
  > (++ a)
  >(let ((i 0)) (while (< i 10) (display i)(++ i)) (newline))
 >(llet (( (a b c) (list 1 2 3) ))
    (display (format "~a, ~a, ~a~%" a b c)))
 1 2 3
  >(require (lib "" "srfi" "19"))
  >(define a (current-date));
  >(sleep 3)(define b (current-date));
  >(date<? a b)
  >(date>? a b)
 And we've also got 'date<=?', 'date>=?' and 'date=?'


srfi:date functions

These date functions only compare the date part of a srfi:date structure. They do so after converting to UTC time.

(date<? dt1:srfi:date dt2:srfi:date) : boolean

returns #t, if dt1<dt2; #f otherwise.

(date>=? dt1:srfi:date dt2:srfi:date) : boolean

returns #t, if dt1>=dt2; #f otherwise.

(date>? dt1:srfi:date dt2:srfi:date) : boolean

returns #t, if dt1>dt2; #f otherwise.

(date<=? dt1:srfi:date dt2:srfi:date) : boolean

returns #t, if dt1<=dt2; #f otherwise.

(date=? dt1:srfi:date dt2:srfi:date) : boolean

returns #t, if dt1=dt2; #f otherwise.

(leap-year? dt:srfi:date) : boolean

returns #t, if dt is a leap year; #f otherwise.

(valid-date? year:number month:number day:number) : boolean

returns #t, year, month and day form a valid date.

Directory browsing

(glob file-pattern:path or string) : list of file:string

returns a list of files that match the given file pattern (empty list if nothing has been found).

(basedir path:path or string) : directory part of path:string

returns the directory part of a given path.

(basename path:path or string) : name of file:string

returns the name part of a given path, or "" if path is a directory.

(mkdir-p path:path or string) : undefined

calls 'make-directory*' if path does not already exist.


(post++ x:number) : number (x)

Increments x, but returns it's original value.

(++ x:number) : number

Increments x and returns the incremented value.

Language constructs

(while expression b1 ...)

Creates a while loop using expression as a continue rule. See also Synopsis.


"List let". With llet it is possible to assign a list returned by a function to individual variables (like perls construction: ($a,$b,$c)=f(10);)

String utils

(substr S:string from:integer . to:integer) : string

A perl like substr. If to isn't given, returns the part of S from 'from' until the end of S. Otherwise, does a (substring S from to). Prevents errors. Constrains the operation to what is possible with S.

(splitstr S:string c:char or list of char) : list of string

Splits string S into substrings for all characters that are either equal to c or in the list of characters that c is. If there's nothing to split, the list of the original string is returned. The characters in c or c itself are removed from the string(s).


(c) 2005 Hans Oesterholt-Dijkema. Distributed under LGPL.
Contact: send email to hans in domain