Skip to content

Commit

Permalink
fix lint errors + fix ++ and -- macros #34
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 17, 2020
1 parent 6fc3277 commit d4a20d1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [LIPS is Pretty Simple](https://jcubic.github.io/lips/) - Scheme based Powerful LISP

[![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&2c23c650b21dc3dc35c4b3b2f65b3dd22e2da643)](https://travis-ci.org/jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&6fc3277c82905f7e196388b4da49dc08b616b09c)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&2c48907438a7265935a7b21e6931008d)](https://coveralls.io/github/jcubic/lips?branch=devel)


Expand Down
25 changes: 12 additions & 13 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Sun, 17 May 2020 13:38:54 +0000
* build: Sun, 17 May 2020 13:58:14 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -5770,6 +5770,9 @@

return new LNumber(Math.sqrt(value));
}; // -------------------------------------------------------------------------
// if browser doesn't support ** it will not parse the code so we use
// Function constructor for test
// -------------------------------------------------------------------------


var pow = new Function('a,b', 'return a**b;');
Expand Down Expand Up @@ -8184,20 +8187,16 @@
return LNumber(number).sub(1);
}), "(1- number)\n\n Function substract 1 from the number and return result."),
// ------------------------------------------------------------------
'++': doc(new Macro('++', function (code) {
'++': doc(Macro.defmacro('++', function (code) {
typecheck('++', code.car, 'symbol');
var car = this.get(code.car);
var value = LNumber(car).add(1);
this.set(code.car, value);
return value;
typecheck('++', code.cdr, 'nil');
return Pair.fromArray([new LSymbol('set!'), code.car, [new LSymbol('+'), code.car, LNumber(1)]]);
}), "(++ variable)\n\n Macro that work only on variables and increment the value by one."),
// ------------------------------------------------------------------
'--': doc(new Macro('--', function (code) {
typecheck('--', code.car, 'symbol');
var car = this.get(code.car);
var value = LNumber(car).sub(1);
this.set(code.car, value);
return value;
typecheck('--', code.cdr, 'nil');
return Pair.fromArray([new LSymbol('set!'), code.car, [new LSymbol('-'), code.car, LNumber(1)]]);
}), "(-- variable)\n\n Macro that decrement the value it work only on symbols"),
// ------------------------------------------------------------------
'%': doc(function (a, b) {
Expand Down Expand Up @@ -9148,10 +9147,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Sun, 17 May 2020 13:38:54 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Sun, 17 May 2020 13:58:14 +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('Sun, 17 May 2020 13:38:54 +0000').valueOf();
var date = LString('Sun, 17 May 2020 13:58:14 +0000').valueOf();

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

Expand Down Expand Up @@ -9184,7 +9183,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Sun, 17 May 2020 13:38:54 +0000',
date: 'Sun, 17 May 2020 13:58:14 +0000',
exec: exec,
parse: parse,
tokenize: tokenize,
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -3754,12 +3754,15 @@
return new LNumber(Math.sqrt(value));
};
// -------------------------------------------------------------------------
// if browser doesn't support ** it will not parse the code so we use
// Function constructor for test
// -------------------------------------------------------------------------
var pow = new Function('a,b', 'return a**b;');
var power_operator_suported = (function() {
try {
pow(1,1);
pow(1, 1);
return true;
} catch(e) {
} catch (e) {
return false;
}
})();
Expand Down Expand Up @@ -6087,22 +6090,34 @@
Function substract 1 from the number and return result.`),
// ------------------------------------------------------------------
'++': doc(new Macro('++', function(code) {
'++': doc(Macro.defmacro('++', function(code) {
typecheck('++', code.car, 'symbol');
var car = this.get(code.car);
var value = LNumber(car).add(1);
this.set(code.car, value);
return value;
typecheck('++', code.cdr, 'nil');
return Pair.fromArray([
new LSymbol('set!'),
code.car,
[
new LSymbol('+'),
code.car,
LNumber(1)
]
]);
}), `(++ variable)
Macro that work only on variables and increment the value by one.`),
// ------------------------------------------------------------------
'--': doc(new Macro('--', function(code) {
typecheck('--', code.car, 'symbol');
var car = this.get(code.car);
var value = LNumber(car).sub(1);
this.set(code.car, value);
return value;
typecheck('--', code.cdr, 'nil');
return Pair.fromArray([
new LSymbol('set!'),
code.car,
[
new LSymbol('-'),
code.car,
LNumber(1)
]
]);
}), `(-- variable)
Macro that decrement the value it work only on symbols`),
Expand Down

0 comments on commit d4a20d1

Please sign in to comment.