Skip to content

Commit

Permalink
fix quasiquote to work like quote if not unquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Dec 11, 2020
1 parent d30bbea commit 04531f9
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* fix indent of `when` and `unless`
* fix usage of Drag&Drop with bookmarklet on pdf files
* fix accessing methods on pattern variables in syntax macros [#83](https://github.com/jcubic/lips/issues/83)
* fix quasiquote to work like quote if not unquotes (R7RS spec)

## 1.0.0-beta.9
### Breaking
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.9-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)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&f4c70220f0c8012205287f7905d8c9419af3fd8c)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&dc7415e662dd94d1eece69acbbc25b6f)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&d30bbeafec9b7579edd7323c25c498d95ffc1910)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&4ad2a0cc51eda574815b5c09cef1fa86)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
[![GitHub license](https://img.shields.io/github/license/jcubic/lips.svg)](https://github.com/jcubic/lips/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/jcubic/lips.svg?style=social&label=Star&maxAge=2592000)](https://github.com/jcubic/lips/stargazers/)
Expand Down
37 changes: 33 additions & 4 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Fri, 11 Dec 2020 14:00:49 +0000
* build: Fri, 11 Dec 2020 14:51:12 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -3459,6 +3459,31 @@
}; // ----------------------------------------------------------------------


Pair.prototype.find = function (item) {
var car;

if (this.car instanceof Pair && this.car.find(item)) {
car = true;
} else if (this.car instanceof LSymbol) {
car = LSymbol.is(this.car, item);
}

var cdr;

if (this.cdr instanceof Pair && this.cdr.find(item)) {
cdr = true;
} else if (this.cdr instanceof LSymbol) {
cdr = LSymbol.is(this.cdr, item);
}

if (cdr || car) {
return true;
}

return false;
}; // ----------------------------------------------------------------------


Pair.prototype.clone = function () {
var visited = new Map();

Expand Down Expand Up @@ -9886,6 +9911,10 @@
}
}

if (arg.car instanceof Pair && !arg.car.find('unquote') && !arg.car.find('unquote-splicing') && !arg.car.find('quasiquote')) {
return quote(arg.car);
}

var x = recur(arg.car, 0, 1);
return unpromise(x, function (value) {
// clear nested data for tests
Expand Down Expand Up @@ -11922,10 +11951,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Fri, 11 Dec 2020 14:00:49 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Fri, 11 Dec 2020 14:51:12 +0000' == '{{' + 'DATE}}'; can be removed
// but disablig Tree-shaking is adding lot of not used code so we use this
// hack instead
var date = LString('Fri, 11 Dec 2020 14:00:49 +0000').valueOf();
var date = LString('Fri, 11 Dec 2020 14:51:12 +0000').valueOf();

var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date);

Expand Down Expand Up @@ -11962,7 +11991,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Fri, 11 Dec 2020 14:00:49 +0000',
date: 'Fri, 11 Dec 2020 14:51:12 +0000',
exec: exec,
// unwrap async generator into Promise<Array>
parse: compose(uniterate_async, parse),
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/R7RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,4 @@
(set! found #t))))))
#f))

;; -----------------------------------------------------------------------------
;; -----------------------------------------------------------------------------
26 changes: 26 additions & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,26 @@
return len;
};

// ----------------------------------------------------------------------
Pair.prototype.find = function(item) {
var car;
if (this.car instanceof Pair && this.car.find(item)) {
car = true;
} else if (this.car instanceof LSymbol) {
car = LSymbol.is(this.car, item);
}
var cdr;
if (this.cdr instanceof Pair && this.cdr.find(item)) {
cdr = true;
} else if (this.cdr instanceof LSymbol) {
cdr = LSymbol.is(this.cdr, item);
}
if (cdr || car) {
return true;
}
return false;
};

// ----------------------------------------------------------------------
Pair.prototype.clone = function() {
var visited = new Map();
Expand Down Expand Up @@ -6654,6 +6674,12 @@
}
}
}
if (arg.car instanceof Pair &&
!arg.car.find('unquote') &&
!arg.car.find('unquote-splicing') &&
!arg.car.find('quasiquote')) {
return quote(arg.car);
}
var x = recur(arg.car, 0, 1);
return unpromise(x, value => {
// clear nested data for tests
Expand Down
28 changes: 28 additions & 0 deletions tests/quotation.scm
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,31 @@
#e#o7
#\x
#\newline))))

(test "quote: should be constant"
(lambda (t)

(define (foo)
'(1 2))

(t.is (eq? (foo) (foo)) true)))

(test "quasiquote: should be constant"
(lambda (t)

(define (foo)
`(1 2))

(t.is (eq? (foo) (foo)) true)))

(test "quasiquote: should create new pair"
(lambda (t)
(define (foo x)
`(1 2 ,@x))

(t.is (eq? (foo '(1)) (foo '(2))) false)

(define (foo x)
`(1 2 ,x))

(t.is (eq? (foo 10) (foo 20)) false)))

0 comments on commit 04531f9

Please sign in to comment.