Skip to content

Instantly share code, notes, and snippets.

Patrik Kårlin megakorre

Block or report user

Report or block megakorre

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am megakorre on github.
  • I am megakorre ( on keybase.
  • I have a public key ASAuD9d2Yv2fzydlqsmDvq-Jz9Psh2qoPwFCji9_DFG0mAo

To claim this, I am signing this object:

View chat_echo.go
package main
import (
func echoLoop(c chan string,broadcast chan string, con net.Conn) {
View let-map.clj
(defmacro let-map [& bindings]
`(let ~(into [] bindings)
(fn [p [n _]]
(if (= \- (first (name n)))
(assoc p (keyword (name n)) n)))
(partition 2 bindings))))
View gist:3308334
enum expr {
plus(&expr, &expr),
minus(&expr, &expr)
mod enum_mod {
export run;
enum expr {
plus(&expr, &expr),
minus(&expr, &expr)
fn eval(e: &expr) -> int {
megakorre /
Created Aug 8, 2012
blog: rust pollymorpism

EDIT! full code can be found here gist

So I played around with rust a bit now. And I thought I might share some random stuff.

So say you wanted to represent a expression tree with plus and minus nodes and a node for values. One way to do this would be to use rust's enum's.

In rust enums are like haskell's union types so you can specify the different values to be constructors carrying data.

View gist:3260324 16:22 error: mismatched types: expected `fn@(&&<V6>) -> <V8>` but found `extern fn(&int) -> &int` (expected argument mode ++ but found &&) let v = mapper(inc, add);
^~~ 16:27 error: mismatched types: expected `fn@(&&<V7>, &&<V8>) -> <V7>` but found `extern fn(&int, &int) -> &int` (expected argument mode ++ but found &&) let v = mapper(inc, add);
error: aborting due to 2 previous errors
megakorre / func-interface.clj
Created Jul 18, 2012
functional interface implementation in clojure
View func-interface.clj
(defmacro fi
[interface args & code]
(let [interface-type (.getMapping *ns* interface)
methods (-> (.getMethods interface-type)
method-sym (.getName (first methods))]
(when-not (= (count methods) 1)
megakorre / gist:2889294
Created Jun 7, 2012
aggr a macro for reduce comprihension*
View gist:2889294
(defn compile-aggr [binding code]
(let [[scoped expression & r] binding]
(when (and scoped (not expression))
(throw (new Exception "aggr needs a even number of parameters")))
(if scoped
(fn [a# b#] (let [~scoped [a# b#]] ~(compile-aggr r code)))
`(do ~@code))))
megakorre / gist:2474043
Created Apr 23, 2012
console log clojurescript
View gist:2474043
(.log js/console "Hello, World")
You can’t perform that action at this time.