Fork me on GitHub
#beginners
<
2019-01-17
>
noisesmith00:01:17

eg. (cons x (when ...)) relies on nil both being falsey and acting like an empty list for cons

noisesmith00:01:29

(commonly seen in lazy seq generation)

Kelsey Sorrels04:01:43

Hi. I'm looking for some feedback. Core.match is great, but I'm getting the sense that I'm abusing it. How would you refactor this https://github.com/aaron-santos/robinson/blob/master/src/robinson/ui/cell.clj#L64 ?

jaihindhreddy-duplicate10:01:14

I would personally break it down into these three vars:

dpsutton04:01:10

so you never care about the water level being less than 10. and then you only care about a trap is found in two cases. \O becomes \~ and \. becomes \^. So really you can just have a direct table of cell type to character and if a trap is found and its a symbol that has a trap-found modifier, do that

dpsutton04:01:00

(defn cell->cp437-character [c trap?] (let [base (cell-lookup c)] (if trap? (trap-lookup c c) c)

dpsutton04:01:16

"look up the base character. if there's a trap, see if there's a special trap symbol (`{\O \~ \. \^}`) else return c"

Kelsey Sorrels04:01:23

Great point! I'll try that out. Thank you

nikola13:01:24

do I understand correctly that if I call nth on a lazy sequence, it will be realized only once?

Alex Miller (Clojure team)13:01:19

sequences are cached as they’re computed so you never realize an element of the sequence more than once

nikola13:01:09

by "it" I mean the sequence up to the nth element

JanisOlex13:01:47

hey, trying to use clojure gradle plugin, and when I run gradlew.bat build my clojure .clj ends up in the jar, and looks like whole clojure also, but I don't see gen-class(ed) class produced... what do I miss?

FlavaDave16:01:23

Hey all, I’m having some trouble using react native with clojurescript. I’ve tried using it with expo and re-natal and keep getting errors. When I use lein new expo “projectname” it will make the project but when I do the && yarn install it returns: “react-native > metro > @babel/[email protected]" has incorrect peer dependency “@babel/[email protected]”. When I try and use re-natal, I get “command failed: lein prod-build. Any thoughts?

Dustin Lahr18:01:06

Hey @dgonsalves22 I don't know if this will help, but I just found

In that he mentions the incorrect peer dependency issue you are having. To solve it, in your case you may need to add
@babel/[email protected]
to your package.json. Literally new to all of this, but came across that. So, I hope it helps!

Daniel Hines18:01:26

I might need to post the actual code I wrote, but does anyone know why my loop/recur form that paged through objects in an S3 bucket just caused CIDER to hang this morning? I fixed it by switching to normal recursion. Am I missing something about loop/recur

manutter5118:01:26

Sounds like it got into an infinite loop somehow.

Daniel Hines18:01:13

Yeah… I thought I had my early exit correct, but you’re probably right. But in theory, there’s nothing wrong with loop/recur, even for tasks that may take a few seconds per loop, right?

mrjames19:01:15

Anyone using electron-builder - app is Clojure-Script(Reagent)?

Machado23:01:49

Hey, folks, night!

Machado23:01:06

I'd like a function with multi-arity and named arguments

Machado23:01:12

but I've been struggling a little with it

Machado23:01:15

user=> (defn whatever-function [] (prn 123)
  #_=> [& {:keys argument-1}] (prn argument-1))

Machado23:01:59

so I'd call this like (whatever-function :argument-1 123)

Machado23:01:43

and later on I could do something like this

user=> (defn whatever-function [] (prn 123)
  #_=> [& {:keys argument-1}] (prn argument-1)
  #_=> [& {:keys argument-2 argument-3}] (prn argument-2))

Machado23:01:58

so I'd not need to necessary the order of the arguments

Machado23:01:05

does that makes any sense?

noisesmith23:01:09

you can't have an empty arg list and all args optional as arities

noisesmith23:01:34

also arity dispatch can't select based on presence or absence of keys

Machado23:01:39

I want to create a Person that has name age and address

noisesmith23:01:41

maybe you want a multimethod?

Machado23:01:46

you always need to provide a name

Machado23:01:55

but sometimes only the address other times the ages

Machado23:01:01

and sometimes both address and age

Machado23:01:23

Not sure what is multimethod

noisesmith23:01:04

a multimethod can differentiate between an empty arg list and optional keys, regular arity dispatch can't

noisesmith23:01:40

@pmachadogabriel the key with multimethods is you write at least two functions - one that looks at all your args and decides how to dispatch, and another that gets called when a given dispatch is matched

hiredman23:01:05

or don't use & {} use {} and pass a map

5
hiredman23:01:52

passing maps is better anyway

Machado23:01:07

thanks a lot @noisesmith I feel that this is what I was looking for

Machado23:01:37

@hiredman not feeling to go in this way since I consider a trick

Machado23:01:47

not something maintainable

Machado23:01:02

JS uses it a lot to handle nil values

hiredman23:01:12

passing a map is way more maintainible

hiredman23:01:24

I think you are misunderstanding what I mean

hiredman23:01:14

(defn f
  ([] no args)
  ([{:keys [...]}] map passed as args))

hiredman23:01:08

in general, if you do the & {} thing for named args, at some point you will want to apply that function, and you will have to write mapply, and it is silly

Machado23:01:02

So I'm building a silly project like a CRUD API

Machado23:01:18

but I can't find any open source project to gather some info about common practices

Machado23:01:32

or even any standards

borkdude23:01:04

@pmachadogabriel there are several libraries to build REST stuff, e.g. yada

Machado23:01:27

I'm not missing the libs, I'm missing some "example projects"

Machado23:01:33

to have some guidance

Machado23:01:48

I've background on elixir

Machado23:01:13

So what I was trying to achieve was some pattern matching whenever a parameter is nil

Machado23:01:43

and I've managed to find core.match, but I'm not sure if its a idiomatic way to write clojure

noisesmith23:01:54

FWIW Rich Hickey has extensive arguments for why he didn't implement matching in clojure.core, and why he thinks people should use multimethods instead of pattern matching.

Dustin Lahr23:01:56

Hey @noisesmith is there any talks or articles about that? I would be interesting in reading them

noisesmith23:01:48

I'm sure the talk is on youtube... I'll have to remember which one it was

Alex Miller (Clojure team)23:01:18

I think the executive summary is that it’s not predictably fast

Machado23:01:57

user=> (defmulti create-person (fn [data] {:age (contains? data :age)  :height  (contains? data :age)}))
user=> (defmethod create-person {:age true :height true} [_] (prn "age and height"))
user=> (create-person {:age 10 :height 10})
"age and height"

Machado23:01:04

@noisesmith I've come up with this

Machado23:01:16

can I enhance it?

Machado23:01:34

But now it clicked on how to use the defmulti, again, thanks a lot!

noisesmith23:01:30

you can create a :default method (defmethod create-person :default ...) for the most generic case

Machado23:01:49

and what about this {:age true :height true}?

noisesmith23:01:54

but in your case there are only 4 possible method implementations

noisesmith23:01:05

yeah, that makes sense as a dispatch value