clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-04-04T00:02:45.259Z

But for domain data I will say I do find them quite nice. But you need to use them like:

#:user{:name "john" :email "<mailto:john@gmail.com|john@gmail.com>"}
{:order/id 1234, :user/name "john", :wallet/balance 456}
Basically you just go :entity-name/property-name

2021-04-04T00:14:56.259500Z

What gets syntactically heavy is when you try to start using namespace aliases and fully package qualified namespaces

raspasov 2021-04-04T04:28:03.261200Z

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])

vemv 2021-04-04T05:00:39.261400Z

zprint

👍 1
aratare 2021-04-04T08:35:09.262400Z

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

aratare 2021-04-04T08:48:53.262600Z

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

1
Karol Wójcik 2021-04-04T11:02:55.265100Z

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

simongray 2021-04-04T11:06:31.265200Z

hah, nice

raspasov 2021-04-04T11:20:40.265400Z

Does it? (seems to work AFAICT)

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

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

Karol Wójcik 2021-04-04T11:56:28.265800Z

(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-&gt;edn-event in#)
                  context# (#'fierycod.holy-lambda.core/java-ctx-object-&gt;ctx-edn ctx# (#'fierycod.holy-lambda.util/envs))
                  response# (#'fierycod.holy-lambda.util/-&gt;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.&lt;init&gt;(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ójcik 2021-04-04T11:56:34.266Z

@raspasov It sometimes does. 😄

raspasov 2021-04-04T12:03:29.266400Z

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

raspasov 2021-04-04T12:04:22.266600Z

(your code compiles for me…)

Karol Wójcik 2021-04-04T12:06:15.266800Z

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.

👍 2
emccue 2021-04-04T14:55:43.267900Z

^"[B"

emccue 2021-04-04T14:56:18.268100Z

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

2021-04-04T15:59:10.268400Z

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

2021-04-04T17:37:12.269700Z

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

schmee 2021-04-04T17:39:34.270400Z

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

vncz 2021-04-04T17:39:54.271100Z

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

☝️ 1
vncz 2021-04-04T17:40:46.272600Z

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”

vncz 2021-04-04T17:41:06.273300Z

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

borkdude 2021-04-04T17:50:26.273900Z

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

vemv 2021-04-04T18:07:05.276200Z

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

👆 1
2021-04-04T22:42:31.276600Z

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