Skip to content

Instantly share code, notes, and snippets.

View swr1bm86's full-sized avatar
🏠
Working from home

xxx swr1bm86

🏠
Working from home
View GitHub Profile
// Compositional evaluator as visitor
import java.math.BigInteger;
// Syntax
interface Exp {
<X> X accept(Visitor<X> v);
}
Y组合子是Lambda演算的一部分,也是函数式编程的理论基础。
它是一种方法/技巧,在没有赋值语句的前提下定义递归的匿名函数。
即仅仅通过Lambda表达式这个最基本的“原子”实现循环/迭代。
颇有道生一、一生二、二生三、三生万物的感觉。
虽然Y组合子在理论上很优美,但在实际开发中并不会真的用到。
想要了解Y组合子是什么,请参见维基百科:http://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator
或者知乎上的回答:http://www.zhihu.com/question/20115649
@swr1bm86
swr1bm86 / Lexer.java
Last active August 29, 2015 14:23 — forked from michiakig/Lexer.java
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:
@swr1bm86
swr1bm86 / reader.hs
Last active August 29, 2015 14:23 — forked from egonSchiele/reader.hs
import Control.Monad.Reader
hello :: Reader String String
hello = do
name <- ask
return ("hello, " ++ name ++ "!")
bye :: Reader String String
bye = do
name <- ask
  • defprotocol: defines an interface
  • deftype: create a bare-bones object which implements a protocol
  • defrecord: creates an immutable persistent map which implements a protocol

Typically you'll use defrecord (or even a basic map);
unless you need some specific Java inter-op,
where by you'll want to use deftype instead.

Note: defprotocol allows you to add new abstractions in a clean way Rather than (like OOP) having polymorphism on the class itself,

@swr1bm86
swr1bm86 / IDEA (Cursive) shortcuts
Last active April 27, 2016 06:53
cursive tips
在oracle的jdk上运行idea会出现一些问题 尤其是在使用cursive的时候 所以要装一下[jdkforosx](https://support.apple.com/kb/DL1572?locale=zh_CN)
然后IntelliJ IDEA->About IntelliJ IDEA.查看idea的运行时是不是用了这个jre如果是就不会有任何问题了
要对某一个自建的symbol设置缩进的时候可以按alt+enter
alt+上下方向键可以格式化选择代码来进行复制删除等操作 alt+左右方向键用来在一个form的左右括号之间来回移动光标
运行repl时需要先switch to current namespace然后再command+shift+l同步一下代码文件再command+shift+p执行某一个form
alt+cmd+left/right 用来跳转到最近光标所在的位置
Settings→Editor→General→Smart Keys→Use structural editing
@swr1bm86
swr1bm86 / Makefile
Last active September 11, 2015 17:03 — forked from jeremyroman/Makefile
llvm-brainfuck: Simple operations
PROGRAM := llvm-brainfuck
OBJECTS := main.o
CXX := clang++
CXXFLAGS := $(shell llvm-config --cppflags) -Wall -Werror -pedantic
LDFLAGS := $(shell llvm-config --ldflags --libs core)
all: $(PROGRAM) $(SHIM)
$(PROGRAM): $(OBJECTS)
@swr1bm86
swr1bm86 / monad conclusion
Created October 3, 2015 16:03
think about monad
单子(monad)就是自函子范畴上的幺半群的含义
首先函子也就是functor就是范畴上的映射 而映射的起点和重点相同的函子就可以称为自函子
满足两个定理的群叫半群 如果含有幺元(monoid)就称为幺半群
所以monad是一组集合 是自函子这个范畴下 满足幺半群定义的子集合 就是满足这些范畴定义的类型集合
(ns my.app
(:require
[aleph.http :refer :all]
[compojure.core :refer [defroutes GET]]
[compojure.handler :as handler]
[lamina.core :refer :all]
[com.netflix.hystrix.core :as hystrix]
[clj-http.client :as client]))
(defn get-pants []
(for [[x y] (map vector '(1 2 3) '(4 5 6))]
(list x y))
=> ((1 4) (2 5) (3 6))
(for [[x y] (map vector '(1 2 3) '(4 5 6) '(7 8 9))]
(list x y))
=> ((1 4) (2 5) (3 6))
(for [[x y z] (map vector '(1 2 3) '(4 5 6) '(7 8 9))]
(list x y z))
=> ((1 4 7) (2 5 8) (3 6 9))
(for [[x y z] (map vector '(1 2 3) '(4 5 6) '(7))]