Skip to content

Commit

Permalink
fix c[ad]+r when access nil + typececk
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 1, 2019
1 parent f55317f commit 53e08fd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* remove `nop` (you can use `(begin undefined)`)
### Bug fixes
* fix unquote-splicing on nil (e.g. processing of `` `(list ,@nil)``)
* cdr and car should return nil on empty list
* typecheck and process nil in c[ad]+r functions

## 0.11.1
### Bug fixes
Expand Down
26 changes: 25 additions & 1 deletion 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: Wed, 01 May 2019 10:23:31 +0000
* build: Wed, 01 May 2019 10:31:05 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -3381,12 +3381,30 @@ function _typeof(obj) {
}, "(cons left right)\n\n Function return new Pair out of two arguments."),
// ------------------------------------------------------------------
car: doc(function (list) {
if (list === nil) {
return nil;
}

typecheck('car', list, 'pair');

if (isEmptyList(list)) {
return nil;
}

return list.car;
}, "(car pair)\n\n Function returns car (head) of the list/pair."),
// ------------------------------------------------------------------
cdr: doc(function (list) {
if (list === nil) {
return nil;
}

typecheck('cdr', list, 'pair');

if (isEmptyList(list)) {
return nil;
}

return list.cdr;
}, "(cdr pair)\n\n Function returns cdr (tail) of the list/pair."),
// ------------------------------------------------------------------
Expand Down Expand Up @@ -4816,6 +4834,12 @@ function _typeof(obj) {
var name = 'c' + spec + 'r';
global_env.set(name, doc(function (arg) {
return chars.reduce(function (list, type) {
if (list === nil) {
return nil;
}

typecheck(name, list, 'pair');

if (type === 'a') {
return list.car;
} else {
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -2027,14 +2027,26 @@
Function return new Pair out of two arguments.`),
// ------------------------------------------------------------------
car: doc(function(list) {
if (list === nil) {
return nil;
}
typecheck('car', list, 'pair');
if (isEmptyList(list)) {
return nil;
}
return list.car;
}, `(car pair)
Function returns car (head) of the list/pair.`),
// ------------------------------------------------------------------
cdr: doc(function(list) {
if (list === nil) {
return nil;
}
typecheck('cdr', list, 'pair');
if (isEmptyList(list)) {
return nil;
}
return list.cdr;
}, `(cdr pair)
Expand Down Expand Up @@ -3513,6 +3525,10 @@
const name = 'c' + spec + 'r';
global_env.set(name, doc(function(arg) {
return chars.reduce(function(list, type) {
if (list === nil) {
return nil;
}
typecheck(name, list, 'pair');
if (type === 'a') {
return list.car;
} else {
Expand Down

0 comments on commit 53e08fd

Please sign in to comment.