Fork me on GitHub
#clojure
<
2021-04-04
>
raspasov04:04:03

Anybody know of an existing library/function that can format/print a (let …) statement like:

(let [a 1 b 2 c 3])
into
(let [a 1 
      b 2
      c 3])

vemv05:04:39

zprint

👍 3
aratare08:04:09

Hi there. Is there any way to mock a Transit request? Thanks in advance.

aratare08:04:53

Well I just used transit-clj and ring-mock and I have my requests now 🙂

clojure-spin 3
Karol Wójcik11:04:55

How tag bytes[] array in macro to get rid of reflection? ^bytes throw an error on compilation phase. > Unable to resolve classname: clojure.lang.bytes

raspasov11:04:40

Does it? (seems to work AFAICT)

(defmacro bbb [n]
  `(let [^bytes b# (byte-array ~n)]
     b#))

(defn use-macro [n]
  (bbb n))

Karol Wójcik11:04:28

(defn- wrap-lambda
  [gmethod-sym fn-args fn-body gclass]
  (let [lambda `(fn ~fn-args ~@fn-body)]
    `(do
       ~gclass
       (defn ~gmethod-sym
         ;; Arity used for testing and native runtime invocation
         ([request#]
          (~lambda request#))
         ;; Arity used for Java runtime
         ([this# ^InputStream in# ^OutputStream out# ^Context ctx#]
          (try
            (let [event# (#'fierycod.holy-lambda.util/in->edn-event in#)
                  context# (#'fierycod.holy-lambda.core/java-ctx-object->ctx-edn ctx# (#'fierycod.holy-lambda.util/envs))
                  response# (#'fierycod.holy-lambda.util/->payload-bytes
                             (~lambda {:event event#
                                       :ctx context#}))]
              (.write out# ^bytes response#))
            (catch Exception error#
              (println "[Holy Lambda] Exception during request handling" error#))
            (finally
              (.close out#))))))))
Error:
Syntax error compiling . at (hello_lambda/core.clj:6:1).
Exception in thread "main" Syntax error compiling . at (hello_lambda/core.clj:6:1).
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7114)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7094)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyze(Compiler.java:6745)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6120)
        at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6436)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7094)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyze(Compiler.java:6745)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6120)
        at clojure.lang.Compiler$TryExpr$Parser.parse(Compiler.java:2314)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyze(Compiler.java:6745)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6120)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5467)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4029)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7104)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7094)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.access$300(Compiler.java:38)
        at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:596)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
        at clojure.lang.Compiler.analyze(Compiler.java:6789)
        at clojure.lang.Compiler.analyze(Compiler.java:6745)
        at clojure.lang.Compiler.compile1(Compiler.java:7725)
        at clojure.lang.Compiler.compile1(Compiler.java:7720)
        at clojure.lang.Compiler.compile1(Compiler.java:7720)
        at clojure.lang.Compiler.compile(Compiler.java:7797)
        at clojure.lang.RT.compile(RT.java:415)
        at clojure.lang.RT.load(RT.java:461)
        at clojure.lang.RT.load(RT.java:428)
        at clojure.core$load$fn__6824.invoke(core.clj:6126)
        at clojure.core$load.invokeStatic(core.clj:6125)
        at clojure.core$load.doInvoke(core.clj:6109)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invokeStatic(core.clj:5908)
        at clojure.core$compile$fn__6829.invoke(core.clj:6136)
        at clojure.core$compile.invokeStatic(core.clj:6136)
        at clojure.core$compile.invoke(core.clj:6128)
        at user$eval157$fn__166.invoke(form-init4478117184497726207.clj:1)
        at user$eval157.invokeStatic(form-init4478117184497726207.clj:1)
        at user$eval157.invoke(form-init4478117184497726207.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:7176)
        at clojure.lang.Compiler.eval(Compiler.java:7166)
        at clojure.lang.Compiler.eval(Compiler.java:7166)
        at clojure.lang.Compiler.load(Compiler.java:7635)
        at clojure.lang.Compiler.loadFile(Compiler.java:7573)
        at clojure.main$load_script.invokeStatic(main.clj:452)
        at clojure.main$init_opt.invokeStatic(main.clj:454)
        at clojure.main$init_opt.invoke(main.clj:454)
        at clojure.main$initialize.invokeStatic(main.clj:485)
        at clojure.main$null_opt.invokeStatic(main.clj:519)
        at clojure.main$null_opt.invoke(main.clj:516)
        at clojure.main$main.invokeStatic(main.clj:598)
        at clojure.main$main.doInvoke(main.clj:561)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:705)
        at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core/bytes
        at clojure.lang.Compiler$HostExpr.tagToClass(Compiler.java:1129)
        at clojure.lang.Compiler$LocalBindingExpr.getJavaClass(Compiler.java:6087)
        at clojure.lang.Compiler.getMatchingParams(Compiler.java:2522)
        at clojure.lang.Compiler$InstanceMethodExpr.<init>(Compiler.java:1512)
        at clojure.lang.Compiler$HostExpr$Parser.parse(Compiler.java:1024)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
        ... 62 more
Compilation failed: Subprocess failed (exit code: 1)

Karol Wójcik11:04:34

@U050KSS8M It sometimes does. 😄

raspasov12:04:29

… are you positive that this error is coming out of the ^bytes?

raspasov12:04:22

(your code compiles for me…)

Karol Wójcik12:04:15

Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core/bytes
Yes I'm 100% sure. Anyway I used (bytes) on byte[] and reflection is gone.

👍 6
emccue14:04:18

(let [byte-arr ^"[B" (... your expr ...)]
   ...)

ribelo15:04:10

~(with-meta x {:tag bytes})

jaide17:04:12

Is Clojure officially regarded as a functional programming language? Like if I said “Clojure is a functional programming language”, would that be incorrect?

schmee17:04:34

@jayzawrotny you would be right, from the front-page of http://clojure.org: > […] Clojure is predominantly a functional programming language, and features a rich set of immutable, persistent data structures.

vncz17:04:54

The point is that even the definition of “functional programming” is fuzzy. For somebody means something, for somebody means another thing.

☝️ 3
vncz17:04:46

So far the best way I’ve put it so far is something along the lines of “Clojure is a computer language that leans towards functional programming”

vncz17:04:06

That usually conveys the message and does not trigger Clojure vs Haskell vs Elixir wars

borkdude17:04:26

Clojure encourages you and nudges you into functional programming most of the time. Some other languages force you into using imperative / OOP features more than FP features

vemv18:04:05

it's a gradient like so many things in life :) the focus on immutability is deeply functional, and so is the focus on HOFs (although that can be found in many modern languages by now). The control of side-effects is more ad-hoc/moderate and probably a contentious point if you were to discuss it with a Haskeller

👆 3
didibus22:04:31

@jayzawrotny I'd recommend reading my answer to this: https://www.reddit.com/r/Clojure/comments/guv9xn/comment/fsm5jds?context=3 to understand FP and its different styles and where Clojure falls into that.