Fork me on GitHub
#beginners
<
2019-01-13
>
seancorfield00:01:44

@peter.kehl Not sure what you're asking -- lots of macros out there inject def into the namespace in which they are invoked.

seancorfield00:01:11

deftest in clojure.test, for example. Even defmacro itself injects a def.

peter-kehl00:01:34

Thanks @seancorfield. In my macro, I was generating code that used clojure.core/def instead of def. I didn't know that special forms are namespace-less.

jaihindhreddy-duplicate01:01:03

After all, they are special.

athomasoriginal01:01:08

Sorry, the semantics are values. I did not add the full structure:

{:column-name {1 5 55 68 8 47}}
Example: when column-name has a value of 1 update it to 5 and so on

lilactown01:01:01

well, a classic way of doing polymorphism in Clojure is to use multi-methods

lilactown01:01:49

so you could define a multi-method that dispatches to discern which row type you have and then from there, return a map of values you want to update:

(defmulti update-map (fn [row] <discern row type>))

(defmethod update-map :type-one
  [_]
  {:column-name {1 5 55 68 8 47}})

lilactown01:01:32

if you need something more dynamic, like you’re programmatically creating these update maps, then you could use something like:

(defn update-map [row updaters]
  (let [row-type <discern row-type>]
    (get updates row-type)))

(update-map row {:type-one {:column-name {1 5 55 68 8 47}}})

👍 5
peter-kehl04:01:37

Hi team. Can a macro somehow detect whether the user's namespace has def-ined a variable with a given name? (Something like &env, but for def?)

peter-kehl05:01:54

I'll try with ns-resolve.

peter-kehl07:01:56

"State of Clojure 2019" survey (https://www.surveymonkey.com/r/clojure2019) has a #19 question: "Rate the priority of making improvements to Clojure in these areas." > "AOT". What does AOT mean?

peter-kehl07:01:11

Ah, "Ahead of Time" compilation

👌 5
Chase17:01:40

recursion is still a hard concept for me to grasp sometimes. I try and write out the steps on paper but sometimes it gets a little crazy. is there a way for the repl to step through the function for me? Is that what debugging is? I think I remember Racket had something like that in their DrRacket IDE and it was helpful.

Lennart Buit19:01:59

Cursive has the ability to step through code step by step.

Lennart Buit19:01:06

That said, as cheesy as it sounds, you have to believe in recursion. “If I do this now, and recur, and end then, I have my problem solved”.

Lennart Buit19:01:47

I would recommend just looking at some recursive algorithms, fibonacci comes to mind and quicksort/mergesort

Lennart Buit19:01:21

Its just something that clicks eventually, so to say

Chase21:01:18

That actually makes sense to me. I was prompted to ask when I realized I knew what a 4clojure recursion exercise was going to return but had difficulty doing the step by step of it after the fact.

Chase21:01:46

I'm using Cider and apparently it does have the capability if I do want to explore it. Thanks for the chat

Lennart Buit21:01:05

(We have the same generated avatar, annoying) You’re welcome

👍 5
Audrius17:01:51

is that def creates var?

peter-kehl22:01:07

Hi team. Is metadata supposed/planned to work with symbols? https://clojure.org/reference/reader#_metadata says so. However, while the following doesn't fail, it doesn't carry any meta either: (meta ^:hello 'a) ;=> nil

hiredman22:01:59

'a => (quote a)

hiredman22:01:38

so you are putting metadata on the list that contains the quoted data, not the data

hiredman22:01:59

(with-meta 'a {:hello true}) will do what you want, because it adds metadata after evaluation, so the quote is stripped

hiredman22:01:30

user=> (read-string "'a")
(quote a)
user=> (eval (read-string "'a"))
a
user=>