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 'clojure.core.logic) | |
| (def rvar? (comp not lvar?)) | |
| (defmacro arithm [r x y op po] | |
| `(fn [a#] | |
| (let [r# (walk a# ~r) | |
| x# (walk a# ~x) | |
| y# (walk a# ~y)] | |
| (cond |
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
| public static class ComUtils | |
| { | |
| public static object Get(object obj, string key, object[] args = null) | |
| { | |
| return obj.GetType().InvokeMember( | |
| key, | |
| System.Reflection.BindingFlags.GetProperty, | |
| null, | |
| obj, | |
| args); |
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 'clojure.core.logic | |
| 'clojure.core.logic.arithmetic) | |
| (defne diffo | |
| [l] | |
| ([[]]) | |
| ([[x]]) | |
| ([[x y . tail]] | |
| (fresh [l0 l1] | |
| (!= x y) |
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
| module AttrHistory | |
| def attr_history(name) | |
| attr_reader "#{name}_history", name | |
| define_method "#{name}=" do |value| | |
| history = send("#{name}_history") || [] | |
| instance_variable_set "@#{name}_history", history.push(value) | |
| instance_variable_set "@#{name}", value | |
| end | |
| end |
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 deffactory | |
| "Defines a factory function that returns an instance of the specified | |
| record initialized with the default values provided overridden by the | |
| values it is given." | |
| [factory-name record-name defaults] | |
| `(defn ~factory-name | |
| ~(str "A factory function returning a new instance of " record-name | |
| " initialized with the defaults specified at the time of" | |
| " definition overridden by the given values. The values can" | |
| " be specified as a map or field-value pairs.") |
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 sicp) | |
| ;;;; Section 1.1 - The Elements of Programming | |
| ;;; Exercise 1.1 | |
| [10 12 8 3 6 'a 'b 19 false 4 16 6 16] |
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
| -- Snake my_turn_in puzzle implementation | |
| -- | |
| -- The direction argument accept an Ordering value where GT is | |
| -- :forward, LT is :backward and EQ is :same. | |
| -- | |
| -- Problem definition can be found in: | |
| -- https://github.com/budu/Puzzles | |
| myTurnIn :: (Ord a, Integral a) => a -> a -> Ordering -> a -> a | |
| myTurnIn _ _ _ 1 = 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
| (ns sy2 "based on: https://gist.github.com/953966") | |
| (defmacro if-eof [true-f false-f] | |
| `(try | |
| ~false-f | |
| (catch Exception e# | |
| (if (= (.getMessage e#) "EOF while reading") | |
| ~true-f | |
| (throw e#))))) |
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 sy | |
| "Monadic implementation of the Shunting-yard algorithm, including | |
| infix binary operator with associativity, function calls and basic | |
| sequence support. It transalate a simple C like expression syntax into | |
| s-expression that can be evaluated by Clojure. | |
| 1 + 2 => (+ 1 2) | |
| 1 + 2 * 3 => (+ 1 (* 2 3)) | |
| 1 * 2 + 3 => (+ (* 1 2) 3) | |
| (1 + 2) * 3 => (* (identity (+ 1 2)) 3) |
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 crazy [name & args] | |
| (let [name* (symbol (str name \*))] | |
| `(do | |
| (defn ~name* [self# & params#] | |
| (prn self#)) | |
| (defmacro ~name [~'& args#] | |
| `(~~name* (quote ~~'&form) ~@args#))))) |