Fork me on GitHub
#beginners
<
2019-09-11
>
SoV400:09:35

Hi everybody ! anybody got any issues ?

zugnush00:09:11

I'm trying to programatically build specs to match the data types of my target system The second form below fails `Assert failed: k must be namespaced keyword or resolvable symbol (c/and (ident? k) (namespace k))` even though the first parameter to both is a qualified-keyword `(s/def foo string?) (s/def (keyword (namespace here) (name :foo)) string?)` Is there a better way to go about this?

alexmiller00:09:09

s/def is a macro and expects forms, not things to evaluate so most stuff like this won't work well

alexmiller00:09:23

you can wrap it in another macro or use eval

SoV400:09:27

yeah are you making a macro that is gonna write spec code that gets expanded later?

alexmiller00:09:36

spec 2 has much more extensive support for this

SoV400:09:50

o.o spec2

zugnush00:09:38

Thanks for the explaination, I'll try one of those options

Paul05:09:38

Hey folks 👋 ! Is there a big-ish JSON-API that's open source that one could take a look at were one to write such a thing?

jumar12:09:53

I assume you ask for a Clojure app. Although I know nothing about this one it looks interesting: https://github.com/yogthos/krueger

Paul13:09:29

@U06BE1L6T yes should be written in clojure sorry 😅 krueger looks like you can get some good api basics from it but nothing too major. The reason I ask is that, while learning Ruby, I could always have a look at the source code for gitlab to how a well established, commercial app solved some of the issues I had. I was hoping for something in that vein for clojure as well

jumar13:09:12

I don't think you're going to find such a large commercial open-source example

jumar13:09:21

What scalewe're talking about?

jumar13:09:19

(especially for #beginners ?)

jumar13:09:12

@UBEP9B508 After scanning quite a few projects I think metabase could serve as an example: https://github.com/metabase/metabase/tree/master/src/metabase/api But again, it can also be misleading especially if we're talking about #beginners

Paul13:09:41

Thanks! Thats exactly the scale I'm talking about. You're right that this may be a bit much for the #beginners , but I do consider myself a beginner so 😅

iecya14:09:57

hi everyone, I am struggling with STDIn and STDOUT in Clojure, hope you can help me. The problem is that I have a multiline STDIN, like this for example:

line 1
line 2
line 3
let's say i want to print only the line number for each line only after all the lines have been input in the STDIN, so that the results is this:
;; input
line 1 
line 2
line 3

;; output
1
2
3

johnjelinek17:09:07

echo -n 'line 1\nline 2\nline 3\n' | clojure in.clj
1
2
3
in.clj:
(import ( BufferedReader))

(doseq [ln (line-seq (BufferedReader. *in*))]
  (-> (clojure.string/split ln #" ")
      second
      read-string
      prn)) 

johnjelinek17:09:32

@U3D7T0REF: is this what you are looking for?

iecya17:09:05

mm i think so, however i need to wrap it in my main- fn. at the moment i start my app with lein run <args> (i need one arg to do some stuff), then i use the following:

(with-open [reader (io/reader *in*)]
        (println "Please insert your input:")
        (doall (map (partial process-line time) (line-seq reader))))
the doall do the trick of printing everything at the end, while doseq was printing the result after each new line of the stdin. this kind of works, however i can never "exit" the stdin without shutting down the whole app (using System/exit) :S

iecya17:09:54

nvm, i think I got it! 😄 many thanks @U0FEHF1RS!

johnjelinek17:09:27

in.clj with io/reader instead of BufferedReader:

(doseq [ln (line-seq ( *in*))]
  (-> (clojure.string/split ln #" ")
      second
      read-string
      prn))

iecya19:09:23

i also tried with io/reader but still couldn't get out of the stdin input, both from the app and the from the repl :S however, i was focusing too much on the user's input after starting the app with lein run instead of the echo/`cat` commands. now the app works both ways, will decide if i want to keep the System/exit to exit the app after lein run

iecya14:09:01

read-line and line-seq with doseq process one line at a time, and the result is something like:

line 1
1
line 2
2
line 3
3

Adrian Smith16:09:16

is there a good way to do rename-keys but I'd like to use regex to change the keys

Adrian Smith16:09:43

for some reason Datomic ions is giving me system parameters like

{"/hello" "world"}
where I'd like
{"hello" "world"}

Markus Kiili17:09:46

@sfyire One way that seems to work is mapping the keys with a string function (zipmap (map #(clojure.string/replace % #"/" "") (keys m)) (vals m))

Mario C.18:09:58

How can I include a clj script file in another one?

alexmiller18:09:08

look at load or load-file

alexmiller18:09:26

probably the latter if you're doing file stuff

Mario C.18:09:03

I want to re-use functions defined in another script'

Mario C.18:09:21

But these scripts dont have namespaces so my world is upside down in terms of understanding

Mario C.18:09:23

I think this what I am looking for

alexmiller18:09:45

load-file is just like typing that stuff in in the current namespace context

alexmiller18:09:05

(probably user effectively)

David Pham21:09:57

Anyone could point me how I could interop C/C++ with Clojure? :)

zygon421:09:55

I can't imagine it's any different than regular JNI..

zygon421:09:13

Are you familiar with JNI?

David Pham21:09:23

Not at all :)

David Pham21:09:40

I am big JVM newbee

zygon421:09:48

That's the java native interface for calling into C/C++

zygon421:09:04

but.. it's a bit of an advanced topic

David Pham21:09:07

What is the difference with JNA?

zygon421:09:10

I'm not familiar with JNA, JNA looks like a wrapper on top of JNI

zygon421:09:46

Maybe JNA is easier to get started with than JNI?

chepprey21:09:18

For a JVM newbee, I would strongly recommend JNA for C/++ interop. JNI is a cumbersome bear. I'd start purely with a small Java project first, get your JNA interop working & proven out. Then go to Clojure and interop with your Java (which should be an easier last-step). Then watch Inception.

hiredman21:09:42

you may also want to check out tools like swig

hiredman21:09:39

https://github.com/jnr/jnr-ffi is also a neat thing, which I have never actually used, but I get the sense it is intended to provide a good ffi experience on the jvm (I think the jruby uses it for ffi stuff)

pferron23:09:15

Hello everyone. Question: this fails with a syntax error, but looks like it should work:

(->> (constantly 1)
     ())
Looking at the source code at https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L1696 it's quite clear why it fails, (first form) is nil. I'm not sure why the source code uses (~(first form) [email protected](next form) ~x) instead of a simple ([email protected] ~x) though. Any ideas?

seancorfield23:09:35

Hmm, I remember that being discussed somewhere at one time but I can't remember where right now...