Skip to content

Instantly share code, notes, and snippets.

aaa
aaa
aaa
@kineticz
kineticz / core.clj
Created January 24, 2015 19:20
Destructuring nested maps in clojure, both versions work.
;; version 1
(def game {:world {:tiles 5}})
(defn get-tiles
[{{:keys [tiles]} :world :as game}]
(println game)
(println tiles))
(get-tiles game)
;; version 2
(def game {:world {:tiles 5}})
(defn get-tiles
;; Accessing / indexing 2d vectors in clojure
(def tiles [[1 2 3] [4 5 6]])
(tiles 1)
((tiles 1) 2)
@kineticz
kineticz / core.clj
Created January 24, 2015 19:38
Using -> where there is no pipe line
(defmulti process-input
(fn [game input]
(:kind (last (:uis game)))))
(defmethod process-input :start [game input]
(-> game
(assoc :world (random-world))
(assoc :uis [(new UI :play)])))
@kineticz
kineticz / world.clj
Created January 24, 2015 20:42
Why is dorun necessary here?
(defn print-row [row]
(println (apply str (map :glyph row))))
(defn print-world [world]
(dorun (map print-row (:tiles world))))
@kineticz
kineticz / core.clj
Created January 25, 2015 19:03
Why doesn't this macro work? It's supposed to print 1 to 5.
(require '(clojure [string :as str]
[walk :as walk]))
(defmacro reverse-it
[form]
(walk/postwalk #(if (symbol? %)
(symbol (str/reverse (name %))))
form))
(reverse-it
(qesod [gra (egnar 5)]
(nltnirp (cni gra))))
@kineticz
kineticz / core.clj
Created January 25, 2015 19:32
difference between ' and ` in clojure macros
(defmacro oops [arg] `(frontfdsa ~arg))
(macroexpand-1 `(oops 13))
(macroexpand-1 '(oops 13))
@kineticz
kineticz / Main.java
Created January 26, 2015 13:01
symbol not found?
package com.company;
public class Main {
public static void main(String[] args) {
for(int i = args.length() - 1; i >= 0; i--) {
reverse(args[i]);
}
System.out.println();
}