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
-- Fixed point registers | |
data Rx = R0 | R1 | R2 | R3 | R4 | R5 | R6 | R7 deriving (Show, Eq, Ord) | |
-- Floating point registers | |
data Fx = F0 | F1 | F2 | F3 | F4 | F5 | F6 | F7 deriving (Show, Eq, Ord) | |
data Expr :: * -> * where | |
AddI :: Rx -> Rx -> Expr Integer | |
SubI :: Rx -> Rx -> Expr Integer | |
AddF :: Fx -> Fx -> Expr Float | |
SubF :: Fx -> Fx -> Expr Float |
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
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Monad (void) | |
import Ivory.Language | |
import Ivory.Compile.C.CmdlineFrontend | |
import Ivory.Compile.C.Modules |
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
var comments = [ | |
{author: "Pete Hunt", text: "This is a text"}, | |
{author: "Suvash", text: "This is *another* comment"} | |
]; | |
// Data is local to components, | |
// passed down from the parent | |
// this.props - immutable |
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
-- Arne Andersson - Balanced Search Trees Made Simple | |
-- Original article: http://user.it.uu.se/~arnea/ps/simp.pdf | |
-- Wikipedia entry: http://en.wikipedia.org/wiki/AA_tree | |
data AATree a = E | T a (AATree a) (AATree a) Int deriving (Show, Eq) | |
insert E x = T x E E 1 | |
insert (T y left right level) x | |
| x < y = balance $ T y (insert left x) right level | |
| otherwise = balance $ T y left (insert right x) level |
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 om-table.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true])) | |
(enable-console-print!) | |
(extend-type string | |
ICloneable | |
(-clone [n] (js/String. n))) | |
(def app-state (atom {:table ["very" "undefined" "such" "parentNode"]})) |
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
;; Updated tutorial code for Om 0.1.6, 2014-01-16 | |
;; http://www.lexicallyscoped.com/2013/12/25/slice-of-reactjs-and-cljs.html | |
;; See comments below for details on the changes. | |
(def app-state | |
(atom {:comments [{:author "Pete Hunt" :text "This is a comment."} | |
{:author "Jordan Walke" :text "This is *another* coment"}]})) | |
(defn comment [{:keys [author text]} owner] | |
(om/component |
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
f x = (42-x)^2 | |
impr = [(x, f x) | x <- [0, 0.1 ..]] | |
opt goal = head $ dropWhile (\(x, err) -> err >= goal) impr |
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 book [state owner] | |
(prn state) | |
(om/component | |
(dom/div nil (dom/h2 nil (:author state))))) | |
;;=> | |
{:author "Richard K. Morgan", :book "Altered Carbon"} core.cljs:55 | |
Uncaught TypeError: Cannot read property 'string' of undefined core.cljs:110 | |
;; Manual creation of a cursor giving the same behaviour | |
;; Inserted this snippet inside an om/component |
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
(loop [foo (seq []) | |
bar [1 2 3]] | |
(if (empty? bar) | |
foo | |
(recur (conj foo (first bar)) (next bar)))) |
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
rows = 3 | |
glasses = [ | |
0.0, | |
0.0, 0.0, | |
0.0, 0.0, 0.0, | |
0.0, 0.0, 0.0, 0.0 ] | |
def index(i, j): | |
"ith glass in the jth row" | |
return i + sum(range(1, j+1)) | |
def dist(v, i, j): |