Skip to content

Commit 37bd737

Browse files
committed
Docs: Update for new function macro names
1 parent 998af3e commit 37bd737

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

doc/basics-reference.markdown

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -149,32 +149,32 @@ generate arbitrary JavaScript are built in to eslisp.
149149

150150
### General
151151

152-
| name | description |
153-
| ----------------- | ---------------------------- |
154-
| `array` | array literal |
155-
| `object` | object literal |
156-
| `regex` | regular expression literal |
157-
| `var` | variable declaration |
158-
| `.` | member expression |
159-
| `get` | *computed* member expression |
160-
| `switch` | switch statement |
161-
| `if` | conditional statement |
162-
| `?:` | ternary expression |
163-
| `while` | while loop |
164-
| `dowhile` | do-while loop |
165-
| `for` | for loop |
166-
| `forin` | for-in loop |
167-
| `break` | break statement |
168-
| `continue` | continue statement |
169-
| `label` | labeled statement |
170-
| `label` | labeled statement |
171-
| `function` | function expression |
172-
| `declarefunction` | function declaration |
173-
| `return` | return statement |
174-
| `new` | new-expression |
175-
| `debugger` | debugger statement |
176-
| `throw` | throw statement |
177-
| `try` | try-catch statement |
152+
| name | description |
153+
| ---------- | ---------------------------- |
154+
| `array` | array literal |
155+
| `object` | object literal |
156+
| `regex` | regular expression literal |
157+
| `var` | variable declaration |
158+
| `.` | member expression |
159+
| `get` | *computed* member expression |
160+
| `switch` | switch statement |
161+
| `if` | conditional statement |
162+
| `?:` | ternary expression |
163+
| `while` | while loop |
164+
| `dowhile` | do-while loop |
165+
| `for` | for loop |
166+
| `forin` | for-in loop |
167+
| `break` | break statement |
168+
| `continue` | continue statement |
169+
| `label` | labeled statement |
170+
| `label` | labeled statement |
171+
| `lambda` | function expression |
172+
| `function` | function declaration |
173+
| `return` | return statement |
174+
| `new` | new-expression |
175+
| `debugger` | debugger statement |
176+
| `throw` | throw statement |
177+
| `try` | try-catch statement |
178178

179179
#### Structural
180180

@@ -417,14 +417,13 @@ the `default`-case clause.
417417

418418
#### Function expressions
419419

420-
The `function` macro creates function expressions. Its first argument becomes
420+
The `lambda` macro creates function expressions. Its first argument becomes
421421
the argument list, and the rest become statements in its body. The `return`
422422
macro compiles to a return-statement.
423423

424424
<!-- !test in function expression -->
425425

426-
(var f (function (a b)
427-
(return (* 5 a b))))
426+
(var f (lambda (a b) (return (* 5 a b))))
428427

429428
<!-- !test out function expression -->
430429

@@ -437,7 +436,7 @@ argument, if you so wish.
437436

438437
<!-- !test in named function expression -->
439438

440-
(var f (function tea () (return "T")))
439+
(var f (lambda tea () (return "T")))
441440

442441
<!-- !test out named function expression -->
443442

@@ -451,7 +450,7 @@ These work much like function expressions above, but require a name.
451450

452451
<!-- !test in function declaration -->
453452

454-
(declarefunction tea () (return "T"))
453+
(function tea () (return "T"))
455454

456455
<!-- !test out function declaration -->
457456

doc/how-macros-work.markdown

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Yey!
6060
We could of course have written the macro function in eslisp instead:
6161

6262
(= (. module exports)
63-
(function (name) (return (array (object atom "=") name "hello"))))
63+
(lambda (name) (return (array (object atom "=") name "hello"))))
6464

6565
That compiles to the same JS before. You can write macros in any language you
6666
want, as long as you can compile it to JS before `require`-ing it from eslisp.
@@ -73,7 +73,7 @@ about that next:
7373
To make macros clearer to read, eslisp has special syntax for returning stuff
7474
that represents code. Let's rewrite the previous hello-assigning macro:
7575

76-
(= (. module exports) (function (name) (return `(= ,name "hello"))))
76+
(= (. module exports) (lambda (name) (return `(= ,name "hello"))))
7777

