Skip to content

Commit

Permalink
add base syntax-parameterize macro #210
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 26, 2024
1 parent c7c2e46 commit 242b47a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.18.1-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&c108344eaeb3ed7eb92e20d584e004cf)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&e8666578679e43d802ef1f3e4532bc35)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
29 changes: 25 additions & 4 deletions dist/lips.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

29 changes: 25 additions & 4 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions dist/lips.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -7848,6 +7848,26 @@ var global_env = new Environment({
and in the absence of syntax-parameterize, is functionally equivalent to
define-syntax.`),
// ------------------------------------------------------------------
'syntax-parameterize': doc(new Macro('syntax-parameterize', function(code, eval_args) {
const args = global_env.get('list->array')(code.car);
const env = this.inherit('syntax-parameterize');
while (args.length) {
const pair = args.shift();
if (!(is_pair(pair) || pair.car instanceof LSymbol)) {
const msg = `invalid syntax for syntax-parameterize: ${repr(code, true)}`;
throw new Error(`syntax-parameterize: ${msg}`);
}
const syntax = evaluate(pair.cdr.car, { ...eval_args, env: this });
typecheck('syntax-parameterize', syntax, 'syntax');
env.set(pair.car, new SyntaxParameter(syntax));
}
const body = new Pair(new LSymbol('begin'), code.cdr);
return evaluate(body, { ...eval_args, env });
}), `(syntax-parameterize (bindings) body)
Macro work similar to let-syntax but the the bindnds will be exposed to the user.
With syntax-parameterize you can define anaphoric macros.`),
// ------------------------------------------------------------------
define: doc(Macro.defmacro('define', function(code, eval_args) {
var env = this;
if (code.car instanceof Pair &&
Expand Down
10 changes: 10 additions & 0 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1382,3 +1382,13 @@
e.message))
(match #/^return used outside of a lambda\^/)))
#f)))

(test "syntax: should create syntax-rules binding with syntax-parameterize"
(lambda (t)
(syntax-parameterize
((it (syntax-rules ()
((_) "hello")))
(is (syntax-rules ()
((_) "world"))))
(t.is (string-append (it) " " (is))
"hello world"))))

0 comments on commit 242b47a

Please sign in to comment.