This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-14
Channels
- # aleph (2)
- # asami (1)
- # aws (6)
- # beginners (65)
- # cider (12)
- # clj-kondo (11)
- # cljs-dev (1)
- # clojure (179)
- # clojure-dev (15)
- # clojure-europe (5)
- # clojure-losangeles (5)
- # clojure-nl (1)
- # clojure-spec (6)
- # clojuredesign-podcast (50)
- # clojurescript (28)
- # cryogen (31)
- # data-science (10)
- # emacs (2)
- # events (1)
- # fulcro (39)
- # helix (4)
- # luminus (3)
- # malli (5)
- # nrepl (4)
- # off-topic (3)
- # pathom (1)
- # reveal (10)
- # shadow-cljs (5)
- # spacemacs (3)
- # tools-deps (6)
- # vscode (1)
- # xtdb (3)
all top level definitions should be constant / immutable, so having a "constant" isn't useful
that's the typical style guide answer at least
if anything we use names like *bot-name*
for things that aren't constant
I've seen +bot-name+
used by people who came from common lisp, but it's not a clojure idiom
Ngl the juxt function is pretty cool I read a blog post that used it in conjunction with sort-by, and it totally blew my mind as a beginner 🤯
Any suggestions for stack (or even some template) if I'd like to start a new API project?
should I just pick compojure? Or maybe reitit which is mentioned in compojure github page?
Back to the topic of naming, is there a specific reason why style guides don't advocate naming reference types differently? Just adding a *
to atoms seem very useful to me, so you don't have to backtrack their bindings to verify whether they've been deref'ed at a previous point (especially when passed across multiple functions).
I'm trying to implement parts of the clojure.reflect/type-reflect
function in a Scala program, to do similar (but more limited) kinds of class reflection. I see that from a Class
there is a method isInterface()
which gives me the :flags :interface
part. Does anyone know how the refl/type-reflect
function figure out if the class is :public
, :final
, or :abstract
. I don't see that in the code. Maybe it's hidden in a java function.
it looks like there is an integer (Long?) called the access bits. And I can and that integer with certain bit-masks to determine such information. But I don't see how to get the access bits integer.
(def ^{:doc "The Java access bitflags, along with their friendly names and
the kinds of objects to which they can apply."}
flag-descriptors
(vec
(map access-flag
[[:public 0x0001 :class :field :method]
[:private 0x002 :class :field :method]
[:protected 0x0004 :class :field :method]
[:static 0x0008 :field :method]
[:final 0x0010 :class :field :method]
;; :super is ancient history and is unfindable (?) by
;; reflection. skip it
#_[:super 0x0020 :class]
[:synchronized 0x0020 :method]
[:volatile 0x0040 :field]
[:bridge 0x0040 :method]
[:varargs 0x0080 :method]
[:transient 0x0080 :field]
[:native 0x0100 :method]
[:interface 0x0200 :class]
[:abstract 0x0400 :class :method]
[:strict 0x0800 :method]
[:synthetic 0x1000 :class :field :method]
[:annotation 0x2000 :class]
[:enum 0x4000 :class :field :inner]])))
I think I found it. looks like class.getModifiers()
gives me the integer.
for some reason lein cljsbuild once
compiles the code in core.js
but not in main.js
as I specified in project.clj
.
cljs/core.js:3359: ERROR - Parse error. primary expression expected
I had to downgrade from versions
:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/clojurescript "1.9.521"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
[ring/ring-json "0.5.0"]]
to versions
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2371"]
[compojure "1.3.1"]
[ring/ring-defaults "0.1.2"]
[ring/ring-json "0.3.1"]]
to make it workNow using clojure.core.cache.wrapped
to cache OAuth access tokens ..
(defn cached-authenticate [app event]
(let [cache-key [(:name app) (get-in event [:installation :id])]]
(cache/lookup-or-miss
installation-access-token-cache cache-key
(fn [_] (authenticate app event)))))
Can anyone recommend something that would allow me to delay incoming messages? I’m working with a webhook, but I do not immediately want to process those messages. Ideally I queue them and process them N seconds later. In the Go version of this GitHub app I am putting them in Redis queue and then poll them … I guess I could do the same, but maybe there is something simpler that doesn’t need an external store?
maybe something based on java's LinkedBlockingQueue? https://gist.github.com/mjg123/1305115/72434dd5da89e5a83c91facb0b7687d6b7e66836
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html
Seems like a good case for a channel https://clojuredocs.org/clojure.core.async/chan
how can I treat a string as a file without writing it out? my google-fu failed me..
I guess, something I could slurp for example
but yes, in memory
thanks, I managed to make it work
with (io/input-stream (.getBytes "text"))
if you need text rather than binary IO, stringreader is simpler
(cmd)user=> (java.io.StringReader. "Hello")
#object[java.io.StringReader 0x7a34b7b8 "java.io.StringReader@7a34b7b8"]
(ins)user=> (slurp *1)
"Hello"
if you need binary io, add the extra arg to getBytes
that specifies the encoding
usually you want "UTF-8"
Basically, if I have the file:
(let [x 5
I'd like it to still be able to read the text so far, so it'd read to something like:
(let [x 5])
If, for example, clojurescript used only parens, I could just keep adding parens to the end until it successfully read, but since it doesn't, that wouldn't really work. (Or rather, it'd be much slower...)
@leif clj-kondo will give you this output:
$ echo "(let [x 5" > partial.clj
$ clj-kondo --lint partial.clj
partial.clj:1:6: error: Found an opening [ with no matching ]
partial.clj:2:1: error: Expected a ] to match [ from line 1
Potentially you could use that output to gradually fix the expression and then read it using a normal parser
@leif edamame (my Clojure parser) also has something similar:
user=> (require '[edamame.core :as e])
nil
user=> (e/parse-string "(+ 1 2 3")
Execution error (ExceptionInfo) at edamame.impl.parser/throw-reader (parser.cljc:92).
EOF while reading, expected ) to match ( at [1,1]
So it looks like I'll have to catch the exception, try to parse the exception to get the correct )
, ]
, or }
, and then append that to the stream, and try again?
Would it be possible for edamame.core
to attach some sort of data to the exception so that I wouldn't have to parse a string?
That's what I suggested: > possibly we could also add the expected thing to the exception data It doesn't do that currently, but a PR for that is welcome
This is the line where it throws that exception: https://github.com/borkdude/edamame/blob/9101156cdcf5ad7b287e160cc28145913bd14d78/src/edamame/impl/parser.cljc#L123