Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains hidden or 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 $(GOROOT)/src/Make.$(GOARCH) | |
| TARG=kademlia | |
| GOFILES=\ | |
| nodeid.go\ | |
| routingtable.go\ | |
| contact.go\ | |
| kademlia.go | |
| include $(GOROOT)/src/Make.pkg |
This file contains hidden or 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" | |
| "reflect" | |
| ) | |
| //function types | |
| type mapf func(interface{}) interface{} |
Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains hidden or 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 CHEATSHEET | |
| ;; | |
| ;; * :require makes functions available with a namespace prefix | |
| ;; and optionally can refer functions to the current ns. | |
| ;; | |
| ;; * :import refers Java classes to the current namespace. | |
| ;; | |
| ;; * :refer-clojure affects availability of built-in (clojure.core) | |
| ;; functions. |
This file contains hidden or 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 fizzbuzz [n] | |
| (let [all-nums (range 0 n) | |
| folder (fn [fb-str p-num fb-coll] | |
| (mapcat (fn [x] (cons fb-str (rest x))) | |
| (partition-all p-num fb-coll))) | |
| fizz (folder "fizz" 3 all-nums) | |
| buzz (folder "buzz" 5 fizz) | |
| fizzbuzz (folder "fizzbuzz" 15 buzz)] | |
| fizzbuzz)) |
This file contains hidden or 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
| // Compositional evaluator as visitor | |
| import java.math.BigInteger; | |
| // Syntax | |
| interface Exp { | |
| <X> X accept(Visitor<X> v); | |
| } |
This file contains hidden or 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
| Y组合子是Lambda演算的一部分,也是函数式编程的理论基础。 | |
| 它是一种方法/技巧,在没有赋值语句的前提下定义递归的匿名函数。 | |
| 即仅仅通过Lambda表达式这个最基本的“原子”实现循环/迭代。 | |
| 颇有道生一、一生二、二生三、三生万物的感觉。 | |
| 虽然Y组合子在理论上很优美,但在实际开发中并不会真的用到。 | |
| 想要了解Y组合子是什么,请参见维基百科:http://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator | |
| 或者知乎上的回答:http://www.zhihu.com/question/20115649 |
This file contains hidden or 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 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: |
This file contains hidden or 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 Control.Monad.Reader | |
| hello :: Reader String String | |
| hello = do | |
| name <- ask | |
| return ("hello, " ++ name ++ "!") | |
| bye :: Reader String String | |
| bye = do | |
| name <- ask |
OlderNewer