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
(defn charx [[ch str] idx] | |
(if ch | |
(conj [ch idx] (charx str (inc idx))) | |
()) | |
(defn charxy | |
([str] (charxy (.spit str "\n") 0) | |
([[s1 rst] idx] | |
(if s1 | |
(concat (map (concat % [idx]) (charx s1)) (charxy rst (inc idx))) |
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
(defn modal-show | |
"displays a modal window" | |
[] | |
(chainable-standard | |
(fn [node] | |
(.modal node "show")))) | |
; Note: chainable-standard is a base wrapper that | |
; in enfocus.core that enables you to work with all | |
; other transforms |
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
(defrecord Tree [left elm right]) | |
(defprotocol Monoid | |
(append [a b] ) | |
(identity [a] )) | |
(defprotocol Foldable | |
(foldl [l f i]) | |
(mfirst [l])) | |
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
object Lambda extends App { | |
val number = (num: Int) => (env: Map[Symbol, Int]) => num | |
val variable = (id: Symbol) => (env: Map[Symbol, Int]) => env(id) | |
val add = (a: (Map[Symbol, Int]) => Int, b: (Map[Symbol, Int]) => Int ) => (env: Map[Symbol, Int]) => a(env) + b(env) | |
val multiply = (a: (Map[Symbol, Int]) => Int, b: (Map[Symbol, Int]) => Int ) => (env: Map[Symbol, Int]) => a(env) * b(env) | |
val environment = Map('a -> 1, 'b -> 2, 'c -> 3) | |
val expr_tree = add(variable('a), multiply(number(2), variable('b))) | |
println(expr_tree(environment)) |
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
Number = lambda { |env, num| num } | |
Variable = lambda { |env, var| env[var] } | |
Add = lambda { |env, a, b| evaluate(env, a) + evaluate(env, b) } | |
Multiply = lambda { |env, a, b| evaluate(env, a) * evaluate(env, b) } | |
def evaluate(env, exp) | |
op, *args = exp | |
op.(env, *args) | |
end |
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
┌───┬────────────┬──────────────────────────────────┐ | |
│Add│┌────────┬─┐│┌────────┬──────────┬────────────┐│ | |
│ ││Variable│a│││Multiply│┌──────┬─┐│┌────────┬─┐││ | |
│ │└────────┴─┘││ ││Number│2│││Variable│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
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
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
;you have a map with a key :action | |
;this contains a known list of actions: | |
;:login, :register, :play, :logout | |
(defmulti appy-action :action) | |
;input looks like this | |
;{:action :login :username "test" :password "test"} | |
(defmethod apply-action :login [msg] | |
(let [username (:username msg) |
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 goog-test.core | |
(:require [goog.testing.jsunit :as unit] | |
[goog.testing :as gt] | |
[goog.testing.TestCase :as tc]) | |
(:use [midje.cljs.core :only [run-test]]) | |
(:use-macros [midje.cljs.semi-sweet :only [expect fact run-tests]] | |
[midje.cljs.sweet :only [fact provided]])) | |
(defn world [] "world") | |
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 midje.cljs.basic) | |
(defn doubler [x] (* 2 x)) | |
(defn world [] "world") | |
(defn hello [] | |
(str "hello " (world))) |