This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-01
Channels
- # adventofcode (1)
- # bangalore-clj (1)
- # beginners (8)
- # boot (47)
- # cider (6)
- # cljsrn (3)
- # clojure (155)
- # clojure-brasil (2)
- # clojure-china (3)
- # clojure-conj (1)
- # clojure-hk (4)
- # clojure-korea (36)
- # clojure-russia (38)
- # clojure-spec (53)
- # clojure-taiwan (1)
- # clojure-uk (14)
- # clojurescript (70)
- # clojurex (9)
- # component (2)
- # cursive (20)
- # datascript (19)
- # datomic (39)
- # defnpodcast (1)
- # events (5)
- # figwheel (2)
- # hoplon (81)
- # incanter (2)
- # jobs (7)
- # juxt (3)
- # klipse (1)
- # leiningen (1)
- # luminus (15)
- # mount (1)
- # off-topic (21)
- # om (5)
- # om-next (2)
- # onyx (19)
- # pedestal (2)
- # proto-repl (1)
- # proton (5)
- # re-frame (19)
- # reagent (4)
- # rethinkdb (2)
- # ring-swagger (6)
- # rum (13)
- # specter (6)
- # untangled (4)
- # yada (1)
DYLD_LIBRARY_PATH is an osx only thing, so lein almost certainly doesn't do anything with it
maybe something like https://github.com/oracle/node-oracledb/issues/231
@oliv think about slicing up the problem a bit differently. Currently you've coupled creation of a pipeline add
with the execution of the pipeline evaluate
. Not a bad design but it is a pattern that already exists in Clojure. In my example, add
becomes comp
and evaluate
becomes into
but it could also be transduce
or something else like a core.async channel.
With core.async you could do (chan 1 chain-instance-once)
, which would create a channel that would run your chain of functions against every value that flows through it.
In addition you can now leverage all of the clojure standard library. For example if you only want the first 4 results, you could do:
(into []
(comp chain-instance-one
(take 4))
(range))
And you could easily mix in, distinct
, partition-all
, map-cat
, etc. All that to say, what you're building isn't "wrong" it's just duplication of effort.
I see what you are saying. I;m just trying to port my JS solution to clojure. and the usage define how I have to implement.
the ideia ( on js ) is to create a Chain instance and append functions inside. once you want to run the Chain you call the evaluate
function with the parameters
the api is add
and evaluate
var chain = new Chain();
var result = chain
.add(function timesFour(a) { return a * 4 })
.add(function timesFive(a) { return a * 5 })
.evaluate([1,2,3,4]);
exactly, and that's a pattern that exists in JS because in JS you don't have transducers, and JS emphasizes OOP.
Anyone know of a good plugin to speed up lein boot time?
you can see the error failing in CI here: https://github.com/lvh/caesium/pull/18
The library I’m getting out of jnr-ffi can — sometimes, and only when creating an uberjar, and only in one particular namespace — not be cast to the interface it’s supposed to be castable to
the expanded version is:
(do (def bytes "Constant returned by `crypto_scalarmult_bytes`. See libsodium docs." (.crypto_scalarmult_bytes caesium.binding/sodium)) (def scalarbytes "Constant returned by `crypto_scalarmult_scalarbytes`. See libsodium docs." (.crypto_scalarmult_scalarbytes caesium.binding/sodium)) (def primitive "Constant returned by `crypto_scalarmult_primitive`. See libsodium docs." (.crypto_scalarmult_primitive caesium.binding/sodium)))
The final exception is:
Caused by: java.lang.ClassCastException: caesium.binding.Sodium$jnr$ffi$0 cannot be cast to caesium.binding.Sodium
You get that because the sodium var it’s calling that on is annotated to implement that interface
the good news is I might not have to care about this; I tried to build an uberjar by accident
@etherfuse: How come assoc*
rather than assoc
? Some special macro meaning for the *
, or a different function (to assoc) altogether?
is it possible to get the :keys destructuring syntax to do direct field lookup when using record types with hints?
i’d love for there to be some getfield opcodes instead of calls to KeywordLookupSite, etc
can someone explain why the first example works, but the second doesn’t
(defmacro java-setter
"Creates all the java setters for the java interface"
[title]
`(defn ~(symbol (str "-set" (hyphen->camel title)))
[this# value#]
(swap! (.state this#) ~(symbol (str "with-" title)) value#) this#))
this doesn’t (defmacro java-setter
"Creates all the java setters for the java interface"
[title]
`(defn ~(symbol (str "-set" (hyphen->camel title)))
[this value]
(swap! (.state this) ~(symbol (str "with-" title)) value) this))
@etherfuse syntax quote (the `) isn’t that smart
I read about it https://osdir.com/ml/java.clojure.user/2008-03/msg00108.html but I feel like I’ve seen other examples without x#
this might help: https://github.com/brandonbloom/backtick/blob/master/src/backtick.clj
but the general guideline is that you use the # suffix on local variables that you don’t want resolved
Has anyone used clj-pdf for automatic report generation? It works very well but I’m finding the time to develop a new template involves a lot of iteration/trial error, and I was wondering if there were interesting alternative libraries/solutions/3rd party tools I could use for this?
(defmacro java-setter
"Creates all the java setters for the java interface"
[title]
`(defn ~(symbol (str "-set" (hyphen->camel title)))
[~'this ~'value]
(swap! (.state ~'this) ~(symbol (str "with-" title)) ~'value) ~‘this))
Ugly ~’
.@achesnais you can always retreat back to the java world!
😂 not sure if java will make me more productive 🙂 I think my question is more about going a bit more high level than the kind of granularity provided by clj-pdf
I like to generate code with type hints from a macro. The java class is an arg of the macro. I can’t generate reader macro stuff like ^~class
or ^{:tag ~class}
. with-meta
seams to do nothing regarding type hints. What can I do?
with-meta or alter-meta works just fine in macros. your problem might be that you’re not actually seeing the metadata when inspecting the macro output
since it’s not printed by default
Question: I am writing a daemon that periodically downloads new csv-files from an S3 bucket. I now need some list that contains the csv-files already processed. This needs to be persisted, since a server restart should not mean that it will re-download already downloaded stuff. The downloaded stuff is merely processed, not stored, so i can't just check if the downloaded file exists. therefore i need some sort of cache/database/storage. Of course i could use some sql database of whatever, but I wonder if there is an idiomatic way in clojure to do this that i don't know of
I'm using something similar on one of my apps, just using a file to persist the atom encoded with transit
but then; is it best to just store it in a simple list of filenames, or can i be a bit smarter and save it as some persisted tree
because it can become quit a long list (filename is like 20160101_<siteid><somesubid>.csv
@joost-diepenmaat my problem is that I get a reflection warning even if I use with-meta
directly
@joost-diepenmaat I solved my problem. I was doing something wrong in the macro.
kah0ona I don't think there's an 'idiomatic' way to do what you want; it depends very much on your environment. If having your server write to disk is reasonable then that's perfectly fine, so long as a restart of the server is guaranteed to have access to the same disk.
obviously, introducing an external DB insulates you against failure but is more overhead
https://medium.com/chain-cloud-company-blog/a-first-look-at-r3-corda-released-yesterday-7a62a298c43f anyone familiar? does this mean one can write smart contracts in clojure too?
Just got my head around to realise that (or (= “foo” val) (= “bar” val))
can be (better) expressed as (#{”foo” “baz”} val)
but that would probably be more directly translated to (contains? #{”foo” “baz”} val)
it looks like it may apply to your use case
Today I learned that you can force-reload a defmulti foo
in a running repl by adding (def foo nil)
before it
@kah0ona in the vein of keeping it simple, I'd recommend using EDN via (via clojure.edn) and then just use slurp/spit to read and write the file. Yes the file will get large, but it'll be faster than you expect, if it starts to get too big it's trivial to convert it to some sort of DB.
@slipset I think the set-as-a-function thing comes from Clojure's view of thinking about what .invoke would mean on almost every type.
For example you can do it with hashmaps ({:a 42} :a)
, keywords (:a {:a 42})
, symbols ('a {'a 42})
, etc.
for "prior art" about the only thing I can think of that comes close is Pythons use of .invoke on types being the constructor:
`
class Foo(object):
def init__(self, val):
this.val = val
foo = Foo(42)
but that's not exactly the same.
When you squint at it though, it's a small step from python-esque some-dict[42]
to some-dict(42)
to (some-dict 42)
So all that to say, I don't think there is prior art in this area, just perhaps iteration on existing ideas.
@tbaldridge: thanks. I guess I'm surprised by how useful this is, and wondering if this was thought of when the language was designed, or if it just a lucky coincidence.
Hey guys, noobish macro question, is it possible to define a macro in one ns that defines a -main
function in another?
eg.
(ns my-first-ns)
(defmacro defmain
[& body]
`(defn -main
[& args]
(println "I'm a main function that prints my args!" args)
~@body))
(ns my-second-ns
(:require [my-first-ns]))
(my-first-ns/defmain
(println "hello world"))
I have lots of projects where their -main functions contain the same boiler plate and I'd like to have a macro that replaces that
personally I'd rather implement a :default
multimethod that can be defined in the second ns
in first-ns
(defmulti -main identity)
in second-ns
(:require [first-ns :as first])
(defmethod first/-main :default [args]
....)
One other thing that seems to work is passing the -main
symbol into the macro.
eg.
(ns my-first-ns)
(defmacro defmain
[fn-name & body]
`(defn ~fn-name
[& args]
(println "I'm a main function that prints my args!" args)
~@body))
(ns my-second-ns
(:require [my-first-ns]))
(my-first-ns/defmain -main
(println "hello world"))
Not beautiful, but for my use case (which is little less contrived, it works well enough.Another question : is code who reads a api to get data that must be displayed also middleware ? or must this be placed in utils.clj ?
Всем привет! Ищу человека, кто может меня научить программированию на Clojure, готов платить деньгами за уроки! Звоните 8 905 225 48 55 <mailto:[email protected]|[email protected]> Сам в Питере нахожусь, но можно и по скайпу .
> Hello! Looking for someone who can teach me Programming Clojure's, ready to pay money for lessons! Call 8905225 48 55 <mailto:[email protected]|[email protected]> myself am in St. Petersburg, but it is possible and on Skype.
how can I trigger a figwheel build of my assets from within (cljs-repl)
(without first backing out using :cljs/quit
?
Does anyone know what was deficient in nREPL's to drive the creation of Socket Server in 1.8?
@futuro nREPL is a RPC protocol, the idea behind socket server being "just attach a REPL I/O streams to a TCP socket", that then morphed into "why a TCP socket, why not simplify even more?".
@tbaldridge Yeah, nREPL looks to be both a specification for how to talk to a running clojure instance, but also the server implementation that listens for connections, a.k.a tools.nrepl
So the end result is the Socket Server provides a way (on the commandline even) to hook a repl up to anything that accepts an Input/OutputStream
and part of that has been research into nREPL and Socket Server haven't been brought together in some fashion
I've read most of the documentation and all of the source for Socket Server and now I'm going through the nREPL source
That may be likely. That's what I like about Socket Server, implementing it for a platform is as simple as opening a TCP connection.
Currently I'd like to see cider and clj-refactor/refactor-nrepl supporting socket servers
Or, more accurately, I'd love to have cider and clj-refactor available for js hosted cljs vm's
yep 🙂
@futuro: I know it's not what you're asking for, but inf-clojure-mode works fine with Planck, but of course without the refactoring support.
@slipset: a minor point from scrollback, (#{foo} x) isn't like contains, it's like get - eg if foo is nil
it returns nil if it's found