This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Wrote def instead of defn [1] | |
- Wrong indentation: Hence the function was nested instead of toplevel [1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro spy | |
[& body] | |
`(let [x# ~@body] | |
(printf "=> %s = %s\n" (first '~body) x#) | |
x#)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (C) Stefan Edlich Eclipse Public License | |
;; ToDo: Zone should be an int! ;; Null values should be inserted as null ! | |
(import '(java.io File)) | |
(def filepath "complete.json") | |
(def oldpath "complete-old.json") | |
(defn sport2json [] | |
"Convert User Input to JSON text" | |
(print "Types: MULTI, RUN, BIKE, SPIN, POWER, SWIM, TT, WALK, YOGA, SEE, KITE, BODYSURF, FOOTBALL, etc.\n\n") | |
(let [date (do (print "Date (e.g. 19.10.2014): ") (flush)(read-line)) ;; get today if empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VIM and Clojure: | |
The current steps might be (intended for vim beginners). | |
0A. Install Pathogen for easy vim installation (optional) | |
- https://github.com/tpope/vim-pathogen | |
- http://www.vim.org/scripts/script.php?script_id=2332 | |
0B. Install new version of static runtime editing (optional, only if latest version is needed) | |
- https://github.com/guns/vim-clojure-static |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def s "Lagergeral") ;; test this in tryclj.com line by line | |
(print (apply str (concat (reverse "Lagergeral") (repeat (- 20 (count s)) "#")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(C) Mikera on Stackoverflow: | |
http://stackoverflow.com/questions/10434638/good-examples-of-clojure-macros-usage-which-demonstrate-advantages-of-the-langua/10435150 | |
I find macros pretty useful for defining new language features. In most languages you would need to wait for a new release of the language to get new syntax - in Lisp you can just extend the core language with macros and add the features yourself. | |
For example, Clojure doesn't have a imperative C-style for(i=0 ;i<10; i++) loop but you can easily add one with a macro: | |
(defmacro for-loop [[sym init check change :as params] & steps] | |
(cond | |
(not (vector? params)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn edlTron2 [{:keys [dir togo] :or {togo 0}}] | |
(if (pos? togo) | |
{:dir dir :togo (dec togo)} | |
{:dir (rand-nth [:up :down :left :right]) | |
:togo 5})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mycycle [mylist index] | |
(println "Habe " mylist "," index) | |
(println "Mycycle Element = " (nth mylist index)) | |
(read-line) | |
(if (>= index (dec (count mylist))) | |
(mycycle mylist 0) | |
(mycycle mylist (inc index)))) | |
(mycycle '(1 2 3 4 5 6) 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn pos2str [pos fenpos i-count spacecount] ;; Convert a position to the fen position (1st element) | |
(println ">" (apply str pos) "<") | |
(println ">" (apply str fenpos) "<") | |
(println "i-count=" i-count "spacecount" spacecount "piece(" (first pos) ") ---------------") | |
(read-line) | |
(let [piece (first pos)] | |
(if (empty? pos) | |
fenpos | |
(if (= i-count 7) | |
(if (= piece " ") ; nr=7 |