SRFI 5: A compatible let form with signatures and rest arguments

This egg extends the syntax of let to allow define-like named let forms with optional "rest" arguments.

  1. SRFI 5: A compatible let form with signatures and rest arguments
  2. SRFI description
  3. Specification
    1. Signature-style syntax
    2. Rest Arguments
    3. Syntax
      1. 1. Unnamed
      2. 2. Named, non-signature-style, no rest argument
      3. 3. Named, signature-style, no rest argument
      4. 4. Named, non-signature-style, rest argument
      5. 5. Named, signature-style, rest argument
    4. Semantics
  4. About this egg
    1. Author
    2. Maintainer
    3. Repository
    4. Version history
    5. Copyright

SRFI description

This page is intended to document the forms exported by the egg. For a full description of SRFI 5, see the SRFI document.

Specification

Signature-style syntax

Using the let form provided by this egg, the following

(let (fibonacci (n 10) (i 0) (f0 0) (f1 1))
  (if (= i n)
      f0
      (fibonacci n (+ i 1) f1 (+ f0 f1))))

is equivalent to

(let fibonacci ((n 10) (i 0) (f0 0) (f1 1))
  (if (= i n)
      f0
      (fibonacci n (+ i 1) f1 (+ f0 f1))))

Rest Arguments

This egg allows named let forms with rest parameters. For example,

(let (blast (port (current-output-port)) . (x (+ 1 2) 4 5))
  (if (null? x)
      'just-a-silly-contrived-example
      (begin
        (write (car x) port)
        (apply blast port (cdr x)))))

is equivalent to

(letrec ((blast
          (lambda (port . x)
            (if (null? x)
                'just-a-silly-contrived-example
                (begin
                 (write (car x) port)
                 (apply blast port (cdr x)))))))
  (blast (current-output-port) (+ 1 2) 4 5))

Note: Users of this feature should be aware of the potential for space leaks. In the above snippet, for example, the list denoted by x will be newly allocated on each recursive call.

Syntax

1. Unnamed

(let ((<parameter> <argument>)...)
  <body>...)

2. Named, non-signature-style, no rest argument

(let <name> ((<parameter> <argument>)...)
  <body>...)

3. Named, signature-style, no rest argument

(let (<name> (<parameter> <argument>)...)
  <body>...)

4. Named, non-signature-style, rest argument

(let <name> ((<parameter> <argument>)... . (<rest-parameter> <rest-argument>...))
  <body>...)

5. Named, signature-style, rest argument

(let (<name> (<parameter> <argument>)... . (<rest-parameter> <rest-argument>...))
  <body>...)

Semantics

Let $lambda and $letrec be hygienic bindings for the lambda and letrec forms, respectively.

For informal syntax 1:

(($lambda (<parameter>...) <body>...) <argument>...)

For informal syntaxes 2 and 3:

($letrec ((<name> ($lambda (<parameter>...) <body>...)))
  (<name> <argument>...))

For informal syntaxes 4 and 5:

($letrec ((<name> ($lambda (<parameter>... . <rest-parameter>) <body>...)))
  (<name> <argument>... <rest-argument>...))

About this egg

Author

Andy Gaynor

Maintainer

Wolfgang Corcoran-Mathe

Contact: wcm at sigwinch dot xyzzy without the zy

Repository

GitHub

Version history

0.1
(2020-11-11) Ported to Chicken Scheme 5 (Sergey Goldgaber).
0.2
(2020-11-16) Fixed broken egg file name (Sergey Goldgaber).
0.3
(2022-04-25) Change maintainer, fix import.
0.3.1
(2022-04-26) Egg infrastructure fixes.
0.3.2
(2022-04-29) Add tests, rework wiki page.

Copyright (C) Andy Gaynor (1999). All Rights Reserved.

This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Scheme Request For Implementation process or editors, except as needed for the purpose of developing SRFIs in which case the procedures for copyrights defined in the SRFI process must be followed, or as required to translate it into languages other than English.

The limited permissions granted above are perpetual and will not be revoked by the authors or their successors or assigns.

This document and the information contained herein is provided on an "AS IS" basis and THE AUTHOR AND THE SRFI EDITORS DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.