Skip to content

Commit

Permalink
fix apply/mv macro from SRFI-210 #43
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 24, 2024
1 parent d1b1b14 commit 652a2ee
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 82 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&65a56cf63b108176824decb89b200164)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2d35c767c7b94ac5d36976f9dddc9d3a)](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
27 changes: 9 additions & 18 deletions dist/lips.cjs

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

27 changes: 9 additions & 18 deletions dist/lips.esm.js

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

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

Large diffs are not rendered by default.

27 changes: 9 additions & 18 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.

15 changes: 4 additions & 11 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -3573,15 +3573,7 @@ function extract_patterns(pattern, code, symbols, ellipsis_symbol, scope = {}) {
}
if (pattern instanceof LSymbol &&
symbols.includes(pattern.literal())) { // TODO: literal() may be SLOW
const ref = expansion.ref(code);
// shadowing the identifier works only with lambda and let
if (LSymbol.is(code, pattern)) {
if (typeof ref === 'undefined') {
return true;
}
return ref === define || ref === global_env;
}
return false;
return LSymbol.is(code, pattern);
}
// pattern (a b (x ...)) and (x ...) match nil
if (pattern instanceof Pair &&
Expand Down Expand Up @@ -3800,7 +3792,7 @@ function extract_patterns(pattern, code, symbols, ellipsis_symbol, scope = {}) {
}
log('recur');
if (traverse(pattern.car, code.car, pattern_names, ellipsis) &&
traverse(pattern.cdr, code.cdr, pattern_names, ellipsis)) {
traverse(pattern.cdr, code.cdr, pattern_names, ellipsis)) {
return true;
}
} else if (pattern === nil && (code === nil || code === undefined)) {
Expand Down Expand Up @@ -8136,6 +8128,8 @@ var global_env = new Environment({
validate_identifiers(macro.car);
}
const syntax = new Syntax(function(code, { macro_expand }) {
log('>> SYNTAX');
log(code);
const scope = env.inherit('syntax');
const dynamic_env = scope;
let var_scope = this;
Expand Down Expand Up @@ -8167,7 +8161,6 @@ var global_env = new Environment({
var bindings = extract_patterns(rule, code, symbols, ellipsis, {
expansion: this, define: env
});
log({bindings});
if (bindings) {
/* c8 ignore next 5 */
if (is_debug()) {
Expand Down
20 changes: 10 additions & 10 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,16 @@

(t.is (test) (list 'b 1 1 2))

(t.is (foo 1 ++ 2) (list 1 1 1 2))
(t.is (to.throw (let ((++ 10))
(foo 1 ++ 2)))
true)
(t.is (to.throw (let* ((++ 10))
(foo 1 ++ 2)))
true)
(t.is (to.throw ((lambda (++)
(foo 1 ++ 2)) 10))
true)))
(t.is (foo 1 ++ 2) '(1 1 1 2))
(t.is (let ((++ 10))
(foo 1 ++ 2))
'(1 1 1 2))
(t.is (let* ((++ 10))
(foo 1 ++ 2))
'(1 1 1 2))
(t.is ((lambda (++)
(foo 1 ++ 2)) 10)
'(1 1 1 2))))

(test "syntax: scope with rewriting"
(lambda (t)
Expand Down

0 comments on commit 652a2ee

Please sign in to comment.