Fork me on GitHub
#beginners
<
2021-08-28
>
seancorfield00:08:30

I'd say "best practice" is to just not do that sort of thing.

seancorfield00:08:58

But is possible if you essentially parse the options a bit:

dev=> (defn fullname
 #_=>   [first-or-last & opts]
 #_=>   (let [[firstname lastname & {:keys [name-title middlename]}] 
 #_=>         (if (or (empty? opts) (keyword? (first opts))) 
 #_=>           (into ["Mr " first-or-last] opts) 
 #_=>           (into [first-or-last] opts))]
 #_=>         (str (when name-title (str name-title " "))
 #_=>         firstname
 #_=>         (if middlename middlename " ")
 #_=>         lastname)))
Needs work on the whitespace separation but it basically "works"

seancorfield00:08:41

(edited the code and tested it in a REPL)

Jon Boone00:08:44

Too new to Clojure to comment intelligently on this, but in CL, I’d use keyword arguments with default values…

seancorfield00:08:25

@ipmonger The issue here is that the OP wants either one or two positional arguments before the keyword arguments.

seancorfield00:08:57

So their function is essentially "doubly variadic" which you can't do (in Clojure).

seancorfield00:08:37

Another option would be to pass those keywords as a hash map and to require {} when none are being passed -- then the function either takes two or three positional arguments (`[firstname opts]` or [firstname lastname opts]). There are other options but everything's a trade off at this point.

olaf01:08:55

Becomes difficult to distinguish between [firstname opts] and [lastname opts]. So I think what is a strictly required parameter can be positional, what is optional should be a keyword arguments (or a map) [lastname & {:keys [firstname middlename name-title]}] .

closure-is-overrated01:08:03

got a question with luminus. how do you apply code changes without restarting lein run? is there a way?

closure-is-overrated01:08:51

@U04V70XH6 hmm that's a new workflow for me. so you mean you just start the app from the REPL e.g. (start) from the user namespace then when you launch the browser the app works?

seancorfield01:08:33

Pretty much, yes.

closure-is-overrated08:08:13

that’s cool. seems super fast in terms of development speed @U04V70XH6

closure-is-overrated08:08:37

any articles, videos on the internet you can give me to demonstrate this workflow? @U04V70XH6

seancorfield13:08:40

Stu Halloway has a great video on REPL-Driven Development. I've also posted several -- some short ones on my YouTube channel and a couple of longer ones for online Clojure Meetup groups.

closure-is-overrated23:08:13

@U04V70XH6 very nice! ok I will look at these videos. thanks very much!

seancorfield06:08:19

If copy-to-old and copy-to-rest are side-effecting, you shouldn't really be using map at all. Or are they pure data transforms?

seancorfield06:08:04

Looking at that, I assume chatroom-id is actually a sequence of IDs and so is old-id (so maybe -ids would be less confusing naming?).

seancorfield06:08:13

Perhaps you can explain a bit more context about what's going on here?

finchharold07:08:59

For all the different ids the function gives out true or false

finchharold07:08:19

and for each of those true or false the if should run the below functions

ChillPillzKillzBillz11:08:46

I am trying to explore clojure.spec... and one of the first things I wanted to valid was the structure of a hash-map... Example hash-map :

{:id "a" :text "a" :x 2 :y 5}
The spec definition so far is asa follows
(s/def ::id string?)
(s/def ::text string?)
(s/def ::x int?)
(s/def ::y int?)
(s/def ::init_state
       (s/keys :req [::id ::text ::x ::y]))
Yet when I run the following, I get error:
=> (s/valid? ::init_state {:id "asdf" :text "asdf" :x 2 :y 5})
false
=> (s/explain ::init_state {:id "asdf" :text "asdf" :x 2 :y 5})
{:id "asdf", :text "asdf", :x 2, :y 5} - failed: (contains? % :cljs.user/id) spec: :cljs.user/init_state
{:id "asdf", :text "asdf", :x 2, :y 5} - failed: (contains? % :cljs.user/text) spec: :cljs.user/init_state
{:id "asdf", :text "asdf", :x 2, :y 5} - failed: (contains? % :cljs.user/x) spec: :cljs.user/init_state
{:id "asdf", :text "asdf", :x 2, :y 5} - failed: (contains? % :cljs.user/y) spec: :cljs.user/init_state
nil
What is going on?

ChillPillzKillzBillz12:08:34

Is there a spec qualifier to check if a value is a chan ... like from core.async?

West14:08:30

Does anyone know how SMTP works? I was able to send myself an MMS message on my local machine using tarayo. Now the only reason it worked was because I was using protonmail bridge. I figured I could send an email from sharklasers or something, but that ended up not working. Really what I want is push notifications to my phone, but programmatically. Eventually I’ll have the service running 24/7 on my raspberry pi. How can I set this up?

West12:08:08

I just found https://gotify.net/! It has a rest api and has an android app on F-droid. Seems perfect for my purposes.

partywombat 4
Anders Persson18:08:08

Witch database solution is best for beginners, i like to focus on clojure world but have to load and save data somewhere.

dpsutton18:08:35

They will largely be the same behind the lib you use to access them. Next.jdbc will look almost identical. Go with the one you are most comfortable with. I love pg but still get annoyed at user permissions on it. MySQL, SQLite, whatever

emccue21:08:33

One thing i think it was practical lisp did was just make the database part of the tutorial

emccue21:08:49

just slurp and spit would be pretty decent

deleted21:08:39

isn't there a db built in? h2 or something?

practicalli-johnny19:08:29

H2 database is self-contained in a library and works very nicely with next.jdbc. it can be in memory only or also write the dB to files. I use H2 when developing as it is extremely light on resources and has more than enough features to bootstrap an app

hiredman21:08:01

Apache derby was shipped with the jdk as javadb for a short time. Derby is nice, and native to the jvm (no native code needed like with the different sqlite drivers). If you want an embedded sql database it is a good one.

ChillPillzKillzBillz22:08:56

Is there a way to reset the counter on gensym?

emccue22:08:32

technically yes, with reflection and madness - at least on the JVM

emccue22:08:22

its this static atomic integer

emccue22:08:35

if you use reflection to access it, you can reset it

emccue22:08:42

but also, don't?

jimmysit023:08:47

What ways do I have to "operate" on `*out*` without using . as an operator

sova-soars-the-sora23:08:24

@jimmyssj3 hi not sure what you mean. There is with-out-str that I learned about recently thanks to @deleted-user but I don't know if that's relevant to what you are tryna do.

jimmysit017:08:15

@U051SS2EU I'd like to get the current value of *out without using . , as pr does: (. *out* (append \space)) my goal here is to code my own implementation of pr

noisesmith02:08:10

*out* is the current value of out, that interop is just writing a single space. anyway print writes to *out* without using interop.