diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index c196eec6..c7549d51 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -1059,9 +1059,16 @@ (quote hs-method-call) (cons obj (cons method args)))) (if - (and (list? dot-node) (= (first dot-node) (quote ref))) - (list (quote hs-win-call) (nth dot-node 1) (cons (quote list) args)) - (cons (quote hs-method-call) (cons (hs-to-sx dot-node) args)))))) + (and + (list? dot-node) + (= (first dot-node) (quote ref))) + (list + (quote hs-win-call) + (nth dot-node 1) + (cons (quote list) args)) + (cons + (quote hs-method-call) + (cons (hs-to-sx dot-node) args)))))) ((= head (quote string-postfix)) (list (quote str) (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote block-literal)) @@ -1231,7 +1238,12 @@ (list (quote hs-coerce) (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote in?)) (list - (quote hs-contains?) + (quote hs-in?) + (hs-to-sx (nth ast 2)) + (hs-to-sx (nth ast 1)))) + ((= head (quote in-bool?)) + (list + (quote hs-in-bool?) (hs-to-sx (nth ast 2)) (hs-to-sx (nth ast 1)))) ((= head (quote of)) @@ -1717,7 +1729,16 @@ (rest (reverse compiled))) (let ((defs (filter (fn (c) (and (list? c) (> (len c) 0) (= (first c) (quote define)))) compiled)) - (non-defs (filter (fn (c) (not (and (list? c) (> (len c) 0) (= (first c) (quote define))))) compiled))) + (non-defs + (filter + (fn + (c) + (not + (and + (list? c) + (> (len c) 0) + (= (first c) (quote define))))) + compiled))) (cons (quote do) (append defs non-defs))))))) ((= head (quote wait)) (list (quote hs-wait) (nth ast 1))) ((= head (quote wait-for)) (emit-wait-for ast)) @@ -1826,8 +1847,12 @@ (make-symbol raw-fn) (hs-to-sx raw-fn))) (args (map hs-to-sx (rest (rest ast))))) - (if (and (list? raw-fn) (= (first raw-fn) (quote ref))) - (list (quote hs-win-call) (nth raw-fn 1) (cons (quote list) args)) + (if + (and (list? raw-fn) (= (first raw-fn) (quote ref))) + (list + (quote hs-win-call) + (nth raw-fn 1) + (cons (quote list) args)) (cons fn-expr args)))) ((= head (quote return)) (let @@ -2098,7 +2123,7 @@ (hs-to-sx (nth ast 1))))) ((= head (quote in?)) (list - (quote hs-contains?) + (quote hs-in?) (hs-to-sx (nth ast 2)) (hs-to-sx (nth ast 1)))) ((= head (quote type-check)) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index d01289a5..0c337953 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -495,7 +495,8 @@ (quote and) (list (quote >=) left lo) (list (quote <=) left hi))))) - ((match-kw "in") (list (quote in?) left (parse-expr))) + ((match-kw "in") + (list (quote in-bool?) left (parse-expr))) ((match-kw "really") (do (match-kw "equal") @@ -571,7 +572,8 @@ (let ((right (parse-expr))) (list (quote not) (list (quote =) left right)))))) - ((match-kw "in") (list (quote in?) left (parse-expr))) + ((match-kw "in") + (list (quote in-bool?) left (parse-expr))) ((match-kw "empty") (list (quote empty?) left)) ((match-kw "between") (let diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 78dea311..4daa71d9 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -1535,6 +1535,25 @@ (hs-contains? (rest collection) item)))))) (true false)))) +(define + hs-in? + (fn + (collection item) + (cond + ((nil? collection) (list)) + ((list? collection) + (cond + ((nil? item) (list)) + ((list? item) + (filter (fn (x) (hs-contains? collection x)) item)) + ((hs-contains? collection item) (list item)) + (true (list)))) + (true (list))))) + +(define + hs-in-bool? + (fn (collection item) (not (hs-falsy? (hs-in? collection item))))) + (define hs-is (fn diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index c196eec6..c7549d51 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -1059,9 +1059,16 @@ (quote hs-method-call) (cons obj (cons method args)))) (if - (and (list? dot-node) (= (first dot-node) (quote ref))) - (list (quote hs-win-call) (nth dot-node 1) (cons (quote list) args)) - (cons (quote hs-method-call) (cons (hs-to-sx dot-node) args)))))) + (and + (list? dot-node) + (= (first dot-node) (quote ref))) + (list + (quote hs-win-call) + (nth dot-node 1) + (cons (quote list) args)) + (cons + (quote hs-method-call) + (cons (hs-to-sx dot-node) args)))))) ((= head (quote string-postfix)) (list (quote str) (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote block-literal)) @@ -1231,7 +1238,12 @@ (list (quote hs-coerce) (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote in?)) (list - (quote hs-contains?) + (quote hs-in?) + (hs-to-sx (nth ast 2)) + (hs-to-sx (nth ast 1)))) + ((= head (quote in-bool?)) + (list + (quote hs-in-bool?) (hs-to-sx (nth ast 2)) (hs-to-sx (nth ast 1)))) ((= head (quote of)) @@ -1717,7 +1729,16 @@ (rest (reverse compiled))) (let ((defs (filter (fn (c) (and (list? c) (> (len c) 0) (= (first c) (quote define)))) compiled)) - (non-defs (filter (fn (c) (not (and (list? c) (> (len c) 0) (= (first c) (quote define))))) compiled))) + (non-defs + (filter + (fn + (c) + (not + (and + (list? c) + (> (len c) 0) + (= (first c) (quote define))))) + compiled))) (cons (quote do) (append defs non-defs))))))) ((= head (quote wait)) (list (quote hs-wait) (nth ast 1))) ((= head (quote wait-for)) (emit-wait-for ast)) @@ -1826,8 +1847,12 @@ (make-symbol raw-fn) (hs-to-sx raw-fn))) (args (map hs-to-sx (rest (rest ast))))) - (if (and (list? raw-fn) (= (first raw-fn) (quote ref))) - (list (quote hs-win-call) (nth raw-fn 1) (cons (quote list) args)) + (if + (and (list? raw-fn) (= (first raw-fn) (quote ref))) + (list + (quote hs-win-call) + (nth raw-fn 1) + (cons (quote list) args)) (cons fn-expr args)))) ((= head (quote return)) (let @@ -2098,7 +2123,7 @@ (hs-to-sx (nth ast 1))))) ((= head (quote in?)) (list - (quote hs-contains?) + (quote hs-in?) (hs-to-sx (nth ast 2)) (hs-to-sx (nth ast 1)))) ((= head (quote type-check)) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index d01289a5..0c337953 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -495,7 +495,8 @@ (quote and) (list (quote >=) left lo) (list (quote <=) left hi))))) - ((match-kw "in") (list (quote in?) left (parse-expr))) + ((match-kw "in") + (list (quote in-bool?) left (parse-expr))) ((match-kw "really") (do (match-kw "equal") @@ -571,7 +572,8 @@ (let ((right (parse-expr))) (list (quote not) (list (quote =) left right)))))) - ((match-kw "in") (list (quote in?) left (parse-expr))) + ((match-kw "in") + (list (quote in-bool?) left (parse-expr))) ((match-kw "empty") (list (quote empty?) left)) ((match-kw "between") (let diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index 78dea311..4daa71d9 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -1535,6 +1535,25 @@ (hs-contains? (rest collection) item)))))) (true false)))) +(define + hs-in? + (fn + (collection item) + (cond + ((nil? collection) (list)) + ((list? collection) + (cond + ((nil? item) (list)) + ((list? item) + (filter (fn (x) (hs-contains? collection x)) item)) + ((hs-contains? collection item) (list item)) + (true (list)))) + (true (list))))) + +(define + hs-in-bool? + (fn (collection item) (not (hs-falsy? (hs-in? collection item))))) + (define hs-is (fn