7878
That does exactly the same thing, but it contains less of the
7979
`array`/`object` fluff, so it's clearer to read. The `array` constructor
@@ -103,7 +103,7 @@ For example, if you want to create a shorthand `mean` for calculating the mean
103103
of some numbers, you could do
104104

105105
(macro mean
106-
(function ()
106+
(lambda ()
107107
; convert arguments to Array
108108
(var args ((. Array prototype slice call) arguments 0))
109109
(var total (. args length))
@@ -150,11 +150,11 @@ list.
150150
<!-- !test in function-expression scope macro -->
151151

152152
; Define at root scope
153-
(macro one (function () (return '1)))
153+
(macro one (lambda () (return '1)))
154154

155-
(function ()
155+
(lambda ()
156156
; Redefine the macro in an inner scope
157-
(macro one (function () (return '1.1))) ; "very large value of 1"
157+
(macro one (lambda () (return '1.1))) ; "very large value of 1"
158158

159159
((. console log) (one)))
160160

@@ -173,7 +173,7 @@ nesting level.
173173

174174
<!-- !test in scoped macro masking -->
175175

176-
(macro ninja (function () (return `stealthMode))) ; define macro
176+
(macro ninja (lambda () (return `stealthMode))) ; define macro
177177
(if seriousBusiness ; in inner scope...
178178
(block (macro ninja) ; mask it
179179
(ninja))) ; function call
@@ -194,10 +194,10 @@ exist in a new, independent scope.
194194
<!-- !test in non-capturing macro -->
195195

196196
; Define a macro "ok".
197-
(macro ok (function () (return 'null)))
197+
(macro ok (lambda () (return 'null)))
198198

199199
; Define a non-capturing macro that expects "ok" not to be defined.
200-
(macro callOk (function (x)
200+
(macro callOk (lambda (x)
201201
(return `(ok)))) ; expects this to compile to calling a function "ok"
202202

203203
; Which it does, despite a macro "ok" being defined!
@@ -218,10 +218,10 @@ reset the macro environment.
218218
<!-- !test in capturing macro -->
219219

220220
; Define a macro "ok".C
221-
(macro ok (function () (return 'null)))
221+
(macro ok (lambda () (return 'null)))
222222

223223
; Define a capturing macro.
224-
(capmacro callOk (function (x)
224+
(capmacro callOk (lambda (x)
225225
(return `(ok)))) ; expects this to compile to calling the macro "ok"
226226
; (NOT the function "ok"!)
227227

@@ -262,7 +262,7 @@ call it with multiple arguments and return that.
262262
<!-- !test in increment twice -->
263263

264264
(macro incrementTwice
265-
(function (x) (return ((. this multi) `(++ ,x) `(++ ,x)))))
265+
(lambda (x) (return ((. this multi) `(++ ,x) `(++ ,x)))))
266266

267267
(incrementTwice hello)
268268

@@ -282,7 +282,7 @@ For example, you might want to pre-compute some expression.
282282
<!-- !test in precompute -->
283283

284284
(macro precompute
285-
(function (list) (return `,((. this evaluate) list))))
285+
(lambda (list) (return `,((. this evaluate) list))))
286286

287287
(precompute (+ 1 2 (* 5 (. Math PI))))
288288

@@ -309,7 +309,7 @@ shouldn't conflict with anything else.
309309

310310
; Generate the assignments needed to swap the values of two variables
311311
(macro swap
312-
(function (varA varB)
312+
(lambda (varA varB)
313313
(var swapVar ((. this gensym))) ; Generate a new symbol we can use
314314
(return ((. this multi)
315315

@@ -343,7 +343,7 @@ implicitly return the last thing in their bodies if it's an expression.
343343

344344
<!-- !test in implicit-return function -->
345345

346-
(macro fn (function ()
346+
(macro fn (lambda ()
347347
(var args ((. Array prototype slice call) arguments))
348348
(var fnArgs (. args 0))
349349
(var fnBody ((. args slice) 1))
@@ -358,7 +358,7 @@ implicitly return the last thing in their bodies if it's an expression.
358358
((. fnBody push) lastConverted) ; push the maybe-converted thing back on
359359

360360
; return the function definition
361-
(return `(function ,fnArgs ,@fnBody))))
361+
(return `(lambda ,fnArgs ,@fnBody))))
362362

363363
(fn (a b) (+ a b))
364364

0 commit comments

Comments
 (0)