(defmacro pass-args (code &rest args)
`(,@code ,@args))
> (macroexpand '(pass-args (format) t "Hello, World!"))
(FORMAT T "Hello, World!")
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
| (ns books.little-series.little-learner.core) | |
| ;; p. 11 | |
| (def remainder | |
| (fn [x y] | |
| (cond | |
| (< x y) x | |
| :else (remainder (- x y) y)))) | |
| ;; p. 14 |
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 atom? [x] | |
| (not (list? x))) | |
| (def car first) | |
| (def cdr next) | |
| (def add1 inc) | |
| (def sub1 dec) | |
| (defn lat? [lst] | |
| (every? atom? lst)) |
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 form-2-component [] | |
| (let [content "Hello, world!"] | |
| (fn [] [:div content]))) |
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 pass-args [code & args] | |
| `(~@code ~@args)) | |
| > (macroexpand '(pass-args (+) 1 2 3)) | |
| (+ 1 2 3) | |
| > (+) | |
| 0 | |
| > (pass-args (+) 1 2 3) | |
| 6 |
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
| require 'rubygems' | |
| require 'couchbase' | |
| def transfer(source, destination, amount) | |
| cb = Couchbase.bucket | |
| # prepare transaction document | |
| id = cb.incr("transaction:counter", :create => true) | |
| trans_id = "transaction:#{id}" | |
| cb.set(trans_id, {"source" => source, "destination" => destination, |
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
| function fibonacci(n) { | |
| var f = [1,1], j, p = f[0], s, i = n + 2; | |
| for (j = 2; j < i; j++) { | |
| s = f[j-1]; | |
| f.push(p + s); | |
| p = s; | |
| } | |
| return f; | |
| } |
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
| function cifradoCesar(string) { | |
| var a = [], | |
| stringLength = string.length, | |
| letter; | |
| for (var i = 0; i < stringLength; i++) { | |
| letter = string.charAt(i); | |
| if (letter == ' ') { | |
| a.push(' '); | |
| } else if (letter == 'z') { |
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
| function maxZaks(array) { | |
| var max = -Infinity; | |
| for (var i = 0; i < array.length; i++) { | |
| max = Math.max(array[i],max) | |
| } | |
| return max; | |
| } |