beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
seancorfield 2021-03-26T01:00:02.063200Z

(if @show? "show" "hide") right?

dpsutton 2021-03-26T01:15:00.064100Z

Ah yeah maybe. The important bit is the returned function and the atom outside of that

1
pinealan 2021-03-26T07:25:59.066800Z

anyone got experience with implementing https://en.wikipedia.org/wiki/Financial_Information_eXchange clients? are there resources in clj/java that can help one to get started?

Tim Robinson 2021-03-26T10:53:35.071Z

is there any documentation that describes what the various metadata flags do? I realise it's extensible but I can't find anywhere that lists the "built-in" ones. specifically ^:redef

2021-03-29T23:38:28.267300Z

interesting question, I think a bunch of them are all grouped here https://github.com/clojure/clojure/blob/05c193c031aa3a825ebb824b4135e36a79693f51/src/jvm/clojure/lang/Compiler.java#L81

2021-03-29T23:38:45.267900Z

if the metadata controls the compiler, I'd expect it to show up in that file

bastilla 2021-03-26T11:21:04.074Z

Simple question here. I do this a lot: (if a a ...)

let [a (some-calc x y)
     a (if a a (some-alternative x y)]
But it dawns on me this is from my imperative mindset and not very lispy/functional. How do you deal with this?

2021-03-26T11:21:56.074100Z

(or a (some-alternative x y))

2021-03-26T11:22:34.074300Z

event better (or (some-calc x y) (some-alternative x y))

πŸ™Œ 2
bastilla 2021-03-26T11:23:04.074500Z

This community rocks!! @delaguardo

simongray 2021-03-26T11:23:19.074800Z

what @delaguardo wrote. Using or is idiomatic.

2021-03-26T11:23:25.075Z

or is a macro so it is safe to even have some sideeffects in some-alternative function

bastilla 2021-03-26T11:25:01.075200Z

Thanks a lot !! (and @simongray @delaguardo )

simongray 2021-03-26T11:27:52.075500Z

both and and or just return the last value (when true) since everything apart from nil and false is considered true in Clojure, so you will see a lot of succinct code that combines logic tests and nil punning in Clojure code.

πŸ™Œ 1
aratare 2021-03-26T13:11:00.076700Z

Hi there. What is the de facto way in Clojure to check if a string is an email address? Is regex matching my best option here?

2021-03-26T13:17:00.077700Z

There are a lot of resources that will tell you the best you can do is to determine if a string probably is an email address, and not necessarily a valid one.

2021-03-26T13:17:36.078400Z

You can google for some really hairy regexes that are intended to be a comprehensive match for any valid email address, but YMMV.

2021-03-26T13:18:53.079800Z

The site I'm working on now just has a simple regex that checks for "_@_._", and if it doesn't match, it just puts up a caption that says "Please be sure you are using a valid email address."

aratare 2021-03-26T13:19:02.080Z

yeah I forgot how hairy email validation can become with regex

2021-03-26T13:19:45.081300Z

The only reliable way to check for valid email addresses is to send it an email with a link that has an embedded one-time token, and then see if they click the link.

☝️ 3
2021-03-26T13:20:45.082100Z

Alternately, there are online services that do mass-mailing that will offer you email validation services, which might be marginally better than a regex, if you don't mind paying.

2021-03-26T13:21:30.082800Z

I'm thinking like MailGun or MailChimp or something, but I don't remember which of them (if any) offers that service. I have seen it though.

aratare 2021-03-26T13:22:30.083400Z

This is for a personal project so I’ll just do some simply regex matching. Thanks a lot πŸ™‚

2021-03-26T13:22:39.083600Z

:thumbsup:

ghadi 2021-03-26T13:24:03.084400Z

@rextruong first 8-9 minutes ofhttps://www.youtube.com/watch?v=9Q--oX5muxw covers email parsing with regexes

πŸ‘ 3
ghadi 2021-03-26T13:24:37.084900Z

tl;dw "good luck" πŸ™‚

2021-03-26T13:33:36.085400Z

The phrase "exponentially diminishing returns" does come to mind πŸ™‚

Elliot Stern 2021-03-26T13:46:26.086300Z

There’s some java libraries like https://javaee.github.io/javamail/, but the simplest regex + sending an email is really best

Azzurite 2021-03-26T16:24:37.090800Z

I feel very stupid right now because this must be so basic and I can't figure it out... I want to create a function that wraps hiccup content

(defn wrap [content] ; content is a list of hiccup elements
  [:div {:id "Test"}
   ; insert content here, but not in a list, just all the individual elements
   [:div {:id "footer"} ...]
  ])
how do I do that? Or is that just the wrong approach?

2021-03-26T16:29:23.092900Z

You could use into effectively here.

dpsutton 2021-03-26T16:30:14.094200Z

you have a vector and a collection and want to return a vector of the concatenation. (into [:div {:id "footer"}] your-collection) is the most straightforward approach

dpsutton 2021-03-26T16:31:48.096100Z

I phrased it like this to point that the smallest reproduction of your issue doesn't have hiccup or divs or a function called wrap involved. often all these details mask the simple problem: (into [:a] [:b :c :d]) -> [:a :b :c :d]

Azzurite 2021-03-26T16:32:18.096800Z

hm ok I was hoping to be able to do something like in js where you can do

let arr1 = [1, 2, 3];
let arr2 = [...arr1, 4, 5, 6];
where arr2 would be [1, 2, 3, 4, 5, 6] then

dpsutton 2021-03-26T16:32:54.097200Z

there's no equivalent of the spread operator in clojure

Azzurite 2021-03-26T16:33:08.097400Z

okay thanks!

Azzurite 2021-03-26T16:33:39.097900Z

kind of interesting, I'd think that'd be a pretty cool thing to have

Azzurite 2021-03-26T16:33:49.098100Z

makes everything more succinct

dpsutton 2021-03-26T16:34:43.099200Z

you can post on http://ask.clojure.org . It's possible it's been brought up before. Possibly declined, possibly still open to it. Or perhaps no one has taken the time to ask about it

Azzurite 2021-03-26T16:46:57.100500Z

so my function would look like this:

(defn wrap [content] ; content is a list of hiccup elements
  (let [wrapper [:div {:id "test"}]
        footer  [
		          ; some more elements here
				]]
  (into (into wrapper content) footer)
it does what I want... idk it's just looking wrong somehow, like it could be much easier...

Azzurite 2021-03-26T16:49:40.102200Z

in JS I would've done

let wrap = (content) => [
   :div, {:id "test"},
   ...content,
   // footer elements
];
(I'm not comparing/complaining, I would've just hoped it was easier and hope there's a better way than what I do)

dpsutton 2021-03-26T16:51:01.103100Z

(reduce into wrapper [content footer])

dpsutton 2021-03-26T16:51:42.103500Z

or (into wrapper (concat content footer)) should work

seancorfield 2021-03-26T16:59:02.104500Z

(-> wrapper
    (into content)
    (into footer))
@azzurite This makes the flow more obvious, perhaps?

alexmiller 2021-03-26T17:04:40.104900Z

Don’t recall anyone asking for it

alexmiller 2021-03-26T17:05:10.106200Z

I mean, there’s concat, and cat transducer if you want vector

Azzurite 2021-03-26T17:05:35.106700Z

honestly idk why this wasn't obvious to any of us πŸ˜„

(concat wrapper content footer)

dpsutton 2021-03-26T17:06:00.107100Z

it needs to be a vector for hiccup

dpsutton 2021-03-26T17:06:25.107700Z

so you'd have to do (into [] (concat ...)) which is what i put above (into wrapper (concat content footer))

2021-03-29T23:42:35.268600Z

this is a great place to use cat - (into [] cat [...])

dpsutton 2021-03-29T23:50:58.269500Z

i always forget about cat

Azzurite 2021-03-26T17:08:02.107900Z

I see, yeah

Azzurite 2021-03-26T17:08:04.108200Z

thanks everyone

Azzurite 2021-03-26T17:09:42.108600Z

for some reason I like (vec (concat wrapper content footer)) best, just gets my intent across I feel

2021-03-29T23:41:24.268200Z

there's also (into [] cat [wrapper content footer])

2021-03-29T23:41:44.268400Z

does the same thing to the data, with less intermediate steps / lazy seqs

Azzurite 2021-03-30T10:43:05.289700Z

I still don't understand transducers and haven't found a good explanation... the official reference seems to assume too much of my intelligence πŸ˜„

2021-03-30T17:13:31.310Z

my tl;dr is that they offer the same transformation steps as lazy seq operations, without needing a seq for input or output

2021-03-30T17:14:07.310200Z

this wouldn't matter if clojure was a "clever" compiler, but clojure is intentionally not one

2021-03-26T17:15:22.109900Z

That works too.

sova-soars-the-sora 2021-03-26T18:41:05.110500Z

So let's say i've got a series of posts on a social-ish thing...

sova-soars-the-sora 2021-03-26T18:41:51.111300Z

and I want to have notifications for users... like if someone "reacts" to your post.

sova-soars-the-sora 2021-03-26T18:43:02.112600Z

i'm thinking: keep a "last-seen-notification" timestamp for each user, and then check it against the stored reactions... but i also want a way for users to mark certain notifications as seen... well i don't know if i want to go that fine-grain... but in general a way to see notifications for reactions. does it make sense to...

sova-soars-the-sora 2021-03-26T18:43:52.113400Z

mark notifications as "seen" ... or try and simply rely on latest-seen timestamp to do that difference?

sova-soars-the-sora 2021-03-26T18:44:22.114100Z

kinda a nebulous design-level question... but i'm a little unclear on doing the notifications bit so any words of help would be appreciated πŸ˜„

2021-03-26T18:58:02.117900Z

most notification systems are really bad, because when they were initially written the idea was "little ephemeral messages"

2021-03-26T18:58:33.118500Z

but no one actually wants that, what they want is basically "lightweight email"

2021-03-26T18:58:50.119Z

meaning an inbox, where notifications persist, and you can mark them as read, and read old ones, etc

2021-03-26T19:00:40.120Z

so I would try to ignore that you are implementing notifications, and instead look at imap, and the extensions to imap for push, for inspiration

sova-soars-the-sora 2021-03-26T19:25:45.120300Z

thank you

sova-soars-the-sora 2021-03-26T19:26:11.120900Z

that makes sense, "lightweight email." I am trying to keep a very reduced interface but a historical view on notifications is likely necessary.

sova-soars-the-sora 2021-03-26T19:35:47.121400Z

Do you reckon "mark as read/seen" and "Mark all as read/seen" would be sufficient with a boolean on each notif?

sova-soars-the-sora 2021-03-26T19:36:10.121700Z

hard-pressed to think of other use-cases.

Franco Gasperino 2021-03-26T23:57:07.124700Z

if this is evaluated lazily, shouldn't i receive a false instead of an NPE?

(first (remove #(% nil) [int? zero?]))

2021-03-29T23:45:03.268800Z

calling first on (remove pred? coll) will realize every item in coll until one is truthy, so the error should be expected

2021-03-29T23:46:19.269100Z

you can replace zero? with (fnil zero? -1) (-1 was an arbitrary choice, plug in any non-zero)

2021-03-29T23:46:49.269300Z

or #(and (number? %) (zero? %))

Franco Gasperino 2021-03-26T23:58:18.125400Z

(int? nil) => false
  (zero? nil) => NPE