Skip to content

Instantly share code, notes, and snippets.

View jlongster's full-sized avatar
💭
Workin on my app

James Long jlongster

💭
Workin on my app
View GitHub Profile
@jlongster
jlongster / gist:1584594
Created January 9, 2012 19:51
multi-term config
(require 'multi-term)
(setq multi-term-program "/bin/zsh")
(global-set-key (kbd "<f8>") 'multi-term)
(setq term-bind-key-alist
`(("M-d" . term-send-forward-kill-word)
("M-DEL" . term-send-backward-kill-word)
("C-c" . term-interrupt-subjob)
("M-v" . term-send-raw)
("C-y" . term-paste)
@jlongster
jlongster / gist:1595376
Created January 11, 2012 16:08
example of js raw output
(define (foo arr)
(js "console.log(arr.length);"))
->
var foo = function(arr){
return console.log(arr.length);}
;
@jlongster
jlongster / gist:1651726
Created January 21, 2012 06:37
Macros
;; AST style:
((equal? term "cond")
(define (transform i)
(if (or (> i node.children.length)
(eq? i node.children.length))
null
(let ((n (vector-ref node.children i)))
(let ((condition (vector-ref n.children 0))
(res (ast.node ast.LIST
@jlongster
jlongster / gist:1712455
Created January 31, 2012 19:37
traditional lisp macros
;; outlet code for implementing traditional macro expansion
;; macros
(define (expand form)
(cond
((variable? form) form)
((literal? form) form)
((macro? (car form))
(expand ((macro-function (car form)) form)))
@jlongster
jlongster / gist:1712468
Created January 31, 2012 19:39
eps macros
;; outlet code for implementing EPS macros (http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.4332)
;; expanders
(define _expanders_ {})
(define (expander-function name)
(ref _expanders_ (symbol->string name)))
(define (install-expander name func)
@jlongster
jlongster / gist:1840230
Created February 16, 2012 00:03
tracing Outlet code
(trace-source (let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4)))))
;; Output
(let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4))))
-- (+ 4 5)
>> RESULT: 9
@jlongster
jlongster / gist:1876901
Created February 21, 2012 14:46
shadowing identical variables in javascript
var x = 1;
function foo() {
var x = x + 2;
console.log(x); // prints NaN
}
function bar() {
var x = x;
console.log(x); // prints undefined
@jlongster
jlongster / gist:1979842
Created March 5, 2012 17:50
Outlet meta-circular evaluator
;; Requires Outlet to run: https://github.com/jlongster/outlet
;;
;; Run with: `ol main.ol <input-file>`
;;
;; This is a meta-circular evaluator for a basic Lisp. It is
;; mostly taken from SICP 4.1*. I wanted to see if I could write a
;; debugger with it. Turns out if I want control over control flow I
;; need a register-based interpreter.
;;
;; * http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1
@jlongster
jlongster / gist:2038485
Created March 14, 2012 18:29
explicit control evaluator in the outlet VM
((goto (label eval-exp))
eval-dispatch
(test (op self-evaluating?) (reg exp))
(branch (label ev-self-eval))
(test (op variable?) (reg exp))
(branch (label ev-variable))
(test (op quoted?) (reg exp))
(branch (label ev-quoted))
(test (op assignment?) (reg exp))
@jlongster
jlongster / gist:2317603
Created April 6, 2012 06:29
LiSP Ch. 1
;; outlet: https://github.com/jlongster/outlet
(define-macro (case c . variants)
`(cond
,@(map (lambda (exp)
(if (== (car exp) 'else)
exp
`((list-find ',(car exp) ,c)
,@(cdr exp))))
variants)))