Skip to content

Instantly share code, notes, and snippets.

View lagenorhynque's full-sized avatar
🐬
architecting & managing

Kent OHASHI lagenorhynque

🐬
architecting & managing
View GitHub Profile
> maybe "undefined" (show . (^ 2)) (Just 42)
"1764"
> maybe "undefined" (show . (^ 2)) Nothing
"undefined"
import java.util.*;
public class Bench {
public static final int _keyRange = 100;
public static final int _threadCount = 300;
public static final int _repeat = 100000;
//--------------------------------------------------------------------------------
public static void main(String[] args) throws Exception {
user=> (def fact
#_=> ((fn [f]
#_=> ((fn [x] (x x))
#_=> (fn [y] (f (fn [& args] (apply (y y) args))))))
#_=> (fn [f]
#_=> (fn [n] (if (< n 2) 1 (* n (f (dec n))))))))
#'user/fact
user=> (for [n (range 10)] (fact n))
(1 1 2 6 24 120 720 5040 40320 362880)
user=> (let [z (+ x y)
#_=> x 1
#_=> y 2]
#_=> z)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context, compiling:(/private/var/folders/pm/hsqkdvv91xn_wpq0fdpfsrz0tk36y9/T/form-init12874968895952326174.clj:1:9)
user=> (letfn [(z [] (+ (x) (y)))
#_=> (x [] 1)
#_=> (y [] 2)]
#_=> (z))
import Model
:set -XOverloadedStrings -XTypeFamilies -XFlexibleContexts
import Database.Persist.Sqlite
asSqlBackendReader :: ReaderT SqlBackend m a -> ReaderT SqlBackend m a
asSqlBackendReader = id
withDB :: (BaseBackend backend ~ SqlBackend,
// アカウント作成
personal.newAccount("sample")
personal.newAccount("sample2") // sample2がそのアカウントのパスフレーズになる
// 残高確認
web3.fromWei(eth.getBalance(eth.accounts[0]))
// マイニング: eth.accounts[0]に報酬が入る
miner.start()
miner.stop() // DAGを作ってるログが出たら、終わるまで待つ必要があるぽい
> :set -XRankNTypes
> :{
| twoList :: [a] -> [b] -> (forall c. [c] -> d) -> (d, d)
| twoList xs ys f = (f xs, f ys)
| :}
> twoList [1,2,3,4,5] ["hoge","fuga","piyo"] length
(5,3)
(ns polymorphism
(:require [cats.context :as ctx]
[cats.core :as m]
[cats.protocols :as p]
[cats.util :as util]))
(defn my-map [f coll]
(lazy-seq
(when-let [s (seq coll)]
(cons (f (first s))
(ns cli
(:require [clojure.spec.alpha :as s]))
(s/fdef sum
:args (s/cat :coll (s/coll-of number?))
:ret number?)
(defn sum [coll]
(if (empty? coll)
0
(ns channel-example
(:require [clojure.core.async :as async]))
(defn -main []
(let [ch1 (async/chan)
ch2 (async/chan)
ch3 (async/chan)]
(async/go-loop []
(let [i (async/<! ch1)]
(async/>! ch2 (* i 2))