Fork me on GitHub
#beginners
<
2020-03-28
>
kwrooijen15:03:43

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?

kwrooijen15:03:03

Oh I can just use edn/read-string haha

hindol18:03:10

Need some CSS help. Any specific channels?

seancorfield18:03:02

#css exists as a channel but I have no idea how active it is @hindol.adhya

👍 4
kwrooijen18:03:14

Thanks, I'll take a look

Aviv Kotek20:03:33

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.

Petrus Theron20:03:20

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.

🚀 4
mruzekw21:03:45

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

mruzekw21:03:25

Stream = a channel, in this case

hiredman21:03:28

Streams in sicp are more like lazy seqs

👍 8
hiredman21:03:49

Which are every where in clojure

hiredman21:03:40

A scheme delay is more like a clojure promise

hiredman21:03:45

If I recall

hiredman21:03:45

A delay in clojure is not the same thing as a promise

dpsutton21:03:00

> 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

hiredman21:03:42

I think I got it reversed

hiredman21:03:20

The thing delay creates in scheme is a promise, which is like a clojure delay and not like a clojure promise

dpsutton22:03:23

Ah. Receives a value versus has the thunk to compute it itself ?

Gulli22:03:59

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?

nate22:03:49

yes, my db layer functions are quite impure

OrdoFlammae22:03:01

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?

nate22:03:08

but they're also incredibly simple, often with one form inside

nate22:03:29

i.e. take the args, put them into the db function

seancorfield22:03:52

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

seancorfield22:03:15

(let [data (read-stuff db)
      new-data (pure-transform data)]
  (write-it db new-data))

Gulli22:03:36

Great, thanks

seancorfield22:03:12

(that way you can test the transformation logic independently, perhaps generatively, for example)

Gulli22:03:12

yeah exactly. My business logic will be a lot of transformation, I had it in my head I'd be using (-> for these

Gulli22:03:43

and try to have them pure

OrdoFlammae22:03:57

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?

8
Michael Bonnet22:03:45

Hello, I know less than John Snow, haven't written anything yet, but a quick search:

didibus22:03:07

I think Java doesn't have unsigned integers, and therefore Clojure as well

OrdoFlammae22:03:24

OK, that works.

OrdoFlammae22:03:31

What's the 2rstuff?

Michael Bonnet22:03:54

a shift? I don't know

seancorfield22:03:10

The radix (the base)

Michael Bonnet22:03:24

Oh, that makes sense

seancorfield22:03:28

2r means binary. 16r means hex.

didibus22:03:56

Hum... Seems that chars are 16bit unsigned

didibus22:03:02

Maybe you could use that

didibus22:03:17

Also, Java 8 has 32 bit unsigned support

didibus22:03:43

Integer/divideUnsigned for example

seancorfield22:03:05

That SO link has an answer from Alex Miller pointing at those Java 8 methods.

OrdoFlammae22:03:27

Thanks @seancorfield. Now the SO answer makes sense.

OrdoFlammae22:03:51

Hopefully the syntax isn't too obtuse...

Michael Bonnet22:03:23

If you liked 'Arrival': (->> 11111 (bit-and-not 7r66666)) => 16512

porkostomus22:03:15

I think they dealt with a problem like this on this episode of Apropos: https://www.youtube.com/watch?v=parkWOdl8RU

didibus22:03:42

I think you can actually use all bitwise operator on a char

didibus22:03:14

In Java you can, so I'd assume Clojure as well

didibus22:03:25

And char are 16bit unsigned

andy.fingerhut22:03:34

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

didibus22:03:56

You won't be a le to use arithmetics though like +,-,*, etc. I believe

didibus22:03:12

Nevermind then

didibus22:03:55

> Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte

didibus22:03:04

Kinda sad that it's not the case for Clojure

seancorfield22:03:25

char not Character

didibus22:03:42

Oh ya, cast to (char) first

OrdoFlammae22:03:46

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

andy.fingerhut23:03:14

There are bigger fish to be sad about 🙂

OrdoFlammae23:03:16

Although it would be interesting to have a library that allows manipulation of this kind of stuff.

didibus23:03:17

(bit-and 5 (char \a)) ?

andy.fingerhut23:03:33

If you don't have a REPL, then how are you using Slack? 🙂

didibus23:03:57

I only have Replete which is Cljs repl on my phone :(

didibus23:03:03

So can't try those interop use cases

seancorfield23:03:41

That explains lots of short messages rather than fewer longer tracts 🙂

didibus23:03:08

Oh ya, I never realized that, it does ☺️

andy.fingerhut23:03:41

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

andy.fingerhut23:03:36

It is straightforward to convert char or Character type values to integers, though.

Petrus Theron20:03:20

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.

🚀 4