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
What gets syntactically heavy is when you try to start using namespace aliases and fully package qualified namespaces
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])
zprint
Hi there. Is there any way to mock a Transit request? Thanks in advance.
Well I just used transit-clj
and ring-mock
and I have my requests now 🙂
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
hah, nice
Does it? (seems to work AFAICT)
(defmacro bbb [n]
`(let [^bytes b# (byte-array ~n)]
b#))
(defn use-macro [n]
(bbb n))
(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)
@raspasov It sometimes does. 😄
… are you positive that this error is coming out of the ^bytes?
(your code compiles for me…)
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.^"[B"
(let [byte-arr ^"[B" (... your expr ...)]
...)
~(with-meta x {:tag bytes})
Is Clojure officially regarded as a functional programming language? Like if I said “Clojure is a functional programming language”, would that be incorrect?
@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.
The point is that even the definition of “functional programming” is fuzzy. For somebody means something, for somebody means another thing.
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”
That usually conveys the message and does not trigger Clojure vs Haskell vs Elixir wars
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
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
@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.