Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ move hash and statement from core to macros ]

  • Loading branch information...
commit 5cc29c21b96b36958ea280370491e35552ea22cb 1 parent de285d7
@jbr authored
Showing with 23 additions and 110 deletions.
  1. +2 −42 lib/browser.js
  2. +17 −0 lib/macros.lisp
  3. +2 −42 lib/sibilant.js
  4. +2 −26 src/core.lisp
View
44 lib/browser.js
@@ -289,13 +289,6 @@
};
})();
});
- macros.statement = (function(args) {
- // args:rest
- var args = Array.prototype.slice.call(arguments, 0);
-
- return (macros.call.apply(undefined, args) + ";\n");
- });
-
macros.progn = (function(body) {
// body:rest
var body = Array.prototype.slice.call(arguments, 0);
@@ -376,17 +369,6 @@
return args;
});
- macros.reverse = (function(arr) {
- // arr:required
- var reversed = [ ];;
- arr.forEach((function(item) {
- // item:required
- return reversed.unshift(item);
- }));
- return reversed;
- });
-
- var reverse = macros.reverse;
var buildArgsString = (function(args, rest) {
// args:required rest:required
var argsString = "",
@@ -468,11 +450,11 @@
macros.quote = (function(item) {
// item:required
return (function() {
- if (("Array" === item.constructor.name)) {
+ if ((item) && (item).constructor.name === "Array") {
return ("[ " + (map(item, macros.quote)).join(", ") + " ]");
} else {
return (function() {
- if (("number" === typeof(item))) {
+ if (typeof(item) === 'number') {
return item;
} else {
return ("\"" + literal(item) + "\"");
@@ -482,28 +464,6 @@
})();
});
- macros.hash = (function(pairs) {
- // pairs:rest
- var pairs = Array.prototype.slice.call(arguments, 0);
-
- (function() {
- if ((0 !== (pairs.length % 2))) {
- return error(("odd number of key-value pairs in hash: " + inspect(pairs)));
- };
- })();
- var pairStrings = bulkMap(pairs, (function(key, value) {
- // key:required value:required
- return (translate(key) + ": " + translate(value));
- }));;
- return (function() {
- if ((1 >= pairStrings.length)) {
- return ("{ " + (pairStrings).join(", ") + " }");
- } else {
- return ("{" + indent((pairStrings).join(",\n")) + "}");
- };
- })();
- });
-
var literal = (function(string) {
// string:required
return inject(string // chain
View
17 lib/macros.lisp
@@ -78,6 +78,9 @@
(defmacro apply (fn arglist)
(macros.send fn 'apply 'undefined arglist))
+(defmacro statement (&rest args)
+ (concat (apply macros.call args) ";\n"))
+
(defmacro zero? (item)
((get macros "=") (translate item) 0))
@@ -283,6 +286,20 @@
(macros.delmacro current-macro-name)
"")
+(defmacro hash (&rest pairs)
+ (when (odd? pairs.length)
+ (error (concat
+ "odd number of key-value pairs in hash: "
+ (call inspect pairs))))
+ (defvar pair-strings
+ (bulk-map pairs (lambda (key value)
+ (concat (translate key) ": "
+ (translate value)))))
+ (if (>= 1 pair-strings.length)
+ (concat "{ " (join ", " pair-strings) " }")
+ (concat "{" (indent (join ",\n" pair-strings)) "}")))
+
+
(defmacro defhash (name &rest pairs)
(macros.defvar name (apply macros.hash pairs)))
View
44 lib/sibilant.js
@@ -182,13 +182,6 @@ var macros = { };
};
})();
});
-macros.statement = (function(args) {
- // args:rest
- var args = Array.prototype.slice.call(arguments, 0);
-
- return (macros.call.apply(undefined, args) + ";\n");
-});
-
macros.progn = (function(body) {
// body:rest
var body = Array.prototype.slice.call(arguments, 0);
@@ -269,17 +262,6 @@ var transformArgs = (function(arglist) {
return args;
});
-macros.reverse = (function(arr) {
- // arr:required
- var reversed = [ ];;
- arr.forEach((function(item) {
- // item:required
- return reversed.unshift(item);
- }));
- return reversed;
-});
-
-var reverse = macros.reverse;
var buildArgsString = (function(args, rest) {
// args:required rest:required
var argsString = "",
@@ -361,11 +343,11 @@ macros.lambda = (function(arglist, body) {
macros.quote = (function(item) {
// item:required
return (function() {
- if (("Array" === item.constructor.name)) {
+ if ((item) && (item).constructor.name === "Array") {
return ("[ " + (map(item, macros.quote)).join(", ") + " ]");
} else {
return (function() {
- if (("number" === typeof(item))) {
+ if (typeof(item) === 'number') {
return item;
} else {
return ("\"" + literal(item) + "\"");
@@ -375,28 +357,6 @@ macros.quote = (function(item) {
})();
});
-macros.hash = (function(pairs) {
- // pairs:rest
- var pairs = Array.prototype.slice.call(arguments, 0);
-
- (function() {
- if ((0 !== (pairs.length % 2))) {
- return error(("odd number of key-value pairs in hash: " + inspect(pairs)));
- };
- })();
- var pairStrings = bulkMap(pairs, (function(key, value) {
- // key:required value:required
- return (translate(key) + ": " + translate(value));
- }));;
- return (function() {
- if ((1 >= pairStrings.length)) {
- return ("{ " + (pairStrings).join(", ") + " }");
- } else {
- return ("{" + indent((pairStrings).join(",\n")) + "}");
- };
- })();
-});
-
var literal = (function(string) {
// string:required
return inject(string // chain
View
28 src/core.lisp
@@ -132,9 +132,6 @@
default-return)))
-(defun macros.statement (&rest args)
- (concat (apply macros.call args) ";\n"))
-
(defun macros.progn (&rest body)
(defvar last-index (-math.max 0 (- body.length 1)))
@@ -181,13 +178,6 @@
args)
-(defun macros.reverse (arr)
- (defvar reversed [])
- (each (item) arr (reversed.unshift item))
- reversed)
-
-(defvar reverse macros.reverse)
-
(defun build-args-string (args rest)
(defvar args-string ""
optional-count 0)
@@ -263,25 +253,11 @@
(defun macros.quote (item)
- (if (= "Array" item.constructor.name)
+ (if (array? item)
(concat "[ " (join ", " (map item macros.quote)) " ]")
- (if (= 'number (typeof item)) item
+ (if (number? item) item
(concat "\"" (literal item) "\""))))
-(defun macros.hash (&rest pairs)
- (when (odd? pairs.length)
- (error (concat
- "odd number of key-value pairs in hash: "
- (call inspect pairs))))
- (defvar pair-strings
- (bulk-map pairs (lambda (key value)
- (concat (translate key) ": "
- (translate value)))))
- (if (>= 1 pair-strings.length)
- (concat "{ " (join ", " pair-strings) " }")
- (concat "{" (indent (join ",\n" pair-strings)) "}")))
-
-
(defun literal (string)
(inject (chain string
(replace /\*/g "_")

0 comments on commit 5cc29c2

Please sign in to comment.
Something went wrong with that request. Please try again.