On Fri, 01 Mar 2024 14:24:37 -0800, Paul Rubin
<
[email protected]d> wrote:
George Neuner <[email protected]> writes:
Named Let is not a binding construct - it's a looping construct.
See 11.16
Thanks, I wonder if that is something relatively recent (i.e. arrived
between r4rs and r6rs). It is kind of ugly and I'm used to seeing
nested defines. Maybe there are some situations where the named let is
more convenient. Or maybe I can get used to it.
Part of the idea of Guile was to be the execution engine for various
other languages that would get transpiled to Scheme, but idk if that
went anywhere.
Named Let was formally added to Scheme in R5RS, but it was recognized
as being a legal variant at least as far back as R3RS.
=======================
R3RS [4.2.4 Iteration]:
R4RS [4.2.4 Iteration]:
:
(let <variable> <bindings> <body>) syntax
Some implementations of Scheme permit a variant on the
syntax of let called \named let" which provides a more
general looping construct than do, and may also be used
to express recursions.
Named let has the same syntax and semantics as ordinary
let except that <variable> is bound within <body> to
a procedure whose formal arguments are the bound vari-
ables and whose body is <body>. Thus the execution of
hbodyi may be repeated by invoking the procedure named
by <variable>.
(let loop ((numbers '(3 -2 1 6 -5))
(nonneg '())
(neg '()))
(cond ((null? numbers) (list nonneg neg))
((>= (car numbers) 0)
(loop (cdr numbers)
(cons (car numbers) nonneg)
neg))
((< (car numbers) 0)
(loop (cdr numbers)
nonneg
(cons (car numbers) neg)))))
==> ((6 1 3) (-5 -2))
=======================
R5RS [4.2.4 Iteration]:
:
(let <variable> <bindings> <body>) library syntax
“Named let” is a variant on the syntax of let which pro-
vides a more general looping construct than do and may
also be used to express recursions. It has the same syn-
tax and semantics as ordinary let except that <variable>
is bound within <body> to a procedure whose formal argu-
ments are the bound variables and whose body is <body>.
Thus the execution of <body> may be repeated by invoking
the procedure named by <variable>.
:
=======================
Unfortunately I don't have any references older than R3RS.
George
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)