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
(define xs (loop [i 0 xs '()] | |
(if (< i 3) | |
(recur (+ i 1) (cons (fn [x] i) xs)) | |
xs))) | |
(println "defined.") | |
((car xs) 'a) | |
((cadr xs) 'a) | |
((caddr xs) 'a) |
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
(define my-map-type (. reflect MapOf | |
(. reflect TypeByKind (. reflect Int)) | |
(. reflect TypeByKind (. reflect String)))) | |
(println my-map-type) | |
(define my-map (. reflect MakeMap my-map-type)) | |
(. my-map SetMapIndex (. reflect ValueOf 1) (. reflect ValueOf "abc")) | |
(. my-map SetMapIndex (. reflect ValueOf 2) (. reflect ValueOf "def")) |
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
: | |
; http://mattn.kaoriya.net/software/lang/go/20131112132831.htm | |
; | |
(begin | |
(define task (make-chan-string)) | |
(define taskquit (make-chan-bool)) | |
(define workerquit (make-chan-bool)) | |
(go (fn [] | |
(loop [] |
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
(GOMAXPROCS 4) | |
(defn greet [n msg] | |
(loop [i 0] | |
(if (< i n) | |
(begin | |
(println msg) | |
(recur (+ i 1))) | |
(println "done")))) |
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
in: (define foo | |
(defer | |
(fn [] (println defer is cool!)) | |
(fn [x] | |
(begin | |
(println do something) | |
(println x) | |
(* 3 x))))) | |
--> foo | |
in: (foo 42) |
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
class G: | |
def __init__(self): | |
self.stack = [] | |
def __iter__(self): | |
return reversed(self.stack) | |
def push(self, v): |
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
(define (f n) | |
(define (downto end i) | |
(if (<= end i) | |
(cons i (downto end (- i 1))) | |
'())) | |
(downto (expt 10 (- n 1)) (- (expt 10 n) 1))) | |
;;(fold-right append '() (map f (list 1 2 3))) | |
(define (flatten xs) (fold-right append '() xs)) |
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
package huffman | |
type Tree interface { | |
Weight() int | |
Symbols() []byte | |
DecodeBit(bits []int, pos int) (byte, bool, Tree) | |
Encode(c byte, out chan int) | |
} |
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
package main | |
import ( | |
"fmt" | |
) | |
func oddsum(xs []int) int { | |
sum := 0 | |
for i, v := range xs { | |
if i % 2 == 0 { |
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
package main | |
import ( | |
"fmt" | |
) | |
func drop(xs []int, n int) []int { | |
ys := make([]int, len(xs)-1) | |
for i:=0 ; i < n ; i++{ |