Having troubles using `defmapcatop` successfully -
Given an input file with two fields, ?id and ?pts:
foo a,b,c,d
bar x,y,z
Trying to generate bigrams, which should have output:
foo a,b
foo b,c
foo c,d
bar x,y
bar y,z
I'm having troubles using `defmapcatop` correctly in this case.
I've been able to use `defmapcatop` to make a generator, as in the "foo"
definition below. And I can use tail recursion to create a list of bigrams,
as in the "bar" definition below:
(ns copa.core
(:use [cascalog.api]
[cascalog.more-taps :only (hfs-delimited)])
(:require [clojure.string :as s]
[cascalog [ops :as c] [vars :as v]])
(:gen-class))
(defmapcatop foo [pts]
(s/split pts #",")
)
(defn bar [pts]
(loop [lst (s/split pts #",") coll []]
(if (> (count lst) 1)
(let [x [(nth lst 0) (nth lst 1)]]
(recur (rest lst) (conj coll x))
)
[coll]
)))
(defn -main [in out & args]
(?<- (hfs-delimited out)
[?id ?x]
((hfs-delimited in) ?id ?pts)
(bar ?pts :> ?x)
))
Which has the output:
foo [["a" "b"] ["b" "c"] ["c" "d"]]
bar [["x" "y"] ["y" "z"]]
However, my attempts to compose "foo" and "bar" into one `defmapcatop` are
causing exceptions.
Something like the following in "baz" would seem to be the intuitive
approach (but it fails):
(defmapcatop baz [lst]
lst
)
Is there a better way to structure the collector in the tail-recursive
definition?
Thanks,
Paco