Skip to content

Instantly share code, notes, and snippets.

@edw
Created January 24, 2011 19:38
Show Gist options
  • Save edw/793797 to your computer and use it in GitHub Desktop.
Save edw/793797 to your computer and use it in GitHub Desktop.
Demonstration of multiple-arity support in DEFMAPCATOP
(defmapcatop set-bucket
([s v inv]
(if (contains? s v) (list inv) '()))
([s v inv outv]
(if (contains? s v) (list inv) (list outv)))
([s v inv outv bothv]
(list bothv (if (contains? s v) (list inv) (list outv)))))
(def x (memory-source-tap [["a" 1]
["b" 1]
["c" 1]
["a" 2]
["b" 2]
["c" 2]]))
(?<- (stdout) [?l ?n ?b] (x ?l ?n)
(set-bucket #{"a" "b"} ?l "a-or-b" "not-a-or-b" "a-or-b-or-not-a-or-b" :> ?b))
;; RESULTS
;; -----------------------
;; a 1 a-or-b
;; a 2 a-or-b
;; b 1 a-or-b
;; b 2 a-or-b
;; a 1 a-or-b-or-not-a-or-b
;; a 2 a-or-b-or-not-a-or-b
;; b 1 a-or-b-or-not-a-or-b
;; b 2 a-or-b-or-not-a-or-b
;; c 1 a-or-b-or-not-a-or-b
;; c 2 a-or-b-or-not-a-or-b
;; c 1 not-a-or-b
;; c 2 not-a-or-b
;; -----------------------
(?<- (stdout) [?l ?n ?b] (x ?l ?n)
(set-bucket #{"a" "b"} ?l "a-or-b" "not-a-or-b" :> ?b))
;; RESULTS
;; -----------------------
;; a 1 a-or-b
;; a 2 a-or-b
;; b 1 a-or-b
;; b 2 a-or-b
;; c 1 not-a-or-b
;; c 2 not-a-or-b
;; -----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment