Fork me on GitHub
Chris Lester04:02:48

More macro fun 🙂 ... Having some problems trying to get a macro to call another macro, either getting "no conversion to symbol" compiling, or a seq to boolean error when calling the output. I've tried many permutations, seems like this should work but currently I'm not seeing it.

Chris Lester07:02:58

... had thought I had the earlier macro working with the defs... turns out it is not. Would love to figure out what I'm doing that causes problems with the symbol definition but have had enough macro playtime today.


@activeghost macros don't evaluate their arguments, so when you type (defflags flags) the macro sees the symbol flags, not the value bound to it, that's why it's unable to coerce it to a seq. You can eval in the macro, but maybe a function would be more appropriate in this case.

Ramon Rios15:02:27

Hello everyone 🙂 . Can you help me think in something? I'm creating a function that call other function (nothing more clojure than this) for check if certain keys on a map are emails

(defn validate-email
  "validate email request"
  (and (is-email? (:to email)) (is-email? (:cc email)) (is-email? (:bcc email))))

Ramon Rios15:02:42

My point is: not all the time we're going to receive a :cc or :bcc , so i'm thinkg how i'm going to "tolerate " these keys in case of them does not exist

Ramon Rios15:02:45

For, when these keys do not exist, it does not count as a false email. Am i being clear?


You can define a function

(defn valid-email? [email] (or (nil? email) (is-email? email)))


something like this?


Both work, in this case I think Lukasz solution is more clear 🙂

Ramon Rios15:02:02

Thanks, i'm testing it

Ramon Rios15:02:12

I tought this at the beginning but , you know, as a "begginer" you always think that your solution is not the best one.


> Simplest solutions are the best first solutions


Sorry, I think I asked this question not long ago but can't find the answer. I'm calling compile, but not getting clojure classes like clojure.lang.Var written to classes. I can't remember what the fix was.


compile doesn't do that


compile writes the jvm bytecode the clojure compiler generates to disk somewhere, it doesn't copy existing jvm bytecode, and doesn't compile java


I was actually trying to follow what's described in this article, which winds up with the same problem (maybe for the same reason), trying to debug by calling compile directly. Maybe this is an issue I need to take up with the tooling authors...


you likely are missing the lib bit of the classpath from there


either missed it entirely, or maybe using a jvm that doesn't understand '*' or maybe launching the jvm in same way that doesn't understand it


That was it. Thanks.


I have some clojure maps that I want to extend to .Closeable. Is there an easy way to reify or similar at runtime such that I still have IPM that now respond to a java interface?


why not defrecord?


I could defrecord, but this hypothetical reify-alike would require less code refactoring


(map->CloseableMap m)

user=> (defrecord ClosableMap [] .Closeable (close [this] (println "I'm closed")))
user=> (def m {:a 0 :b 1 :c 2})
user=> (def cm (map->ClosableMap m))
user=> (.close cm)
I'm closed


Making a map Closeable sounds like something at the end or the beginning of a road of pain


my assumption was that you had something upstream that wanted to call .close and you needed a placeholder - if it requires actual logic for closing, I agree


@arohner I have this dodgey code from earlier


but swapping explicit .close calls to a close through a protocol might solve your issue in a clean way maybe>


