This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tco | |
[func] | |
(let [unique-id (gensym) | |
firstcall (ref true) | |
arguments (ref nil) | |
continue? (ref true) | |
answer (ref nil)] | |
(fn | |
[& args] | |
(if @firstcall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
int gcd(int a, int b) | |
{ | |
if(a < b) gcd(b, a); | |
if(b == 0) return a; | |
return gcd(b,a%b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.contrib.combinatorics) | |
; How to use | |
; (sisoku [7 7 7 9 11 11] 218/100) | |
; (sisoku [1 1 6 11 12 13] 314/100) | |
(defn drop-nth [n coll] | |
(concat (take n coll) | |
(drop (inc n) coll))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.contrib.combinatorics) | |
; How to use | |
; (sisoku-solve [7 7 7 9 11 11] 218/100) | |
; (sisoku-solve [1 1 6 11 12 13] 314/100) | |
(defn drop-nth [n coll] | |
(concat (take n coll) | |
(drop (inc n) coll))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/Gambit-C/bin/gsi | |
; Copyright (C) 2004 by Marc Feeley, All Rights Reserved. | |
; This is the "90 minute Scheme to C compiler" presented at the | |
; Montreal Scheme/Lisp User Group on October 20, 2004. | |
; Usage with Gambit-C 4.0: | |
; | |
; % ./90-min-scc.scm test.scm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-1) | |
(define (normalize form) | |
(cond | |
[(atom? form) form] | |
[(and (list? form) (macro? (car form))) form] | |
[(list? form) | |
(case (car form) | |
((define) (normalize-define form)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, sys | |
def lex(s): | |
for m in re.finditer(r'S|I|K|\(|\)', s): | |
yield m.group(0) | |
def parse(s): | |
l = lex(s) | |
while True: | |
x = next(l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def fib (n) | |
(if (< n 2) | |
1 | |
(+ (fib (- n 1)) (fib (- n 2))))) | |
(fib 30) | |
------------------------------------------- | |
[0] const 0x79 ; fixnum(30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def sum (list) | |
(if (nilp list) | |
0 | |
(+ (car list) | |
(sum (cdr list))))) | |
(sum '(1 2 3)) | |
----------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hello | |
(:gen-class)) | |
(def x (atom 2)) | |
(defmacro test-macro [] | |
(println @x)) | |
(swap! x inc) |