Skip to content

Instantly share code, notes, and snippets.

@delihiros
delihiros / lisp.scm
Created December 15, 2011 16:28
pure lisp written in Gauche
#!/opt/local/bin/gosh
(define (myeval exp env)
(cond ((atom? exp)
(if (number? exp)
exp
(assoc* exp env)))
((eq? (car exp) 'quote:) (cadr exp))
(else (myapply (car exp)
(eval-args (cdr exp) env) env))))
(setq indent-tabs-mode nil)
(setq load-path
(append
(list
(expand-file-name "~/emacssetup")
)
load-path))
(require 'mac-key-mode)
(mac-key-mode 1)
(define foo
(lambda (n lst)
(if (zero? n) '()
(cons (cons n lst) (foo (- n 1) lst)))))
;; MIT Scheme
;; (foo 4 '(4))
;; ==> ((4 4) (3 4) (2 4) (1 4))
;; Gauche (and my env)
#include <iostream>
#include <cstdlib>
using namespace std;
int data[5001];
int main(){
for (int i = 0; i < 5001; i++) data[i] = 0;
int buf;
-- Sxyz -> xz yz
-- Kxy -> x
-- Ix -> x
data Combinator = S | K | I | E
deriving (Show, Eq)
char2ski :: Char -> Combinator
char2ski c = case c of
'S' -> S
-- Sxyz -> xz yz
-- Kxy -> x
-- Ix -> x
data Combinator = S | K | I | E
deriving (Show, Eq)
char2ski :: Char -> Combinator
char2ski c = case c of
'S' -> S
(define sum
(lambda (lst)
(if (null? lst)
0
(+ (car lst) (sum (cdr lst))))))
(define node-expand
(lambda (n lst)
(if (zero? n) '()
(cons (cons n lst) (node-expand (- n 1) lst)))))
(define safe?
(lambda (lst)
(let ((new (car lst))
(hlst (cdr lst)))
(if (null? hlst) #t
(setq indent-tabs-mode nil)
(setq load-path
(append
(list
(expand-file-name "~/emacssetup")
)
load-path))
(require 'mac-key-mode)
(mac-key-mode 1)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand((unsigned)time(NULL));
char str[1024];