Skip to content

Commit 8a8ae52

Browse files
update errors on macro uLisp guides
1 parent 35d8069 commit 8a8ae52

File tree

7 files changed

+103
-31
lines changed

7 files changed

+103
-31
lines changed

docs/drafts/pages/lifeviewer-test.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/drafts/pages/testpage.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pages/ulisp_howto/backquote.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pages/ulisp_howto/macros.html

Lines changed: 44 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

markdown/pages/ulisp_howto/backquote.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The backquote special form and its reader-macro version are incredibly useful in
4242

4343
object* process_backquote (object* arg, size_t level = 0) {
4444
// "If ast is a map or a symbol, return a list containing: the "quote" symbol, then ast."
45-
if (arg == NULL || atom(arg)) return quoteit(QUOTE, arg);
45+
if (arg == NULL || atom(arg)) return quote(arg);
4646
// "If ast is a list starting with the "unquote" symbol, return its second element."
4747
if (listp(arg) && symbolp(first(arg))) {
4848
switch (builtin(first(arg)->name)) {

markdown/pages/ulisp_howto/macros.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,41 @@ Title: Adding Macros to uLisp
22

33
The Lisp form `:::lisp defmacro` allows for more powerful syntactic constructs. Note that this does not include backquote support -- there is a [separate page]({filename}backquote.md) for that.
44

5-
*EDIT: In response to [all of the confusion](http://forum.ulisp.com/t/what-would-you-like-to-see-in-ulisp-in-2024/1350/36) I seem to have caused by posting this error-ridden guide, I have done my best to correct all of the errors. Hopefully, now it should be possible to to directly follow this guide from a vanilla uLisp to be able to add macros. I apologize for any confusion, compiler problems, and crashes caused by my sloppiness.*
5+
*EDIT Feb. 28: In response to [all of the confusion](http://forum.ulisp.com/t/what-would-you-like-to-see-in-ulisp-in-2024/1350/36) I seem to have caused by posting this error-ridden guide, I have done my best to correct all of the errors. Hopefully, now it should be possible to to directly follow this guide from a vanilla uLisp to be able to add macros. I apologize for any confusion, compiler problems, and crashes caused by my sloppiness.*
6+
7+
*EDIT Nov. 24: again, corrected some more errors... my sincerest apologies for this undue insanity!*
68

79
## Part 1 - the Functions
810

9-
1. Add these functions and their table entries:
11+
1. Add the `MACRO` sentinel symbol, right after `LAMBDA` in the table and builtins:
12+
13+
```cpp
14+
const char stringmacro[] = "macro";
15+
```
16+
17+
```cpp
18+
const char docmacro[] = "(macro (parameter*) form*)\n"
19+
"Creates an unnamed lambda-macro with parameters. The body is evaluated with the parameters as local variables\n"
20+
"whose initial values are defined by the values of the forms after the macro form;\n"
21+
"the resultant Lisp code returned is then evaluated again, this time in the scope of where the macro was called.";
22+
```
23+
24+
```{.cpp data-line="2"}
25+
{ string8, NULL, 0017, doc8 }, // string8 should be "lambda"
26+
{ stringmacro, NULL, 0017, docmacro },
27+
{ string9, NULL, 0017, doc9 },
28+
```
29+
30+
```{.cpp data-line="4"}
31+
enum builtins: builtin_t { NIL, TEE, NOTHING, OPTIONAL,
32+
FEATURES, INITIALELEMENT, ELEMENTTYPE,
33+
TEST, EQ, BIT, AMPREST, LAMBDA,
34+
MACRO,
35+
LET, LETSTAR,
36+
/* rest of them omitted for brevity */ }
37+
```
38+
39+
2. Add these functions and their table entries:
1040

1141
```cpp
1242
bool is_macro_call (object* form, object* env) {
@@ -56,31 +86,43 @@ The Lisp form `:::lisp defmacro` allows for more powerful syntactic constructs.
5686
object* fn_macroexpand (object* args, object* env) {
5787
return macroexpand(first(args), env);
5888
}
89+
90+
object* sp_defmacro (object* args, object* env) {
91+
(void) env;
92+
object* var = first(args);
93+
if (!symbolp(var)) error(notasymbol, var);
94+
object* val = cons(bsymbol(MACRO), cdr(args));
95+
object* pair = value(var->name, GlobalEnv);
96+
if (pair != NULL) cdr(pair) = val;
97+
else push(cons(var, val), GlobalEnv);
98+
return var;
99+
}
59100
```
60101

61102
```cpp
62-
const char stringbackquote[] PROGMEM = "backquote";
63-
const char stringunquote[] PROGMEM = "unquote";
64-
const char stringuqsplicing[] PROGMEM = "unquote-splicing";
103+
const char stringdefmacro[] = "defmacro";
104+
const char stringmacroexpand1[] = "macroexpand-1";
105+
const char stringmacroexpand[] = "macroexpand";
65106
```
66107

67108
```cpp
68-
const char docmacro[] PROGMEM = "(macro (parameter*) form*)\n"
69-
"Creates an unnamed lambda-macro with parameters. The body is evaluated with the parameters as local variables\n"
70-
"whose initial values are defined by the values of the forms after the macro form;\n"
71-
"the resultant Lisp code returned is then evaluated again, this time in the scope of where the macro was called.";
72109
const char docdefmacro[] PROGMEM = "(defmacro name (parameters) form*)\n"
73-
"Defines a syntactic macro.";
110+
"Defines a syntactic macro. No attempt is made to make it a "
111+
"hygienic macro.";
112+
const char docmacroexpand1[] = "(macroexpand-1 'form)\n"
113+
"If the form represents a call to a macro, expands the macro once and returns the expanded code.";
114+
const char docmacroexpand[] = "(macroexpand 'form)\n"
115+
"Repeatedly applies (macroexpand-1) until the form no longer represents a call to a macro,\n"
116+
"then returns the new form.";
74117
```
75118

76119
```cpp
77-
{ stringmacro, NULL, 0017, docmacro },
78120
{ stringdefmacro, sp_defmacro, 0327, docdefmacro },
79121
{ stringmacroexpand1, fn_macroexpand1, 0111, docmacroexpand1 },
80122
{ stringmacroexpand, fn_macroexpand, 0111, docmacroexpand },
81123
```
82124

83-
2. Wire up the evaluator to expand the macros:
125+
3. Wire up the evaluator to expand the macros:
84126

85127
```{.cpp data-line="6"}
86128
// in object* eval (object* form, object* env)

pelicantheme

0 commit comments

Comments
 (0)