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
(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 cxy ([s] (cxy s 0 0)) | |
([[c & s] x y] | |
(cond | |
(nil? c) () | |
(= c \newline) (recur s 0 (inc y)) | |
:else (conj (cxy s (inc x) y) [c x y])))) |
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 P26 extends App { | |
def combinations[T](n: Int, l: List[T]): List[List[T]] = { | |
if(l.size < n) { | |
Nil | |
} else { | |
n match { | |
case 0 => Nil | |
case 1 => l.map{List(_)} | |
case _ => combinations(n-1,l.tail).map{ l.head :: _} ::: combinations(n, l.tail) | |
} |
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 & [f k] | |
(fn [& args] | |
(k (apply f args)))) | |
(defmacro cps [steps] | |
(if (seq steps) | |
`(& ~(first steps) | |
(cps ~(rest steps))) | |
`identity)) |
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 move [direction {:keys x y :as piece}] | |
(case direction | |
:down (assoc piece :y (inc y)) | |
:right (assoc piece :x (inc x)) | |
:left (assoc piece :x (dec x)) | |
:up (assoc piece :y (dec y)) | |
piece)) | |
(defn handle-input [k game-state] |
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
The Objective | |
This language experiment was designed to show how parametric polymorphism and type classes are | |
implemented in different languages. The implementation languages where chosen out of personal | |
preference. I am well aware it's not complete and would love for you to help me with that. If | |
you don't see your favorite language please add it as a comment. I am also not an expert in all | |
of these languages but did try to make them as idiomatic as possible. If you believe there is a | |
better solution please leave a comment with the implementation. | |
The Code |
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
package example | |
class Widget(val description : String) | |
class CoolWidget extends Widget("cool widget") | |
class Sprocket(val description : String) | |
object Sprocket { |
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
class Comparable a where | |
compareTo :: a -> a -> Int | |
intCompare :: Int -> Int -> Int | |
intCompare x y | |
| x < y = -1 | |
| x > y = 1 | |
| x == y = 0 | |
instance Comparable Int where |
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
class Monoid a where | |
append :: a -> a -> a | |
identity :: a | |
foldLeft :: [a] -> b -> (b -> a -> b) -> b | |
foldLeft [] x f = x | |
foldLeft (h:l) x f = foldLeft l (f x h) f | |
instance Monoid Int where |