This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-28
Channels
- # announcements (3)
- # babashka (36)
- # beginners (77)
- # boot (3)
- # chlorine-clover (10)
- # cider (27)
- # clj-kondo (1)
- # cljs-dev (4)
- # clojure (256)
- # clojure-belgium (1)
- # clojure-europe (9)
- # clojure-uk (18)
- # clojuredesign-podcast (9)
- # clojurescript (54)
- # cryogen (8)
- # cursive (3)
- # data-science (1)
- # datomic (2)
- # duct (31)
- # events (1)
- # exercism (3)
- # fulcro (116)
- # joker (20)
- # kaocha (5)
- # meander (2)
- # nrepl (4)
- # off-topic (10)
- # other-languages (15)
- # re-frame (18)
- # reagent (4)
- # shadow-cljs (44)
- # sql (14)
- # tools-deps (17)
Anyone have an easy way to get the namespace of a .cljs file? All I have is a string representation of the file contents. Or is my best shot to just resort to regex?
#css exists as a channel but I have no idea how active it is @hindol.adhya
@kevin.van.rooijen something like https://github.com/clojure/tools.namespace/blob/8d632bfcd8ce4f872f9a9cdafb5245c9b10574a0/src/main/clojure/clojure/tools/namespace.clj#L57-L94 is probably most reliabel
hey, reading abit SICP and curious about streams and their impl in clojure as with LISP. what are streams in clojure then? I'm assuming 'seq'
can be thought as a 'stream-like'? with it laziness? how can I think on streams with clojure? I see that delay, force
are used as-well.
In Clojure, a seq is anything that implements the *clojure*.lang.Seqable
interface (https://clojure.org/reference/sequences#_the_seq_interface), which means it supports first
, rest
(or next
, if lazy) and cons
(so stuff can be added to the seq). This means you can consume a "stream" / seq in a loop (recursively if you like) by iteratively processing the first
item, and consuming the rest
.
When I hear streams I think of core.async: https://github.com/clojure/core.async But I havenât read SICP that far in, so I may be off in suggesting that
> Our implementation of streams will be based on a special form called delay. Evaluating (delay âšexpâ©) does not evaluate the expression âšexpâ©, but rather returns a so-called delayed object, which we can think of as a âpromiseâ to evaluate âšexpâ© at some future time. As a companion to delay, there is a procedure called force that takes a delayed object as argument and performs the evaluationâin effect, forcing the delay to fulfill its promise. good memory
The thing delay creates in scheme is a promise, which is like a clojure delay and not like a clojure promise
I might be trying to much to create pure functions, possibly in places where it's hard to do so. To the more experienced Clojurians out there, is it normal that your DB layer functions are quite impure?
I need to do some bitwise operations in Clojure; is there a way to work with 16-bit unsigned integers instead of the default 32-bit signed integers?
If your app is basically doing CRUD, it's OK to have impure functions all over the place. It's worth trying to separate out any transformation as pure functions tho'.
(let [data (read-stuff db)
new-data (pure-transform data)]
(write-it db new-data))
(that way you can test the transformation logic independently, perhaps generatively, for example)
yeah exactly. My business logic will be a lot of transformation, I had it in my head I'd be using (-> for these
I hope it's not rude, but since my question got covered up by the previous discussion, I'm going to repost it. > I need to do some bitwise operations in Clojure; is there a way to work with 16-bit unsigned integers instead of the default 32-bit signed integers?
Sorry @ordoflammae I've no idea.
Hello, I know less than John Snow, haven't written anything yet, but a quick search:
(->> 123
(bit-and-not 16rFFFF))
from https://stackoverflow.com/questions/41983701/unsigned-16-bit-integers-in-clojureOK, that works.
What's the 2r
stuff?
Or 16r
.
a shift? I don't know
OK. Thanks @dolphinlink!
The radix (the base)
Oh, that makes sense
2r means binary. 16r means hex.
That SO link has an answer from Alex Miller pointing at those Java 8 methods.
Thanks @seancorfield. Now the SO answer makes sense.
Hopefully the syntax isn't too obtuse...
If you liked 'Arrival': (->> 11111 (bit-and-not 7r66666)) => 16512
I think they dealt with a problem like this on this episode of Apropos: https://www.youtube.com/watch?v=parkWOdl8RU
Not quite:
user=> (bit-and 5 \a)
Execution error (IllegalArgumentException) at user/eval1 (REPL:1).
bit operation not supported for: class java.lang.Character
user=> (bit-and 5 (int \a))
1
> Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte
char
not Character
@didibus I think it's sort of a niche case, working with bitwise stuff, so it's probably not the best use of time for the Clojure developers.
There are bigger fish to be sad about đ
Although it would be interesting to have a library that allows manipulation of this kind of stuff.
If you don't have a REPL, then how are you using Slack? đ
That explains lots of short messages rather than fewer longer tracts đ
Clojure/JVM enables semi-straightforward use of values with types that are Java primitive long
and double
. I am not aware of any ways to make that semi-straightforward for other Java primitive types like char
It is straightforward to convert char
or Character
type values to integers, though.
In Clojure, a seq is anything that implements the *clojure*.lang.Seqable
interface (https://clojure.org/reference/sequences#_the_seq_interface), which means it supports first
, rest
(or next
, if lazy) and cons
(so stuff can be added to the seq). This means you can consume a "stream" / seq in a loop (recursively if you like) by iteratively processing the first
item, and consuming the rest
.