Fork me on GitHub

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


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"


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


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


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


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.


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]}] .


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


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


Pretty much, yes.


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


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


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.


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


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?


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?).


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


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


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


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})
=> (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
What is going on?


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


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?


I just found! 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.


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


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


just slurp and spit would be pretty decent


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


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


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.


Is there a way to reset the counter on gensym?


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


its this static atomic integer


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


but also, don't?


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


@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.


@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


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