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:
I hereby claim:
To claim this, I am signing this object:
package main | |
import ( | |
"bufio" | |
"io" | |
"net" | |
"os" | |
) | |
func echoLoop(c chan string,broadcast chan string, con net.Conn) { |
(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)))) |
enum expr { | |
val(int), | |
plus(&expr, &expr), | |
minus(&expr, &expr) | |
} |
mod enum_mod { | |
export run; | |
enum expr { | |
val(int), | |
plus(&expr, &expr), | |
minus(&expr, &expr) | |
} | |
fn eval(e: &expr) -> int { |
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.
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 |
(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) |
(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)))) |
(.log js/console "Hello, World") |