Showing the changes to src/system.sl (1 of 2 files). Show all
Unified · Split
| @@ -1961,6 +1961,19 @@ · 1960 unmodified lines | |||
| 1961 | (list '$trycatch try catch)) | 1961 | (list '$trycatch try catch)) |
| 1962 | 1962 | ||
| 1963 | (defmacro (letrec binds . body) | 1963 | (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* | ||
| 1964 | (unless (cons? body) | 1977 | (unless (cons? body) |
| 1965 | (arg-error "missing body")) | 1978 | (arg-error "missing body")) |
| 1966 | `((λ ,(map car binds) | 1979 | `((λ ,(map car binds) |
| @@ -1969,6 +1982,19 @@ · 2 unmodified lines | |||
| 1969 | ,.(map void binds))) | 1982 | ,.(map void binds))) |
| 1970 | 1983 | ||
| 1971 | (defmacro (let* binds . body) | 1984 | (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 | ||
| 1972 | (unless (cons? body) | 1998 | (unless (cons? body) |
| 1973 | (arg-error "missing body")) | 1999 | (arg-error "missing body")) |
| 1974 | `((λ (,(caar binds)) | 2000 | `((λ (,(caar binds)) |
| @@ -1978,6 +2004,29 @@ · 3 unmodified lines | |||
| 1978 | ,(aref binds 0 1))) | 2004 | ,(aref binds 0 1))) |
| 1979 | 2005 | ||
| 1980 | (defmacro (let binds . body) | 2006 | (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 | ||
| 1981 | (unless (cons? body) | 2030 | (unless (cons? body) |
| 1982 | (arg-error "missing body")) | 2031 | (arg-error "missing body")) |
| 1983 | (let ((lname NIL)) | 2032 | (let ((lname NIL)) |
| @@ -2004,6 +2053,8 @@ · 20 unmodified lines | |||
| 2004 | thelambda) | 2053 | thelambda) |
| 2005 | theargs)))) | 2054 | theargs)))) |
| 2006 | 2055 | ||
| 2056 | (defdoc (let id binds . body)) | ||
| 2057 | |||
| 2007 | (defmacro (cond . clauses) | 2058 | (defmacro (cond . clauses) |
| 2008 | (def (1arg-lambda? func) | 2059 | (def (1arg-lambda? func) |
| 2009 | (and (cons? func) | 2060 | (and (cons? func) |