Skip to content

Instantly share code, notes, and snippets.

View rizo's full-sized avatar

Rizo I rizo

  • London (UK), Porto (Portugal)
View GitHub Profile
@cqfd
cqfd / uniques.ml
Created April 23, 2011 22:07
OCaml implementation of a nub function
let rec elem x xs =
match xs with
| [] -> false
| y :: ys -> x = y || elem x ys
let rec uniques l =
let rec helper l acc =
match l with
| [] -> acc
| x :: xs ->
@qerub
qerub / gist:969308
Created May 12, 2011 19:53
Objective-R: Objective-C-like syntax for method calls in Racket
#lang racket ; Requires Racket >= 5.1.1
(provide (rename-out (objective-r-read read)
(objective-r-read-syntax read-syntax)))
(require syntax/stx)
(define (rewrite-method-calls stx)
(if (stx-list? stx)
(let ((stx* (stx-map rewrite-method-calls stx)))
@NicolasT
NicolasT / zipper.ml
Created October 14, 2011 10:25
List zipper in OCaml
# Untested!
type 'a zipper = Zip of 'a list * 'a list
let empty = Zip ([], [])
let from_list l = Zip ([], l)
let to_list (Zip (ls, rs)) = List.rev ls @ rs
let at_begin = function
| Zip ([], _) -> true
| _ -> false
@chadselph
chadselph / patternmatching.py
Last active February 15, 2024 14:45
Functional language style pattern matching in python with a decorator
from collections import defaultdict
class BadMatch(NameError):
"""Exception when your args don't match a pattern"""
pass
class Any(object):
"""
>>> 'wutup' == Any()
True
@ckirkendall
ckirkendall / clojure-match.clj
Created June 15, 2012 02:26 — forked from bkyrlach/Expression.fs
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
(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})
@sekati
sekati / xcode-build-bump.sh
Created July 24, 2012 20:44
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
@lambda-fairy
lambda-fairy / gist:3445830
Last active October 9, 2015 05:27
Aqua programming language

TODO

  • Exceptions
  • Delimited continuations, because continuations are cool.
  • Macros (maybe)
  • Attribute lookup – lenses?
  • Keyword parameters
    • [GHC implicit parameters][] are interesting
@NicolasT
NicolasT / delimcc.ml
Created September 26, 2012 18:23
Delimited Continuations in OCaml
(* Boilerplate *)
(* Identity: id :: a -> a *)
let id = fun x -> x
(* Function composition: (.) :: (b -> c) -> (a -> b) -> a -> c *)
let (<.>) (f : 'b -> 'c) (g : 'a -> 'b) : 'a -> 'c =
fun x -> f (g x)
(* Cont type *)
type ('w, 'a) cont = Cont of (('a -> 'w) -> 'w)
@mlin
mlin / netclient_https_threads.ml
Created November 27, 2012 02:39
Attempting multithreaded https requests using ocamlnet netclient
(*
ocamlfind ocamlopt -o netclient_https_threads -thread -linkpkg -package threads,netclient,ssl,equeue-ssl netclient_https_threads.ml
http://docs.camlcity.org/docs/godipkg/3.12/godi-ocamlnet/doc/godi-ocamlnet/html/Https_client.html
*)
open Printf
module HTTP = Http_client
module HTTPS = Https_client
;;
// http://rentzsch.tumblr.com/post/40806448108/ns-poor-mans-namespacing-for-objective-c
#ifndef NS
#ifdef NS_NAMESPACE
#define JRNS_CONCAT_TOKENS(a,b) a##_##b
#define JRNS_EVALUATE(a,b) JRNS_CONCAT_TOKENS(a,b)
#define NS(original_name) JRNS_EVALUATE(NS_NAMESPACE, original_name)
#else
#define NS(original_name) original_name
#endif
#endif