Fork me on GitHub
#clojure
<
2022-05-15
>
Benjamin C00:05:43

I'm curious if anyone knows about a tool to automatically merge .clj and .cljs files into a .cljc file?

👀 4
borkdude14:05:55

Hmm... any pointers why this might happen?

user=> (spit "/tmp/rec.clj" (with-out-str (clojure.pprint/pprint (macroexpand-1 '(defrecord Rec [])))))
nil
user=> (load-file "/tmp/rec.clj")
Syntax error (VerifyError) compiling . at (/tmp/rec.clj:41:4).
Bad type on operand stack

borkdude14:05:52

Got it: *print-meta*

Alex Miller (Clojure team)14:05:00

Well if you have a repro, please file an ask question

borkdude14:05:24

This worked:

user=> (spit "/tmp/rec.clj" (with-out-str (binding [*print-meta* true] (clojure.pprint/pprint (macroexpand-1 '(defrecord Rec []))))))
nil
user=> (load-file "/tmp/rec.clj")
user.Rec

Alex Miller (Clojure team)14:05:56

A VerifyError should almost always be considered a bug in the compiler

borkdude14:05:25

My use case for the above: I want something like defrecord (in SCI) but with more implementation data on that. I could use metadata (which I'm doing right now) but sometimes people use with-meta on the record and it wipes the implementation data. So I thought, maybe I could use the code generated by defrecord and add a few fields of my own...

borkdude14:05:37

If there is a more light weight solution to that, I'd love to use that

borkdude14:05:48

So in general terms: I want to create a record that has some fields that should not show up in the ILookup nor in the metadata of the record, basically a hybrid between defrecord and deftype

borkdude14:05:25

I guess I could also try to add those fields to the ext-map and override print-method or so to not print those, but it does feel more like metadata than anything else

borkdude14:05:22

I'm going to a thread now to reduce noise. 🧵

borkdude14:05:58

I'm trying to add a field _sci_meta to the above output. This yields:

Syntax error (ClassFormatError) compiling deftype* at (/tmp/rec.clj:5:2).
Duplicate method name "<init>" with signature "(Ljava.lang.Object;Ljava.lang.Object;Ljava.lang.Object;)V" in class file compile__stub/user/Rec

borkdude14:05:16

I updated all the constructor calls, but I'm not sure where the constructor itself is being generated

Alex Miller (Clojure team)14:05:04

it's in the compiler, so not sure you're going to be able to do that

1
borkdude15:05:13

I don't understand: I'm basically doing the same as defrecord which emits code that runs deftype* - is there some magic Compiler stuff going on besides that?

ghadi15:05:40

You could find out by comparing the macroexpansion against the datafied class

borkdude15:05:24

Can do that. Can also copy emit-defrecord , that might be less error prone than editing what it generates

Alex Miller (Clojure team)15:05:19

there's a special temporary stub class that gets generated under deftype* (note the compile__stub there) - that's all in the Compiler

borkdude15:05:25

ok, so the emit-defrecord stuff isn't that generalizable as there is special support for it in the Compiler only for a specific set of cases?

Alex Miller (Clojure team)16:05:05

it's not intended as public api so maybe not as general as you would like

borkdude16:05:02

yeah I get that :) I copied emit-defrecord to emit-defrecord2 and added a field __sci_meta (and to every place which removes those built-in field names to separate them from user fields)

user=> (eval (emit-defrecord2 'Foo 'Foo '[] nil nil {}))
Syntax error (ClassFormatError) compiling deftype* at (REPL:1:1).
Duplicate method name "<init>" with signature "(Ljava.lang.Object;Ljava.lang.Object;Ljava.lang.Object;)V" in class file compile__stub/user/Foo 

borkdude16:05:34

so there's probably an assumption in the Compiler about the amount of of built-in fields or so. No problem, this was just me exploring if this was a feasible option.

ghadi16:05:10

Try skipping the underscore prefix

borkdude16:05:51

Same issue with sci_meta and scimeta. Here's the code I tried: https://gist.github.com/borkdude/19ac04ea0b2ef9d6643ba3de6817de57

borkdude18:05:16

Ah right :(

borkdude09:05:23

I'm going to need something else than metadata anyways, since different types are not equal and the type info is currently stored in the metadata which does not affect equivalence... But storing the type info in a field in the record itself affects into etc: this info is preserved... So a tweaked defrecord is probably the way forward - even if I cannot add fields of my own (I still don't fully get why that isn't possible), I can tweak the protocol/interface methods a bit to make it work.

emccue15:05:51

Does anyone have any experience receiving emails with any sort of clojure/java/node api? I'm in a bit of a cursed integration testing scenario and I don't see another way out

lukasz16:05:38

What are you trying to do exactly? You can use something like Sendgrid's Parse Webhook to expose a web service that receives emails https://docs.sendgrid.com/for-developers/parsing-email/setting-up-the-inbound-parse-webhook If you're looking for a queryable local SMTP server that you can use in integration tests you can try https://github.com/mailhog/MailHog

emccue17:05:55

> What are you trying to do exactly? I'm trying to navigate an email based auth mechanism. So i want to run a machine and get the emails and parse out the needed info

lukasz18:05:38

and is that for some other service that you need to auth into?

lukasz18:05:30

Sounds like setting up a web service + the Sendgrid parse webhook would give you that - then you receive http callbacks to your endpoint with all of the email info (envelope, various content types etc)

domparry15:05:36

We have some processes that fetch mail and process attachments

emccue15:05:14

I'm trying to do this all in memory. No gmail or whatever

hkrish20:05:25

How do I fix this error? Looks like cheshire is finding it difficult to convert "class http://java.net.URL" to JSON. Thanks for any hint. [{:type com.fasterxml.jackson.core.JsonGenerationException :message "Cannot JSON encode object of class: class java.net.URL: https://xxxxxxxx.s3.us-west-2.amazonaws.com/xxxxxxxxxxxxxxxx" :at [cheshire.generate$generate invokeStatic "generate.clj" 155]}]

hkrish21:05:43

Thank you so much. It really helped/worked. What I did is (:require

[cheshire.core :refer :all]
[cheshire.generate :as cheshire-gen]
....) Then added this line
(cheshire-gen/add-encoder java.net.URL cheshire-gen/encode-str)
Thanks a bunch.

👍 1
lilactown20:05:39

what's the current state of the art for streaming web servers? I know of manifold + aleph. is that still the best bet?

phronmophobic20:05:24

what kind of streaming? • media (audio/video) • long polling • web sockets • large files

lilactown20:05:47

mainly I'm interested in sending chunked HTTP responses, e.g. https://www.mariokandut.com/how-to-stream-to-an-http-response-in-node-js/

phronmophobic20:05:20

I thought that was available for most web servers. Are you already using a particular web server or are you trying to pick one with at least this capability?

lilactown20:05:23

trying to pick one to program against for a library

lilactown20:05:23

looks like I could use jetty and raw InputStreams

👀 1
phronmophobic20:05:34

Yea. I would be surprised if you couldn't do chunked responses with jetty. There's some examples for teh ring-jetty-adapter, https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/test/ring/adapter/test/jetty.clj

phill22:05:05

Pedestal has interesting options involving clojure.core.async: http://pedestal.io/reference/streaming