Fork me on GitHub
#beginners
<
2019-12-05
>
ScArcher03:12:49

If I want to generate a set of numbers between two known numbers, what's the best way to do that?

(apply range (sort [x y]))
Would this be an appropriate way to go about this?

seancorfield03:12:00

@scott.archer Randomly generated? Any constraints?

seancorfield03:12:47

(and do you actually want a set or just a sequence?)

ScArcher03:12:11

Not randomly generated, given 5 and 100 I would need numbers 5 through 100. Given -8 through 5 I would need the numbers -8 through 5.

ScArcher03:12:19

A sequence or set is fine.

seancorfield03:12:04

(range (min x y) (max x y)) or (apply range (sort [x y])) both seem reasonable then

ScArcher03:12:34

Min max is better I think as that way I can increment the max by 1 to account for the way range works. Thanks!

seancorfield03:12:12

Yup, depending on whether you need inclusive/exclusive range ends...

ScArcher03:12:23

Thanks again, I really appreciate the time you spend helping others!

😊 4
bartuka04:12:13

what today should be the recommended approach to create/deploy clojure functions as aws lambdas?

alex31415911:12:31

Hello - I’m struggling to eagerly read a 50mb CSV file (numbers and strings). Uses 500mb memory on first read and just runs out of memory on further reads. Have heap as -Xmx1G. What can I do? My code is

(with-open [r (io/reader path)] (doall (csv/read-csv r)))
thanks!

dharrigan12:12:52

I think doseq would solve this

dharrigan12:12:02

doall forces all into memory, doseq does one-at-a-time.

mavbozo12:12:11

looks like a great test case for iota https://github.com/thebusby/iota

indy11:12:47

Hey All, How do I use the Garden library to generate the CSS and then include it in my project? I understand (css [:h1 {:font-weight "bold"}]) will output the appropriate CSS string, but how do I create a CSS file from this and include it in my ClojureScript project?

herald11:12:11

If you're using leiningen, the author of garden has a plugin for it that handles the building for you https://github.com/noprompt/lein-garden

nitaai12:12:09

Hello. How do I remove-method which was defmethod in another namespace?

FiVo14:12:29

(remove-method namespace/multiname dis-value)?

nitaai14:12:30

No, doesn’t work. I tried that: java.lang.RuntimeException: No such var: namespace/multiname

Xiaoyu Zhang14:12:13

hello, I have a simple question, how I can run (into-array Double [ 100 200]) without element type mismatch error ? shouldn't clojure convert integer to double automatically ?

jsyrjala14:12:39

you need to convert integers to doubles. E.g this works: (into-array Double [ 100.0 200.0])

jsyrjala14:12:45

or (into-array Double (map #(.doubleValue %) [100 200]))

Xiaoyu Zhang14:12:55

what if (into-array Double INPUT-LIST) should I map the INPUT-LIST with like ' map #(to-double) INPUT-LIST '?

Xiaoyu Zhang15:12:07

yeah, that's right but looks a little bit odd, if 95% chances INPUT-LIST is floated based, then the mapping function is causing unnecessary overhead for CPU.

Xiaoyu Zhang15:12:26

thank you for your reply anyway

chadhs15:12:26

kind of a meta question… what would be the appropriate channel to share something we’ve built with Clojure?

Alex Miller (Clojure team)15:12:23

if it's a company kind of thing, would love to have a company story for http://clojure.org! https://clojure.org/community/community_stories

chadhs15:12:18

@alexmiller it’s a solo / single developer effort. a small web app i built and launched today. but wanted to ask vs just posting a product hunt link.

chadhs15:12:32

cool thanks alex!

Chase21:12:54

When checking a set for a value to use in an if statement is it more idiomatic and/or clear to use (#{values} value) or (contains? #{values} value) ? The former returns the value or nil and the latter is true or false right, but in a conditional those both kind of do the job I think.

shaun-mahood21:12:25

Check out https://guide.clojure.style/#set-as-predicate - it's a good place to figure out if you are doing things in a reasonably idiomatic way, and in this case it agrees with the way I do things normally so it must be right 🙂

Chase21:12:56

Oh wow, this looks like a great resource. And extensive! Not sure how I overlooked this one

andy.fingerhut21:12:27

Also note that if the set you are interested in checking membership in contains nil or false , then (#{values} value) will return nil or false when it successfully finds an element, whereas contains? will return true in those cases. If it is a literal compile-time constant set that contains neither nil nor false , no problem. If it is a run-time variable set that you do not know whether it contains those values, I'd recommend contains?

👍 4
Chase21:12:26

ahh, that is a great point! I was doing some advent of code stuff so the input had no nil or false values in it.

Alex Miller (Clojure team)22:12:25

In general, nil or false values in sets are an issue in many places and it’s best to just not do that ever

noisesmith23:12:16

user=> (into #{##NaN} [##NaN ##NaN])
#{##NaN ##NaN ##NaN}