So for problem 88, this is how I coded my solution
(fn [x y]
(into #{} (concat
((fn foo [a b]
(cond
(empty? a) a
(not (contains? b (first a)))
(concat (list (first a)) (foo (rest a) b))
:else (foo (rest a) b))
) x y)
((fn foo [a b]
(cond
(empty? a) a
(not (contains? b (first a)))
(concat (list (first a)) (foo (rest a) b))
:else (foo (rest a) b))) y x)
)
))
As you can see, I had to redefine the function foo twice, that is duplication of code. Is there any way that I can define the function once and then access it?
I tried using def in 4clojure and it said I was not allowed. Had similar issue declaring it with defn.
I tried defining the function foo outside of my anonymous main function like this.
(fn foo [a b]
(cond
(empty? a) a
(not (contains? b (first a)))
(concat (list (first a)) (foo (rest a) b))
:else (foo (rest a) b))
)
(fn [x y]
(into #{} (concat
(foo x y)
(foo y x)
)
))
And using foo inside anonymous function like following.
(fn [x y]
((into #{} (concat
(foo x y)
(foo y x)
))
(fn foo [a b]
(cond
(empty? a) a
(not (contains? b (first a)))
(concat (list (first a)) (foo (rest a) b))
:else (foo (rest a) b))
)
))
But each time I get the message, that foo cannot be accessed. What is it, that I am messing up in scoping?
Any help would be appreciated.
Thanks,
Soham