(defn make-adder-form [type]
  `(fn [i] (+ 2 i)))
=> #'voskos.avro/make-adder-form
(make-adder-form ['int])
=> (clojure.core/fn [user/i] (clojure.core/+ 2 user/i))
What should I add to the form I'm returning if I want to add the given type hint to the function parameter i?


@mac01021 (with-meta i {:type type})



user=> (defn make-adder-form [type] `(fn [~(with-meta 'i {:type type})] (+ 2 ~'i)))
user=> (make-adder-form 'int)
(clojure.core/fn [i] (clojure.core/+ 2 i))
user=> (binding [*print-meta* true] (pr-str (make-adder-form 'int)))
"(clojure.core/fn [^{:type int} i] (clojure.core/+ 2 i))"


I also added a classic unqoute / quote trick to make parameters work


What’s the state-of-the-art choice for deploying a CLJ/CLJS app to a Linux box with minimal fuss?


I've been using the clj command line, with configuration using integrant - it works pretty well as far as the minimal fuss goes.


Ah, ok. I’ll check into that. I’ve been running from a jarfile.


@U054BUGT4 so in your case the deploy itself is a copy or git clone?


How do you handle deployment?


Yes, that was my next question ☝️:skin-tone-2:


Yes, forgot to mention that part - I also forgot to mention that I'm using aero for config files (managing passwords as shown in Copy the config files over manually before deployment.


Does anyone know what passing two arguments when invoking a hashmap as a function does? ‘({:a 1 :b 2} :a :b)’


it invokes get

user=> (doc get)
([map key] [map key not-found])
  Returns the value mapped to key, not-found or nil if key not present.


Ah thanks. This was hard for me to google


ahh clojure source code - we aren't allowed to question your uglyness

Alex Miller (Clojure team)23:02:00

maybe it's ugly on purpose :)


You are allowed to question, but you are not allowed to demand that PRs are accepted 🙂


And I never saw it before reading Clojure source code, but Whitesmith's indentation style is a thing that existed before Clojure:


Even says it is second most popular, according to one source. Strange I never saw it before Clojure source code, if so.

Alex Miller (Clojure team)00:02:33

Rich likes it, but I think he’s crazy on this point :)

🙂 4
metal 4

I was wondering what was up with the clojure indentation


I can't complain though, I did everything GNU style for a while


And I forgot to mention the perhaps-obvious: you are allowed to use automated code reformatting tools like indent (or the Java equivalent, if that doesn't work on Java source) on your own copy of the source code.


Ouch, the diffs though


Who said anything about diffs? I'm talking about reading code with the formatting you prefer to see


Those diffs will never be applied to the official source, as far as I am aware.


yes, reformatting other folks' code for reading purposes is quite nice.


Hope you are sarcastic, I really do.


Why do you hope he is being sarcastic? I took it as serious, and not a bad thing at all. If someone really has a strong preference for the indentation format for code readability purposes, why not reformat it before reading it? [especially if an automated tool can do it in seconds]


The Wikipedia article I linked hints at how strongly some people word their distaste for these differences, and I wish they were joking, but some people go nuts over this stuff: "The Linux kernel coding style documentation also strongly recommends against this [GNU] style, urging readers to burn a copy of the GNU coding standards as a "great symbolic gesture".[28]"


i was not being sarcastic -- i really appreciate being able to reformat code to read it locally. before it occured to me that i could do that i struggled quite a lot (still do even with reformatting). i have a hard enough time reading other people's source code as it is, being able to reformat really helps!


Seems like a bad idea to me. I have learned to not fight against the system. For example, not putting {} on their own line in C#. I think that's a waste of vertical space, but any of the code analysis tools will catch it! Nowadays, I do place {} on their own lines. If you absolutely restrict it to reading, I don't know, maybe that will work. But I am skeptical from my own past experience.


There might be other issues as well. Line 100 in your reformatted code may not be the 100th line in the actual code. How do you tell your coworker to refer to line x?


it seems like andy.fingerhut and i are referring to reading source code locally for our own understanding mostly -- may be you are thinking about other situations? if you're thinking of discussing source, it seems possible to reformat code in the same manner (e.g. use the same editor + config or same reformatting tool). in any case, i have been using the reformatting method for my own purposes and it has worked quite well for me. i'm not trying to convince anyone else to do so, just reporting on my own experience. i would prefer not to have to reformat, but i'm not sure people can agree on what they find most readable. for example, one thing i seem to be at odds with a significant portion of the developer population is how long a line of code should be. i keep encountering source where the length is greater than 80 columns. that is really a big drawback for me, but apparently not for a significant portion of the population. in the case of clojure, if it helped rich hickey to focus on his writing of code (and later reading of it) to do it in the style he preferred, i'm happy enough to have gotten to use it as well as study it.


hindol: If I was using this technique, and found a part of the code that I wanted to discuss with others, then it is on me to communicate the actual location in the "true" code base, not my transformed version that I use to read it.


I realised I assumed some of the things that you weren't even trying to say. What you are saying makes sense.


no worries. It is easy to realize things that can go wrong with using some proposed technique, and assume the other person is suggesting using the technique without realizing those potential problems.


And often as a helpful engineer, you want warn others about potential pitfalls.

👍 4