Skip to content

Instantly share code, notes, and snippets.

@alex-dixon
Last active May 30, 2018 14:31
Show Gist options
  • Save alex-dixon/4dee1b6a81fa7c86d010aabfddefe17a to your computer and use it in GitHub Desktop.
Save alex-dixon/4dee1b6a81fa7c86d010aabfddefe17a to your computer and use it in GitHub Desktop.

Revisions

  1. alex-dixon revised this gist May 30, 2018. 1 changed file with 0 additions and 14 deletions.
    14 changes: 0 additions & 14 deletions deflocals.clj
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,3 @@
    (defmacro |
    "Takes a variable even number binding to expression pairs and defs each in the current namespace.
    (defn my-func [args]
    (let [(| foo :bar
    {:keys [a b]} {:a 1 :b 2}
    c (+ a b)
    d c)]))
    d => 3
    "
    [& bindings]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))))

    (defmacro deflet [bindings & body]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))
  2. alex-dixon revised this gist Apr 28, 2018. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions deflocals.clj
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,20 @@
    (list 'def sym expr))
    ~@body))

    (defmacro defbindings [bindings]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))))

    (defmacro deflast [sym]
    `(def ~sym *1))


    ;(deflet [foo 1
    ; [_ bar] [1 2]
    ; {:keys [baz]} {:baz 3}]
    ; (+ foo bar baz))
    ;=> 6

    ;(+ 1 1)
    ;(deflast foo)
    ;foo => 2
  3. alex-dixon revised this gist Apr 27, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deflocals.clj
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@
    ;(deflet [foo 1
    ; [_ bar] [1 2]
    ; {:keys [baz]} {:baz 3}]
    ; (+ foo bar baz))
    ; (+ foo bar baz))
    ;=> 6
  4. alex-dixon revised this gist Apr 27, 2018. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion deflocals.clj
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,15 @@
    "
    [& bindings]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))))
    (list 'def sym expr))))

    (defmacro deflet [bindings & body]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))
    ~@body))

    ;(deflet [foo 1
    ; [_ bar] [1 2]
    ; {:keys [baz]} {:baz 3}]
    ; (+ foo bar baz))
    ;=> 6
  5. alex-dixon created this gist Apr 18, 2018.
    13 changes: 13 additions & 0 deletions deflocals.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    (defmacro |
    "Takes a variable even number binding to expression pairs and defs each in the current namespace.
    (defn my-func [args]
    (let [(| foo :bar
    {:keys [a b]} {:a 1 :b 2}
    c (+ a b)
    d c)]))
    d => 3
    "
    [& bindings]
    `(do ~@(for [[sym expr] (partition 2 (destructure bindings))]
    (list 'def sym expr))))