Skip to content

Commit

Permalink
merge with devel
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed May 13, 2018
2 parents ccb60fa + c18f5ad commit c3d1e00
Show file tree
Hide file tree
Showing 10 changed files with 918 additions and 174 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ npm-debug.log
.\#*
.DEV
.[0-9]*
www
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.4.0
### Features
* lambda with reset parameter (like in scheme)
* new functions: 1+, 1-, curry and range
* execute LIPS code from script tag with text-x/lips type attribute
* add string functions: join, split, replace, match, search
* new second parameter to `tokenize` that make it return array of extra objects `{token, col, line, offset}`
* Pair.flatten and lips function flatten

### Bugs
* fix (reduce + list)
* fix handling of empty list
* make let* handle promises
* fix evaluate of macro that return a Promise
* fix evaluating code with promises

## 0.3.0
### Features
* exec api method
Expand Down
18 changes: 14 additions & 4 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-0.3.0-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&75a8e908f71d1893396db68780c9a21f88ff392c)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&a6562124b6b8df22c67398db686aa9f0)](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/jquery.terminal.svg?branch=devel&2dc94aa1484e56f5566d4c09b9f3ed51ace31d72)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&a6562124b6b8df22c67398db686aa9f0)](https://coveralls.io/github/jcubic/lips?branch=devel)


LIPS is very simple Lisp, similar to Scheme written in JavaScript.
Expand All @@ -26,7 +26,7 @@ https://unpkg.com/@jcubic/lips
or from rawgit

```
https://cdn.rawgit.com/jcubic/lips/master/dist/lips.min.js
https://cdn.rawgit.com/jcubic/lips/devel/dist/lips.min.js
```

## Usage
Expand Down Expand Up @@ -65,6 +65,16 @@ First argument is an object with functions, macros and varibles (see Extending L
Second argument is parent environment, you need to use global environment (or other that extend global)
otherwise you will not have any functions.

You can also use script tag to execute LIPS code:

```html
<script type="text-x/lips">
(let ((what "world")
(greet "hello"))
(print (concat "hello" " " what)))
</script>
```

## License

Released under [MIT](http://opensource.org/licenses/MIT) license
Expand Down
65 changes: 58 additions & 7 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
if (term.hasClass('terminal')) {
$.terminal.active().error(message);
} else {
$('body').terminal(function() {
window.term = $('body').terminal(function() {
this.error('You need to use modern browser');
}, {
greetings: greetings
greetings: false
}).error(message);
}
};
Expand Down Expand Up @@ -61,13 +61,12 @@
}
}
}, global_environment);
env.set('replace', function(re, sub, string) {
return string.replace(re, sub);
});
env.set('quote-car', new Macro(function(code) {
return Pair.fromArray([new Symbol('quote'), code.car.car]);
}));
var term = $('body').terminal(function(code, term) {
var position;
var timer;
window.term = $('body').terminal(function(code, term) {
if (!balanced_parenthesis(code)) {
term.error('Unbalanced parenthesis');
} else {
Expand All @@ -90,8 +89,60 @@
}
}, {
name: 'lips',
greetings: greetings
greetings: false,
// below is the code for parenthesis matching (jumping)
keydown: function() {
if (position) {
term.set_position(position);
position = false;
}
},
keypress: function(e) {
var term = this;
if (e.key == ')') {
setTimeout(function() {
position = term.get_position();
var command = term.get_command();
var len = command.split(/\n/)[0].length;
var tokens = tokenize(command, true);
var count = 1;
var token;
var i = tokens.length - 1;
while (count > 0) {
token = tokens[--i];
if (!token) {
return;
}
if (token.token === '(') {
count--;
} else if (token.token == ')') {
count++;
}
}
if (token.token == '(') {
clearTimeout(timer);
setTimeout(function() {
term.set_position(token.offset);
timer = setTimeout(function() {
term.set_position(position)
position = false;
}, 200);
}, 0);
}
}, 0);
} else {
position = false;
}
}
});
})();
</script>
<script type="text-x/lips">
;; Example of LIPS in script tag
(load "greetings.lips")
(let* ((res (fetch "greetings.lips"))
(text ((. res "text")))
(log (. console "log")))
(log text))
</script>
</html>
Loading

0 comments on commit c3d1e00

Please sign in to comment.