Skip to content

Commit

Permalink
fix map #21 + refactor read function in node REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Dec 1, 2019
1 parent 9f22a26 commit c980210
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.17.1
### Bug fixes
* fix map last value [#21](https://github.com/jcubic/lips/issues/21)

## 0.17.0
### Features
* revert breaking change of read to return Array
Expand Down
6 changes: 3 additions & 3 deletions README.md
@@ -1,8 +1,8 @@
## LIPS is Pretty Simple

[![npm](https://img.shields.io/badge/npm-0.17.0-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=master&095cfbd62a0b195e609d12d598047aa67bcd4723)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&8710db161df0ca3500520bda08815b5e)](https://coveralls.io/github/jcubic/lips?branch=master)
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&9f22a2615145274042e35c5e2ecec2d0338980f4)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&8710db161df0ca3500520bda08815b5e)](https://coveralls.io/github/jcubic/lips?branch=devel)


LIPS is very simple Lisp, similar to Scheme written in JavaScript.
Expand Down
52 changes: 19 additions & 33 deletions bin/lips.js
Expand Up @@ -108,18 +108,8 @@ if (options.c) {
var e = env.inherit('name', {
stdin: {
read: function() {
return new Promise(function(done) {
rl.resume();
code = '';
if (process.stdin.isTTY) {
rl.setPrompt('');
}
resolve = function() {
done(code);
code = '';
rl.setPrompt(prompt);
resolve = null;
};
return new Promise(function(resolve) {
rl.question('', resolve);
});
}
}
Expand All @@ -128,29 +118,25 @@ if (options.c) {
code += line;
if (balanced_parenthesis(code)) {
rl.pause();
if (resolve) {
resolve();
} else {
run(code, e).then(function(result) {
if (process.stdin.isTTY) {
print(result);
if (multiline) {
rl.setPrompt(prompt);
}
code = '';
rl.prompt();
}
rl.resume();
}).catch(function() {
if (process.stdin.isTTY) {
if (multiline) {
rl.setPrompt(prompt);
}
rl.prompt();
run(code, e).then(function(result) {
if (process.stdin.isTTY) {
print(result);
if (multiline) {
rl.setPrompt(prompt);
}
code = '';
});
}
rl.prompt();
}
rl.resume();
}).catch(function() {
if (process.stdin.isTTY) {
if (multiline) {
rl.setPrompt(prompt);
}
rl.prompt();
}
code = '';
});
} else {
multiline = true;
var i = indent(code, 2, prompt.length - continuePrompt.length);
Expand Down
12 changes: 8 additions & 4 deletions dist/lips.js
@@ -1,5 +1,5 @@
/**@license
* LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.17.0
* LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. DEV
*
* Copyright (c) 2018-2019 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
Expand All @@ -24,7 +24,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Sun, 01 Dec 2019 19:31:34 +0000
* build: Sun, 01 Dec 2019 20:21:46 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -4859,8 +4859,12 @@
});

if (lists.some(function (x) {
return isEmptyList(x);
return x === nil;
})) {
return nil;
}

if (lists.some(isEmptyList)) {
return emptyList();
}

Expand Down Expand Up @@ -5867,7 +5871,7 @@
Environment.__className = 'Environment'; // -------------------------------------------------------------------------

var lips = {
version: '0.17.0',
version: 'DEV',
exec: exec,
parse: parse,
tokenize: tokenize,
Expand Down
6 changes: 3 additions & 3 deletions dist/lips.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/lips.js
Expand Up @@ -3433,7 +3433,10 @@
lists.forEach((arg, i) => {
typecheck('map', arg, ['pair', 'nil'], i + 1);
});
if (lists.some((x) => isEmptyList(x))) {
if (lists.some(x => x === nil)) {
return nil;
}
if (lists.some(isEmptyList)) {
return emptyList();
}
return unpromise(fn.call(this, ...lists.map(l => l.car)), (head) => {
Expand Down

0 comments on commit c980210

Please sign in to comment.