Skip to content

Instantly share code, notes, and snippets.

View michiakig's full-sized avatar

aki michiakig

  • Rent the Runway
  • Brooklyn, NY
View GitHub Profile
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@michiakig
michiakig / three.cljs
Created August 19, 2011 20:53
three.js demo in ClojureScript
(ns three.demo)
(def camera (THREE.Camera. 75 (/ window/innerWidth
window/innerHeight) 1 10000))
(set! (.z (.position camera)) 1000)
(def scene (THREE.Scene.))
(def geometry (THREE.CubeGeometry. 200 200 200))
(def obj (js/Object.))
(set! (.color obj) 0xff0000)
(set! (.wireframe obj) true)
(def material (THREE.MeshBasicMaterial. obj))
import java.util.List;
import java.util.ArrayList;
/*
* Lexical analyzer for Scheme-like minilanguage:
* (define (foo x) (bar (baz x)))
*/
public class Lexer {
public static enum Type {
// This Scheme-like language has three token types:
signature POSITIONAL_STREAM =
sig
type elem
type stream
val peek : stream -> (elem * stream) option
val getPos : stream -> pos
end
structure SubstringStream : STREAM =
type 'a monoid = {zero : 'a; plus : 'a -> 'a -> 'a}
let sum (m : 'a monoid) (l : 'a list) : 'a = List.fold_left m.plus m.zero l
let string_summer = sum {zero = ""; plus = (^)}
let int_summer = sum {zero = 0; plus = (+)}
#lang eopl
;(module lang (lib "eopl.ss" "eopl")
(require "drscheme-init.scm")
(provide (all-defined))
;;;;;;;;;;;;;;;; grammatical specification ;;;;;;;;;;;;;;;;
(define the-lexical-spec
utahraptor:~ aki$ rlwrap ocaml
Objective Caml version 3.12.1
# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#!/usr/bin/emacs --script
(princ (format "batch mode: %s\n" noninteractive))
(defun ext (cmd args)
(with-temp-buffer
(let ((exit (funcall 'call-process cmd nil (current-buffer) nil args)))
(cons exit (buffer-substring (point-min) (point-max))))))
(defun deep-rev (list)
(if (or (null list) (not (listp list))) list
(reverse (mapcar 'deep-rev list))))