This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; derived from http://blog.fikesfarm.com/posts/2015-12-12-clojurescript-macro-functions.html | |
| (ns dual-world | |
| #?(:cljs (:require-macros [dual-world :refer [add]]))) | |
| #?(:clj (defmacro add [& xs] `(+ ~@xs 0.1)) | |
| :cljs (defn add [& xs] (apply + xs))) | |
| (add 1 2) | |
| #?(:cljs (apply add 1 2 [])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns utils.km-light | |
| (:refer-clojure :exclude [get]) | |
| (:require [utils.core :as u] | |
| [utils.check :as uc] | |
| [cljs.core :as c])) | |
| (declare km? kset? kset->km normalize) | |
| (defn catv [a b] | |
| (vec (concat a b))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (inc nil) ;=> 1 | |
| (update {} :a not) ;=> {:a true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns shorts | |
| (:refer-clojure :exclude [cat]) | |
| (:require [clojure.core :as c])) | |
| ;; short-circuiting application | |
| ;; in this model when a function receive a nil argument it returns nil | |
| ;; in addition we can make predicates return their first argument in case of success or nil otherwise | |
| ;; we will call this 'guards' | |
| ;; ex: (pos? x) returns x only if x is positive else returns nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; impl --------------------------------------------------- | |
| traverse: func [x f /only /deep dive?][ | |
| until [ | |
| x: case [ | |
| all [deep dive? x/1] [traverse/deep x/1 :f :dive? next x] | |
| all [not deep not only series? x/1] [traverse/deep x/1 :f :series? next x] | |
| 'else [f x] | |
| ] | |
| tail? x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [ | |
| Description: "a rule for rules" | |
| ] | |
| rules: [rule '| rules | rule [end | rules]] | |
| rule: [ | |
| m: | |
| block! :m into rules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Red [] | |
| ;; https://gist.github.com/hiiamboris/5f85edba139fc88a5eb0ee9b7b30bc6b | |
| arity?: function [p [word! path!]] [ | |
| either word? p [ | |
| preprocessor/func-arity? spec-of get :p | |
| ][ | |
| ; path format: obj1/obj2.../func/ref1/ref2... | |
| ; have to find a point where in that path a function starts | |
| ; i.e. p2: obj1/obj2.../func |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (do | |
| (require '[clojure.core.logic :as l]) | |
| (require '[clojure.core.logic.fd :as fd]) | |
| (defn zip+o [l1 l2 l3] | |
| (l/conde | |
| [(l/== () l1) (l/== () l2) (l/== () l3)] | |
| [(l/fresh [fl1 rl1 fl2 rl2 fl3 rl3] | |
| (l/conso fl1 rl1 l1) | |
| (l/conso fl2 rl2 l2) | |
| (l/conso fl3 rl3 l3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (letfn [(merge-in* [a b] | |
| (if (map? a) | |
| (merge-with merge-in* a b) | |
| b))] | |
| (defn merge-in | |
| "Merge multiple nested maps." | |
| [& args] | |
| (reduce merge-in* nil args))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns exp.destruct | |
| (:refer-clojure :exclude [destructure])) | |
| (defprotocol IDestructure | |
| (-destructure [this data])) | |
| (extend-protocol IDestructure | |
| clojure.lang.PersistentVector | |
| (-destructure [this data] |