Skip to content

Commit

Permalink
fxi quasiquote macro #14
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 13, 2019
1 parent 236dbdc commit e3f02f0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
### Bug fixes
* fix white space in docs for macros
* fix two cases in parser: `` `(,(list 1 2)) `` and `` `(+ ,,(list 'foo)) `` [#12](https://github.com/jcubic/lips/issues/12)

* fix quaisquote macro (eval of single unquote in double quasiquote) [#14](https://github.com/jcubic/lips/issues/14)

## 0.12.0
### Features
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## LIPS is Pretty Simple

[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&beea1c49847762f1c3b2018d94676f3b737bab0c)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&eabd750484ab61985caf654a864d4680)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&236dbdc38d30d76402de548ee76098fc17ca4691)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&326fe9079b144d4545c8e3672990bc0e)](https://coveralls.io/github/jcubic/lips?branch=devel)


LIPS is very simple Lisp, similar to Scheme written in JavaScript.
Expand Down
8 changes: 6 additions & 2 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* http://javascript.nwbox.com/ContentLoaded/
* http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
*
* build: Thu, 09 May 2019 12:02:13 +0000
* build: Mon, 13 May 2019 08:47:51 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -4021,7 +4021,7 @@ function _typeof(obj) {
var dynamic_scope = _ref16.dynamic_scope,
error = _ref16.error;
var self = this;
var max_unquote = 0;
var max_unquote = 1;

if (dynamic_scope) {
dynamic_scope = self;
Expand Down Expand Up @@ -4103,6 +4103,10 @@ function _typeof(obj) {
});
}

if (_Symbol.is(pair.car, 'quasiquote')) {
max_unquote++;
}

if (_Symbol.is(pair.car, 'unquote')) {
var head = pair.cdr;
var node = head;
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions spec/lips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ describe('parser', function() {
it('should create quasiquote list from literals', function() {
testQuasituote('(quasiquote (list (unquote-splicing (list))))', true);
});
it('should unquote from single quasiquote', function() {
lips.exec("`(let ((name 'x)) `(let ((name 'y)) `(list ',name)))").then(function(result) {
expect(result[0].toString()).toEqual(
['(let ((name (quote x)))',
'(quasiquote (let ((name (quote y)))',
'(quasiquote (list (quote (unquote name)))))))'].join(' ')
);
});
});
it('should use reader macros', function() {
testQuasituote('`(list ,@(list))');
});
Expand Down
5 changes: 4 additions & 1 deletion src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@
// ------------------------------------------------------------------
quasiquote: doc(new Macro('quasiquote', function(arg, { dynamic_scope, error }) {
var self = this;
var max_unquote = 0;
var max_unquote = 1;
if (dynamic_scope) {
dynamic_scope = self;
}
Expand Down Expand Up @@ -2663,6 +2663,9 @@
return unpromise(value, value => join(eval_pair, value));
});
}
if (Symbol.is(pair.car, 'quasiquote')) {
max_unquote++;
}
if (Symbol.is(pair.car, 'unquote')) {
var head = pair.cdr;
var node = head;
Expand Down

0 comments on commit e3f02f0

Please sign in to comment.