I keep on having this error but i cannot seem to resolve it.
(ns stack)
(def output [[1, 2 ,3]])
(def condensedrecords 0)
(def i 0)
(def currentDateTime 0)
(def timeDiffinSeconds 0)
(def secondLastOutputValue 0)
(def outlier [])
(def isOutlier false)
(def timeDiffinSeconds 20)
(def for1 true)
(def ab [1])
;just for testing
(def a [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])
(def b [a, a])
(def NoOfLines 3)
(defn getOutlierConfidence [p i]
0.5)
(defn processNewTransaction [p i] 1)
(defn exceedTimeThresholdwDistance [p i] false)
(defn doRunThroughSplit [vector]
(loop [i 1
condensed 0
output1 output
outlier1 outlier]
(if (< i (- NoOfLines 1))
(let [p ((peek output1) 1)] ;function doesnt work
(cond
;cond1
(= ((vector i) 27) ((peek output1) 1)) (do(let [condensed (inc condensed)]
(println "in cond1")
(recur (inc i) condensed output1 outlier1)))
;cond2
(> timeDiffinSeconds 480) (do (let [i (processNewTransaction p i)] (println "in cond2") (recur (inc i) condensed output1 outlier1)))
;cond3
(> timeDiffinSeconds 600) (do (let [i (processNewTransaction p i)] (println "in cond3") (recur (inc i) condensed output1 outlier1)))
;cond4
(exceedTimeThresholdwDistance p i) (do (let [i (processNewTransaction p i)] (println "in cond4") (recur (inc i) condensed output1 outlier1)))
(and (not= ((peek output) 1) ((vector i) 27)) (not= secondLastOutputValue ((vector i) 27)))
(do ;perform the following statements
(println "in cond5")
(let [secondLastOutputValue ((peek vector) 27)]
***output1 (conj ([output1] ab))]*** ;error starts at here/// ab is a vector by commenting this line the error is removed
(println "reached")
(recur (inc i) condensed output1 outlier1)))
);cond ending
);let ending
[condensed, output1, outlier1]);if ending
);loop ending
);func ending
(def sa (doRunThroughSplit b))
The error has been commented out which is the line
output1 (conj ([output1] ab))
But i cannot seem to resolve this error at all. The majority of the code seems fine but once it hits the let statement in cond5 it gives an error.
The output would be
in cond5
///it ends here
It seems that you’re translating some code from some imperative language (Java?), because there are some things which are completely redundant in clojure.
First of all, most of the first definitions (a number of
defs in the beginning) are not required at all. You do not have to define your variables in this way in clojure: all variables are introduced automatically into the lexical scope with corresponding constructions (let,loop,defnfor local parameters etc.), anddefis supposed to create something like global variables.Next, what do you intend for these constructions to do:
((peek output1) 1),((vector i) 27)? They are completely meaningless. If you want to get an element from a collection by index, you have to do something like(get collection 123)or even(collection 123)provided thatcollectionis some collection, e.g. vector.Finally, your question.
(conj)function is really not supposed to be called like that. A piece from documentation:See, it should be called with a collection as the first argument and elements you wish to insert into this collection as all other arguments. So, if you want to add
abtooutput1collection, you should do(conj output1 ab).Note, however, that fixing
conjwill not make your code work. There are more mistakes in the code (e.g. the ones I mentioned in second point of my answer) which need to be fixed.