Miscellaneous libraries

13.1  when and unless

This section describes the (r6rs when-unless)library.

syntax:  (when <test> <expression1> <expression2> ...) 
syntax:  (unless <test> <expression1> <expression2> ...) 

Syntax: <Test> must be an expression. Semantics: A when expression is evaluated by evaluating the <test> expression. If <test> evaluates to a true value, the remaining <expression>s are evaluated in order, and the result(s) of the last <expression> is(are) returned as the result(s) of the entire when expression. Otherwise, the when expression evaluates to the unspecified value. An unless expression is evaluated by evaluating the <test> expression. If <test> evaluates to false, the remaining <expression>s are evaluated in order, and the result(s) of the last <expression> is(are) returned as the result(s) of the entire unless expression. Otherwise, the unless expression evaluates to the unspecified value.

(when (> 3 2) ’greater)         ===⇒ greater
(when (< 3 2) ’greater)         ===⇒ 
(unless (> 3 2) ’less)         ===⇒ 
(unless (< 3 2) ’less)         ===⇒ less

The when and unless expressions are derived forms. They could be defined in terms of base library forms by the following macros:

(define-syntax when
  (syntax-rules ()
    ((when test result1 result2 ...)
     (if test
         (begin result1 result2 ...)))))

(define-syntax unless
  (syntax-rules ()
    ((unless test result1 result2 ...)
     (if (not test)
         (begin result1 result2 ...)))))

13.2  case-lambda

This section describes the (r6rs case-lambda)library.

syntax:  (case-lambda <clause1> <clause2> ...) 

Syntax: Each <clause> should be of the form

(<formals> <body>)

<Formals> must be as in a lambda form (report section on “Procedures”), <body> must be a body according to report section on “Bodies and sequences”.

Semantics: A case-lambda expression evaluates to a procedure. This procedure, when applied, tries to match its arguments to the <clause>s in order. The arguments match a clause if one the following conditions is fulfilled:

For the first clause matched by the arguments, the variables of the <formals> are bound to fresh locations containing the argument values in the same arrangement as with lambda.

If the arguments match none of the clauses, an exception with condition type &assertion is raised.

(define foo
  (case-lambda 
   (() ’zero)
   ((x) (list ’one x))
   ((x y) (list ’two x y))
   ((a b c d . e) (list ’four a b c d e))
   (rest (list ’rest rest))))

(foo)         ===⇒ zero
(foo 1)         ===⇒ (one 1)
(foo 1 2)         ===⇒ (two 1 2)
(foo 1 2 3)         ===⇒ (rest (1 2 3))
(foo 1 2 3 4)         ===⇒ (four 1 2 3 4 ())

A sample definition of case-lambda in terms of simpler forms is in appendix 18.

13.3  Command-line access and exit values

The procedures described in this section are exported by the (r6rs programs)library.

procedure:  (command-line) 

Returns a list of strings with at least one element. The first element is an implementation-specific name for the running top-level program. The following elements are command-line arguments according to the operating system’s conventions.

procedure:  (exit) 
procedure:  (exit obj) 

Exits the running program and communicates an exit value to the operating system. If no argument is supplied, the exit procedure should communicate to the operating system that the program exited normally. If an argument is supplied, the exit procedure should translate the argument into an appropriate exit value for the operating system.