![]()
![]()
The following is a short list of useful code that comes with scheme48. Definitions of these packages can be found in the files rts-packages.scm, comp-packages.scm, and more-packages.scm in the distribution directory. The bindings they export are listed in interfaces.scm and more-interfaces.scm.
        ,load-package bigbit
	,open bitwise
The general syntax is:
      (define-record-type <tag> <type-name>
        (<constructor-name> <field-tag>*)
	<predicate-name>
	(<field-tag> <accessor-name> [<modifier-name>])*)
Example:
      (define-record-type pare :pare
        (kons x y)
	pare?
	(x kar set-kar!)
	(y kdr))
    This defines KONS to be a constructor, KAR and KDR to be
    accessors, SET-KAR! to be a modifier, and PARE? to be a predicate
    for a new type of object.  The type itself is named :PARE.
    PARE is a tag used in printing the new objects.
    The field tags X and Y are used in the inspector and to match
    constructor arguments with fields.
By default, the new objects print as #{Pare}. The print method can be modified using DEFINE-RECORD-DISCLOSER:
      (define-record-discloser :pare
        (lambda (p) `(pare ,(kar p) ,(kdr p))))
        (DISPLAY-CONDITION condition port) => unspecific
	  Display condition in an easily readable form.  E.g.
	  > ,open display-conditions handle conditions
	  > (display-condition
	     (call-with-current-continuation
	       (lambda (k)
		 (with-handler (lambda (c punt)
				 (if (error? c)
				     (k c)
				     (punt)))
		   (lambda () (+ 1 'a)))))
	     (current-output-port))
	  Error: exception
		 (+ 1 'a)
	  > 
      (MAKE-FLUID top-level-value) => a "fluid" object
      (FLUID fluid) => current value of fluid object
      (SET-FLUID! fluid value) => unspecific; changes current value of
        fluid object
      (LET-FLUID fluid value thunk) => whatever thunk returns
Within the dynamic extent of execution of (thunk), the fluid object has value as its binding (unless changed by SET-FLUID! or overridden by another LET-FLUID). E.g.
      (define f (make-fluid 7))
      (define (baz) (+ (fluid f) 1))
      (baz)   ;=> 8
      (let-fluid f 4 (lambda () (+ (baz) 1)))  ;=> 6
      (WITH-HANDLER handler thunk) => whatever thunk returns.
Handler is a procedure of two arguments. The first argument is a condition object, and the second is a "punt" procedure. The handler should examine the condition object (using ERROR?, etc. from the CONDITIONS structure). If it decides not to do anything special, it should tail-call the "punt" procedure. Otherwise it should take appropriate action and perform a non-local exit. It should not just return unless it knows damn well what it's doing; returns in certain situations can cause VM crashes.
,open threads more-threads (start-threads) (spawn (lambda () (display "Hello ")))
The procedure pretty-print takes three arguments: the object to be printed, a port to write to, and the current horizontal cursor position. If you've just done a newline, then pass in zero for the position argument.
The algorithm is very peculiar, and sometimes buggy.
        > (define random (make-random <seed>))
	> (random)  =>  a pseudo-random number between 0 and 2^28
        (sort-list <list> <pred>)
	(sort-list! <list> <pred>)
        (MAKE-WEAK-POINTER thing) => weak-pointer
	(WEAK-POINTER-REF weak-pointer) => thing or #F
	  #F if the thing has been gc'ed.
        (RECURRING-WRITE thing port recur) => unspecific
This is the same as WRITE except that recursive calls invoke the recur argument instead of WRITE. For an example, see the definition of LIMITED-WRITE in env/dispcond.scm, which implements processing similar to common Lisp's *print-level* and *print-length*.
![]()
Ownership, Maintenance and Disclaimers
Last modified