Skip to content

Commit

Permalink
Merge pull request #186 from shawwn/2018-08-25/hd
Browse files Browse the repository at this point in the history
Define HD?
  • Loading branch information
Scott Bell authored Aug 29, 2018
2 parents 4652dcb + 3e5a06e commit 47573b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
23 changes: 13 additions & 10 deletions bin/lumen.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ obj63 = function (x) {
atom63 = function (x) {
return nil63(x) || string63(x) || number63(x) || boolean63(x);
};
hd63 = function (l, x) {
return obj63(l) && hd(l) === x;
};
nan = 0 / 0;
inf = 1 / 0;
_inf = - inf;
Expand Down Expand Up @@ -188,13 +191,13 @@ reduce = function (f, x) {
};
join = function () {
var __ls = unstash(Array.prototype.slice.call(arguments, 0));
var __r37 = [];
var __r38 = [];
var ____x1 = __ls;
var ____i4 = 0;
while (____i4 < _35(____x1)) {
var __l11 = ____x1[____i4];
if (__l11) {
var __n3 = _35(__r37);
var __n3 = _35(__r38);
var ____o2 = __l11;
var __k4 = undefined;
for (__k4 in ____o2) {
Expand All @@ -209,12 +212,12 @@ join = function () {
if (number63(__k5)) {
__k5 = __k5 + __n3;
}
__r37[__k5] = __v2;
__r38[__k5] = __v2;
}
}
____i4 = ____i4 + 1;
}
return __r37;
return __r38;
};
find = function (f, t) {
var ____o3 = t;
Expand Down Expand Up @@ -671,16 +674,16 @@ apply = function (f, args) {
return f.apply(f, __args);
};
call = function (f) {
var ____r74 = unstash(Array.prototype.slice.call(arguments, 1));
var __f = destash33(f, ____r74);
var ____id = ____r74;
var ____r75 = unstash(Array.prototype.slice.call(arguments, 1));
var __f = destash33(f, ____r75);
var ____id = ____r75;
var __args11 = cut(____id, 0);
return apply(__f, __args11);
};
setenv = function (k) {
var ____r75 = unstash(Array.prototype.slice.call(arguments, 1));
var __k18 = destash33(k, ____r75);
var ____id1 = ____r75;
var ____r76 = unstash(Array.prototype.slice.call(arguments, 1));
var __k18 = destash33(k, ____r76);
var ____id1 = ____r76;
var __keys = cut(____id1, 0);
if (string63(__k18)) {
var __e19;
Expand Down
23 changes: 13 additions & 10 deletions bin/lumen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ end
function atom63(x)
return nil63(x) or string63(x) or number63(x) or boolean63(x)
end
function hd63(l, x)
return obj63(l) and hd(l) == x
end
nan = 0 / 0
inf = 1 / 0
_inf = - inf
Expand Down Expand Up @@ -174,26 +177,26 @@ function reduce(f, x)
end
function join(...)
local __ls = unstash({...})
local __r36 = {}
local __r37 = {}
local ____x2 = __ls
local ____i4 = 0
while ____i4 < _35(____x2) do
local __l11 = ____x2[____i4 + 1]
if __l11 then
local __n3 = _35(__r36)
local __n3 = _35(__r37)
local ____o2 = __l11
local __k2 = nil
for __k2 in next, ____o2 do
local __v2 = ____o2[__k2]
if number63(__k2) then
__k2 = __k2 + __n3
end
__r36[__k2] = __v2
__r37[__k2] = __v2
end
end
____i4 = ____i4 + 1
end
return __r36
return __r37
end
function find(f, t)
local ____o3 = t
Expand Down Expand Up @@ -579,16 +582,16 @@ function apply(f, args)
return f(values(__args))
end
function call(f, ...)
local ____r71 = unstash({...})
local __f = destash33(f, ____r71)
local ____id = ____r71
local ____r72 = unstash({...})
local __f = destash33(f, ____r72)
local ____id = ____r72
local __args11 = cut(____id, 0)
return apply(__f, __args11)
end
function setenv(k, ...)
local ____r72 = unstash({...})
local __k9 = destash33(k, ____r72)
local ____id1 = ____r72
local ____r73 = unstash({...})
local __k9 = destash33(k, ____r73)
local ____id1 = ____r73
local __keys = cut(____id1, 0)
if string63(__k9) then
local __e8
Expand Down
3 changes: 3 additions & 0 deletions runtime.l
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
(define-global atom? (x)
(or (nil? x) (string? x) (number? x) (boolean? x)))

(define-global hd? (l x)
(and (obj? l) (= (hd l) x)))

(define-global nan (/ 0 0))
(define-global inf (/ 1 0))
(define-global -inf (- inf))
Expand Down
6 changes: 6 additions & 0 deletions test.l
Original file line number Diff line number Diff line change
Expand Up @@ -1089,4 +1089,10 @@ c"
(f 1 'x g)
(test= (list 'x g) l)))

(define-test hd?
(test= true (hd? '(%if 1 2) '%if))
(test= false (hd? '((%if) 1 2) '(%if)))
(test= false (hd? 42 '%if))
(test= true (hd? '() nil)))

(run)

0 comments on commit 47573b1

Please sign in to comment.