Fork me on GitHub
#clojure
<
2019-02-13
>
Gordon08:02:48

Hey, can we generate an Clojure Server from swagger definition?

ikitommi10:02:32

@g0rd0n don’t think so. Have been waiting for someone to take a stab at this. The thing missing is that swagger defines parameters & responses in swagger json schema, while most Clojure web libs use Schema or clojure.spec as the idiomatic way to describe those. Generator would need to convert the params. Just the paths, libs like org.zalando/swagger1st and metosin/reitit both use the swagger path format, so the transformation should be quite trivial.

ikitommi10:02:42

(co-authoring reitit, so happy to help if you would like to do the converter for it)

Yehonathan Sharvit13:02:54

A question related to the REPL: I’d like to write a small Clojure program that opens an JSON file and allows me to investigate the content of the JSON as a Clojure object in the REPL. I was thinking of creating a core.clj file with a -main function that receives the path to the JSON file as an argument and define a core.data var that contains the Clojure representation of the JSON file. My problem is that I cannot when I pass -m core to the REPL, it runs the program and exits. I’d like the REPL to stay open. Is that feasible?

dominicm13:02:02

You could call clojure.main/repl in your main

Yehonathan Sharvit14:02:40

Yeah. I thought about that but somehow I was expecting to find a simpler solution @dominicm

dominicm14:02:26

@viebel you could use -e instead of -m

Yehonathan Sharvit15:02:02

@dominicm can we have access to command line arguments with -e?

Alex Miller (Clojure team)15:02:47

$ clj -e "(println *command-line-args*)" -m foo 1 2 3
(1 2 3)

Yehonathan Sharvit18:02:20

@alexmiller awesome This is exactly what I was looking for

Yehonathan Sharvit18:02:23

And with -r, I can open a REPL

➜  ~ clj -e "(ns my.aa) (def a 1)" -r
#'my.aa/a
my.aa=> a
1
my.aa=>
Now, I am wondering why -m is not compatible with -r?

Alex Miller (Clojure team)19:02:52

-m starts a program, -r starts a repl

Alex Miller (Clojure team)19:02:06

they are different modes

Alex Miller (Clojure team)19:02:56

or you can pass a path to run a clj script or - for stdin

Alex Miller (Clojure team)19:02:55

-e is an initial option that happens before those (and can be used more than once)

NoahTheDuke19:02:18

Let's say I have a macro that defines a bunch of local variables for easy of use. Is it possible to conditionally bind them only if they're used in the body?

hmaurer20:02:24

Is there a built-in clojure function that has the following effect?

(f [] 0) ; => []
(f [1] 0) ; => [1 0]
(f [1 2] 0) ; => [1 0 2 0]
(f [1 2 3] 0) ; => [1 0 2 0 3 0]
Almost interpose but with the separator also added to the end when the sequence is not empty

nwjsmith20:02:20

There isn’t

nwjsmith20:02:06

> added to the end Does it have to be the last item in the seq, or should it be conjed?

valtteri20:02:18

Would (interleave [1 2 3] (repeat 0)) work?

5
hmaurer20:02:24

@valtteri oh wow; that works

hmaurer20:02:36

thanks!

👌 5
conaw23:02:55

I’m trying to figure out how to write a macro that will return a quoted vector of the arguments passed to it Example ` (quote-me [:user/id]) ;;-> ’[:user/id] any ideas?

nwjsmith23:02:49

=> (doc quote)
-------------------------
quote
  (quote form)
Special Form
  Yields the unevaluated form.

  Please see 
  Yields the unevaluated form.

nwjsmith23:02:16

^ I think quote is what you’re looking for

noisesmith23:02:12

@conaw '[:foo] and [:foo] are already equal - there's a difference for symbols, the macro you want for that is quote, which is what ' expands to

noisesmith23:02:42

also that's not a quoted vector of the arguments, that's taking a vector and returning it

conaw23:02:08

This doesn’t seem to work for the function I’m trying to pass the return value into

conaw23:02:21

as in, I need to pass it in as quoted

noisesmith23:02:58

quoting is a compilation time operation that prevents evaluation of literal forms in your source code

noisesmith23:02:13

it doesn't have a meaning at runtime, unless you are using runtime eval

noisesmith23:02:42

I might be misunderstanding what you are trying to do here

Robert Nikander23:02:49

Sounds like you're asking for an extra level of quote, like (defmacro foo [x] `(quote (quote ~x)))` (foo [:user/id]) ==> '[:user/id]. Like your example.

Robert Nikander23:02:16

Oh... looks like I don't know how to put code in slack.

conaw23:02:31

turns out didn’t need to use a macro

conaw23:02:33

(deftrack a [b conn id] (b @(posh/pull conn `[~b] id)) )

conaw23:02:36

this did what I wanted

noisesmith23:02:26

what do you expect

`[~b]
to do that [b] wouldn't?

conaw23:02:39

get accepted by datascript

noisesmith23:02:01

how would datascript see a difference?

conaw23:02:09

yeah, think you’re actually right

conaw23:02:58

I think it is more because datascript allows things in the pull and query that would otherwise get evaluted

noisesmith23:02:24

sure, quote those things if you need their unevaluated meaning

conaw23:02:44

for the toy example just putting it in directly works fine

noisesmith23:02:46

and quasiquote can help build a partially quoted data structure with selective evaluation, without needing a macro

conaw23:02:58

its for building up the more complicated queries and pulls that I need the ` and ~

noisesmith23:02:58

right, and you don't actually want a macro for that - you just want a convenient syntax for selective quoting

conaw23:02:40

yeah, hadn’t realized I could use ` and ~ outside of macros