Browse files

Initial Commit

  • Loading branch information...
0 parents commit 85f89b6b5fe45eac4b85da843d48ce89a85c3438 @ajlopez committed Mar 24, 2012
Showing with 237 additions and 0 deletions.
  1. +23 −0 LICENSE
  2. +23 −0 LICENSE~
  3. +5 −0 README.md
  4. +10 −0 README.md~
  5. BIN lib/.ajlogo.js.swp
  6. +60 −0 lib/ajlogo.js
  7. +60 −0 lib/ajlogo.js~
  8. +28 −0 test/test.js
  9. +28 −0 test/test.js~
23 LICENSE
@@ -0,0 +1,23 @@
+
+Copyright (C) 2012, Angel J Lopez
+http://www.ajlopez.com
+http://ajlopez.wordpress.com
+http://twitter.com/ajlopez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
23 LICENSE~
@@ -0,0 +1,23 @@
+
+Copyright (C) 2008-2012, Angel J Lopez
+http://www.ajlopez.com
+http://ajlopez.wordpress.com
+http://twitter.com/ajlopez
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
5 README.md
@@ -0,0 +1,5 @@
+# AjLogoJs
+
+Logo interpreter written in Javascript, using TDD (Node assert).
+
+
10 README.md~
@@ -0,0 +1,10 @@
+# AjLispJs
+
+Lisp interpreter written in Javascript, using TDD (QUnit).
+
+Posts:
+
+[AjLisp in Javascript (Part 1) Atoms, Lists and TDD](http://ajlopez.wordpress.com/2011/08/19/ajlisp-in-javascript-part-1-atoms-lists-and-tdd/)
+
+[AjLisp in Javascript (Part 2) List Evaluation, Forms and Special Forms](http://ajlopez.wordpress.com/2011/08/30/ajlisp-in-javascript-part-1-list-evaluation-form-and-special-forms/)
+
BIN lib/.ajlogo.js.swp
Binary file not shown.
60 lib/ajlogo.js
@@ -0,0 +1,60 @@
+
+(function(exports)
+{
+ function Context()
+ {
+
+ }
+
+ Context.prototype.set = function(name, value)
+ {
+ this[name] = value;
+ }
+
+ Context.prototype.get = function(name)
+ {
+ return this[name];
+ }
+
+ function List(first, rest)
+ {
+ this.first = first;
+ this.rest = rest;
+ }
+
+ Array.prototype.evaluate = function(context)
+ {
+ var func = this.evaluateFirst(context);
+ var args = this.evaluateRest(context);
+ if (func.apply)
+ return func.apply(null, args);
+ return args.unshift(func);
+ }
+
+ Array.prototype.evaluateFirst = function(context)
+ {
+ var first = this[0];
+ if (first.evaluate)
+ return first.evaluate(context);
+ return first;
+ }
+
+ Array.prototype.evaluateRest = function(context)
+ {
+ var l = this.length;
+
+ if (l < 2)
+ return null;
+
+ var result = new Array(l-1);
+
+ for (var k = 1; k < l ; k++)
+ result[k-1] = this[k].evaluate ? this[k].evaluate(context) : this[k];
+
+ return result;
+ }
+
+ exports.Context = Context;
+ exports.List = List;
+
+})(typeof exports == "undefined" ? this['ajlogo'] = {} : exports);
60 lib/ajlogo.js~
@@ -0,0 +1,60 @@
+
+(function(exports)
+{
+ function Context()
+ {
+
+ }
+
+ Context.prototype.set = function(name, value)
+ {
+ this[name] = value;
+ }
+
+ Context.prototype.get = function(name)
+ {
+ return this[name];
+ }
+
+ function List(first, rest)
+ {
+ this.first = first;
+ this.rest = rest;
+ }
+
+ Array.prototype.evaluate = function(context)
+ {
+ var func = this.evaluateFirst(context);
+ var args = this.evaluateRest(context);
+ if (func.apply)
+ return func.apply(null, args));
+ return args.unshift(func);
+ }
+
+ Array.prototype.evaluateFirst = function(context)
+ {
+ var first = this[0];
+ if (first.evaluate)
+ return first.evaluate(context);
+ return first;
+ }
+
+ Array.prototype.evaluateRest = function(context)
+ {
+ var l = this.length;
+
+ if (l < 2)
+ return null;
+
+ var result = new Array(l-1);
+
+ for (var k = 1; k < l ; k++)
+ result[k-1] = this[k].evaluate ? this[k].evaluate(context) : this[k];
+
+ return result;
+ }
+
+ exports.Context = Context;
+ exports.List = List;
+
+})(typeof exports == "undefined" ? this['ajlogo'] = {} : exports);
28 test/test.js
@@ -0,0 +1,28 @@
+
+var assert = require('assert');
+var ajlogo = require('../lib/ajlogo.js');
+
+
+// Context
+
+var ctx = new ajlogo.Context();
+
+assert.ok(ctx);
+
+assert.equal(null, ctx.get('foo'));
+
+ctx.set('foo', 'bar');
+assert.equal('bar', ctx.get('foo'));
+
+var list = new ajlogo.List(1, null);
+assert.equal(1, list.first);
+assert.equal(null, list.rest);
+
+ctx.set('add', function(x, y) { return x + y; });
+
+var add = ctx.get('add');
+
+var array = [add, 2, 3];
+
+assert.equal(5, array.evaluate(ctx));
+
28 test/test.js~
@@ -0,0 +1,28 @@
+
+var assert = require('assert');
+var ajlogo = require('../lib/ajlogo.js');
+
+
+// Context
+
+var ctx = new ajlogo.Context();
+
+assert.ok(ctx);
+
+assert.equal(null, ctx.get('foo'));
+
+ctx.set('foo', 'bar');
+assert.equal('bar', ctx.get('foo'));
+
+var list = new ajlogo.List(1, null);
+assert.equal(1, list.first);
+assert.equal(null, list.rest);
+
+ctx.set('add', function(x, y) { return x + y; });
+
+var add = ctx.get('add');
+
+var array = [add, [2, 3]];
+
+assert.equal(5, array.evaluate(ctx));
+

0 comments on commit 85f89b6

Please sign in to comment.