Fork me on GitHub
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

Hmm... any pointers why this might happen?

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


Got it: *print-meta*

Alex Miller (Clojure team)14:05:00

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


This worked:

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

Alex Miller (Clojure team)14:05:56

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


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


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


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


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


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


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


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


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?


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


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


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


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 


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.


Try skipping the underscore prefix


Same issue with sci_meta and scimeta. Here's the code I tried:


Ah right :(


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.


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


What are you trying to do exactly? You can use something like Sendgrid's Parse Webhook to expose a web service that receives emails If you're looking for a queryable local SMTP server that you can use in integration tests you can try


> 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


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


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)


We have some processes that fetch mail and process attachments


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


How do I fix this error? Looks like cheshire is finding it difficult to convert "class" to JSON. Thanks for any hint. [{:type com.fasterxml.jackson.core.JsonGenerationException :message "Cannot JSON encode object of class: class" :at [cheshire.generate$generate invokeStatic "generate.clj" 155]}]


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 cheshire-gen/encode-str)
Thanks a bunch.

👍 1

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


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


mainly I'm interested in sending chunked HTTP responses, e.g.


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?


trying to pick one to program against for a library


looks like I could use jetty and raw InputStreams

👀 1

Yea. I would be surprised if you couldn't do chunked responses with jetty. There's some examples for teh ring-jetty-adapter,


Pedestal has interesting options involving clojure.core.async: