History

docs: document let, let* and letrec

Sigrid Solveig Haflínudóttir committed 4 months ago

Commit b9c4cc31 parent 0a9d6ff2 files · +69 −15Browse files

Showing the changes to src/system.sl (1 of 2 files). Show all

Unified · Split

src/system.sl+51−0
@@ -1961,6 +1961,19 @@ · 1960 unmodified lines
19611961 (list '$trycatch try catch))
19621962
19631963 (defmacro (letrec binds . body)
1964+ «Same as the second form of `let` but each of the binding expressions
1965+ may reference any of the variables bound, before or after.
1966+
1967+ Examples:
1968+
1969+ (letrec ((a (λ () 1))
1970+ (b (λ () (+ (c) 1)))
1971+ (c (λ () (+ (a) 1))))
1972+ (list (a) (b) (c)))
1973+ ; ↳ (1 3 2)»
1974+ :doc-group syntax
1975+ :doc-see let
1976+ :doc-see let*
19641977 (unless (cons? body)
19651978 (arg-error "missing body"))
19661979 `((λ ,(map car binds)
@@ -1969,6 +1982,19 @@ · 2 unmodified lines
19691982 ,.(map void binds)))
19701983
19711984 (defmacro (let* binds . body)
1985+ «Same as the second form of `let` but each of the binding expressions
1986+ may reference any of the varibles bound previously.
1987+
1988+ Examples:
1989+
1990+ (let* ((a 1)
1991+ (b (+ a 1))
1992+ (c (+ b 1)))
1993+ c)
1994+ ; ↳ 3»
1995+ :doc-group syntax
1996+ :doc-see let
1997+ :doc-see letrec
19721998 (unless (cons? body)
19731999 (arg-error "missing body"))
19742000 `((λ (,(caar binds))
@@ -1978,6 +2004,29 @@ · 3 unmodified lines
19782004 ,(aref binds 0 1)))
19792005
19802006 (defmacro (let binds . body)
2007+ «Bind variables and execute a series of expression that use
2008+ these bindings, return the result of the last expression.
2009+
2010+ The first form `(let id ((… ) …) …)`, which is called
2011+ "named let", allows referencing the resulting lambda within
2012+ the expressions following the bindings to aid with recursive
2013+ calls.
2014+
2015+ Examples:
2016+
2017+ (let loop ((a (iota 3 1))) ; first form
2018+ (when a
2019+ (princ (car a))
2020+ (loop (cdr a))))
2021+ ; ‼ 123
2022+ ; ↳ NIL
2023+
2024+ (let ((a 123) (b 456)) ; second form
2025+ (+ a b))
2026+ ; ↳ 579»
2027+ :doc-group syntax
2028+ :doc-see let*
2029+ :doc-see letrec
19812030 (unless (cons? body)
19822031 (arg-error "missing body"))
19832032 (let ((lname NIL))
@@ -2004,6 +2053,8 @@ · 20 unmodified lines
20042053 thelambda)
20052054 theargs))))
20062055
2056+(defdoc (let id binds . body))
2057+
20072058 (defmacro (cond . clauses)
20082059 (def (1arg-lambda? func)
20092060 (and (cons? func)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t