Fork me on GitHub
#clojure
<
2020-02-07
>
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.

leonoel07:02:11

@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"
  [email]
  (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?

pauldub15:02:16

You can define a function

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

lukasz15:02:38

something like this?

pauldub15:02:24

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.

lukasz15:02:14

> Simplest solutions are the best first solutions

sparkofreason17:02:26

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.

hiredman17:02:02

compile doesn't do that

hiredman17:02:15

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

sparkofreason17:02:06

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... https://cjohansen.no/clojure-in-production-tools-deps/

hiredman17:02:41

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

hiredman17:02:29

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

sparkofreason17:02:11

That was it. Thanks.

arohner19:02:18

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?

noisesmith19:02:52

why not defrecord?

arohner19:02:02

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

noisesmith19:02:26

(map->CloseableMap m)

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

hiredman19:02:55

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

noisesmith20:02:37

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

emccue20:02:21

@arohner I have this dodgey code from earlier

emccue20:02:03

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

mac0102120:02:59

(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?

noisesmith21:02:24

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

noisesmith21:02:50

@mac01021

user=> (defn make-adder-form [type] `(fn [~(with-meta 'i {:type type})] (+ 2 ~'i)))
#'user/make-adder-form
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))"

noisesmith21:02:30

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

jmckitrick22:02:50

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

shaun-mahood22:02:19

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

jmckitrick22:02:51

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

noisesmith22:02:43

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

jmckitrick22:02:50

How do you handle deployment?

jmckitrick22:02:00

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

shaun-mahood22:02:44

Yes, forgot to mention that part - I also forgot to mention that I'm using aero for config files (managing passwords as shown in https://github.com/juxt/aero#hide-passwords-in-local-private-files). Copy the config files over manually before deployment.

nlloyd22:02:38

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

noisesmith22:02:05

it invokes get

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

nlloyd22:02:31

Ah thanks. This was hard for me to google

emccue23:02:53

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 :)

andy.fingerhut23:02:48

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

andy.fingerhut23:02:10

And I never saw it before reading Clojure source code, but Whitesmith's indentation style is a thing that existed before Clojure: https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style

andy.fingerhut23:02:26

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
Cameron00:02:08

I was wondering what was up with the clojure indentation

Cameron00:02:17

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

andy.fingerhut00:02:27

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.

Kamuela00:02:53

Ouch, the diffs though

andy.fingerhut00:02:38

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

andy.fingerhut00:02:56

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

sogaiu02:02:43

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

hindol09:02:15

Hope you are sarcastic, I really do.

andy.fingerhut09:02:25

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]

andy.fingerhut09:02:43

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]"

sogaiu09:02:21

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!

hindol10:02:06

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.

hindol10:02:08

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?

sogaiu10:02:02

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.

andy.fingerhut20:02:31

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.

hindol20:02:51

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

andy.fingerhut20:02:39

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.

andy.fingerhut20:02:14

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

👍 4