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
View keybase.md

Keybase proof

I hereby claim:

  • I am megakorre on github.
  • I am megakorre (https://keybase.io/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 (
"bufio"
"io"
"net"
"os"
)
func echoLoop(c chan string,broadcast chan string, con net.Conn) {
View let-map.clj
(defmacro let-map [& bindings]
`(let ~(into [] bindings)
~(reduce
(fn [p [n _]]
(if (= \- (first (name n)))
p
(assoc p (keyword (name n)) n)))
{}
(partition 2 bindings))))
View gist:3308334
enum expr {
val(int),
plus(&expr, &expr),
minus(&expr, &expr)
}
View code-example.rs
mod enum_mod {
export run;
enum expr {
val(int),
plus(&expr, &expr),
minus(&expr, &expr)
}
fn eval(e: &expr) -> int {
@megakorre
megakorre / rust-poly.md
Created Aug 8, 2012
blog: rust pollymorpism
View rust-poly.md

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
test.rs:16:19: 16:22 error: mismatched types: expected `fn@(&&<V6>) -> <V8>` but found `extern fn(&int) -> &int` (expected argument mode ++ but found &&)
test.rs:16 let v = mapper(inc, add);
^~~
test.rs:16:24: 16:27 error: mismatched types: expected `fn@(&&<V7>, &&<V8>) -> <V7>` but found `extern fn(&int, &int) -> &int` (expected argument mode ++ but found &&)
test.rs:16 let v = mapper(inc, add);
^~~
error: aborting due to 2 previous errors
@megakorre
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)
seq)
method-sym (.getName (first methods))]
(when-not (= (count methods) 1)
@megakorre
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
`(reduce
(fn [a# b#] (let [~scoped [a# b#]] ~(compile-aggr r code)))
~expression)
`(do ~@code))))
@megakorre
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.