Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / gist:2158055
Created March 22, 2012 12:30
lambda
(defun eval (e env)
(cond ((symbolp e) (cadr (assoc e env)))
((eql (car e) 'lambda) (cons e env))
(t (apply (eval (car e) env) (eval (cadr e) env)))))
(defun apply (f x)
(eval (cddr (car f)) (cons (list (cadr (car f)) x) (cdr f))))
;; CL-USER> (eval '(((lambda (f) (lambda (x) (f x))) (lambda (a) a)) (lambda (b) b)) '())
;; ((LAMBDA (B) B))
@osa1
osa1 / gist:2169083
Created March 23, 2012 09:45
sexp parser
module Parser where
import Text.ParserCombinators.Parsec hiding (token)
data Sexp = List [Sexp] | Atom String deriving (Show)
sexps :: Parser [Sexp]
sexps = sexp `sepBy` listSeparator
sexp :: Parser Sexp
@osa1
osa1 / gist:2358925
Created April 11, 2012 12:05
brainfuck interpreter
import Control.Monad
import Control.Monad.State
import Data.Array.Unboxed
import Data.Word
import Data.Char
import qualified Data.Map as M
import Data.Ix
data Bf = Bf { getArray :: UArray Int Word8
, getPointer :: Int
@osa1
osa1 / gist:2422883
Created April 19, 2012 18:34
DFA and NFA simulators
import Data.Map as M hiding (map)
import Data.Set as S hiding (map)
import Data.Maybe (catMaybes)
type State = Int
type Input = Char
data DFA = DFA { getEdges :: Map (State, Input) State
, getAcceptingStates :: Set State
}
@osa1
osa1 / gist:2439072
Created April 21, 2012 18:51
glapse patch to continue recording from last screenshot
--- /home/sinan/Downloads/glapse-0.3/glapseControllers/glapseMain.py 2011-06-24 19:16:45.000000000 +0300
+++ /home/sinan/opt/glapse/glapseControllers/glapseMain.py 2012-04-21 13:57:06.864076116 +0300
@@ -47,7 +47,6 @@
self.outputDir = output
self.quality = quality
self.interval = interval
- self.currentShot = 0
# Start a thread to take screenshots
self.done = False
{
module Main (main) where
import Control.Monad.IO.Class (liftIO)
}
%wrapper "monad"
$whitespace = [\ \b\t\n\f\v\r]
@osa1
osa1 / gist:2730819
Created May 19, 2012 13:13
hand-written lexer for EtuLang (a hypothetical PL for a PL course) in Haskell
{-# OPTIONS_GHC -Wall #-}
module Lexer where
import Prelude hiding (lex)
import Control.Monad.State
import qualified Data.Set as S
import Char (toLower)
data LexemeClass
= LLParen
@osa1
osa1 / gist:2757232
Created May 20, 2012 07:46
Lisp-style lazy-lists in Lua
function makeThunk(f, args)
return { tag = "thunk", f = f, args = args }
end
function evalThunk(t)
return t.f(unpack(t.args))
end
function cons(first, rest)
return { first = first,
@osa1
osa1 / target.ml
Created May 27, 2012 20:36
some tests for a lisp that compiles to OCaml
(type (tree a b)
Leaf
(Node (a (list b)) (tree a b) (tree a b)))
(type (maybe a)
Nothing
(Just a))
(define empty Leaf)
@osa1
osa1 / gist:2842455
Created May 31, 2012 10:18
wtf, TH
test.hs:20:8:
Couldn't match expected type `Parser
(MemoTable[a1AV] str0) str0 s0 t0'
with actual type `Language.Haskell.TH.Syntax.Q
Language.Haskell.TH.Syntax.Exp'
In the return type of a call of `Language.Haskell.TH.Syntax.lift'
In the expression: Language.Haskell.TH.Syntax.lift Nothing
In a case alternative:
Nothing -> Language.Haskell.TH.Syntax.lift Nothing