Fork me on GitHub
#clojure
<
2019-11-18
>
pinkfrog05:11:02

what’s the cucumber gherkin framework to go for clojure?

seancorfield05:11:29

@i Searching GitHub doesn't turn up much. The three top results have almost no stars and no forks so I don't think it's an approach that Clojure folks use much?

pinkfrog06:11:49

yup. that’s the problem.

pinkfrog06:11:12

but bdd really helps non-tech people to communicate with tech ones.

emccue06:11:10

i feel like i know the answer is no, but just hoping

emccue06:11:45

is there a way to add a "default" to one of two values being dispatched on without breaking out derive and namespaced keywords?

emccue06:11:26

(defmulti f (juxt :a :b))
(defmethod f [6 4] [_])
(defmethod f [6 :default] [_])

emccue06:11:56

i guess it would be possible with a "top type" on derives

TheAlemazing08:11:26

Hello folks, Can I do SPA web development with Clojure only?

dharrigan08:11:01

Very much yes.

dharrigan08:11:10

ClojureScript...

etiago08:11:58

Some food for thought: functions and macros behave substantially different from a usability perspective. My understanding right now is that functions evaluate their arguments before executing their body, whereas macros pass the arguments unevaluated (or probably, more correctly, I imagine the code gets expanded with the unevaluated arguments) and then resolve the underlying code. With this in mind, would it not make sense to have a special sort of marker to unequivocally show when a certain call is a macro versus a function? Any thoughts please put them in a thread 🙂 👇

etiago08:11:05

Thread 👇

etiago08:11:21

I'm happy to be told I'm wrong, and why 😄

rickmoynihan09:11:36

They do… they have ^{:macro true} metadata on their var

etiago09:11:37

Ooooooh nice! I didn't know this - thank you!

etiago09:11:47

(I didn't even know about metadata 😊 )

Ben Hammond11:11:32

is

<groupId>com.cognitect.aws</groupId>
<artifactId>ses</artifactId>
not a thing? cannot seem to find it on https://repo1.maven.org/maven2/com/cognitect/aws/ses

dominicm11:11:51

Try com.cognitect.aws/email

👍 4
Ben Hammond12:11:18

ah yes that works, thanks

Ben Hammond12:11:04

is there a better place to pick the specific api names?

tzzh12:11:47

Hey, I am using [org.clojure/data.json "0.2.6"] and it’s not behaving as I would have expected as it’s happily parsing invalid JSON eg

user=> (require '[clojure.data.json :as j])
nil
user=> (j/read-str "{\"a\": 123,,}")
{"a" 123}
user=> (j/read-str "{\"a\": 123,\"b\",}")
{"a" 123}
am I missing something ?

Rex12:11:39

you may want to use Cheshire since it's the de facto JSON library for Clojure afaik. Just did a quick test and it immediately failed on detecting those commas.

tzzh12:11:47

yeah I have been recommended https://github.com/metosin/jsonista as well that looks good - find it weird that the standard one is broken though

tzzh16:11:30

I raised in issue on ask-clojure as that seems to be the preferred way for that type of issues https://ask.clojure.org/index.php/8860/is-the-standard-json-parser-broken

borkdude13:11:59

Is it expected that prewalk doesn't preserve metadata like this?

user=> (meta (walk/prewalk (fn [x] (if (seq? x) (with-meta x {:a 1}) x)) '(1 2 3)))
nil

borkdude13:11:00

I guess so, postwalk is maybe a better choice then

borkdude13:11:01

But I really need prewalk 🙂

dpsutton13:11:20

Didn’t ztellman make Ridley for exactly this reason?

dpsutton13:11:17

I’m maybe remembering a comment in the source. I’m reading it now

borkdude13:11:28

it's a similar problem, but not exactly the same? I just want clojure.walk/prewalk to preserve metadata

borkdude13:11:02

I'll just write my own

clj 8
delaguardo14:11:10

small hack that might be usefull (p

(def original-empty empty)

(meta
 (with-redefs [empty (fn [x]
                       (with-meta
                         (original-empty x)
                         (meta x)))]
   (clojure.walk/walk (comp vec reverse) identity ^{:x 1} {0 :start 1 :inprogress 2 :end})))
;; => {:x 1}

Ben Hammond14:11:05

what is the state-of-the-art for java.time tagged readers? should I use https://github.com/magnars/java-time-literals ?

eraserhd18:11:10

Are there any good patterns for a DSLs that can express a sequence of events, where sometimes the events do not have to be sequenced? e.g. A, then B and C in either order, followed by D?

nwjsmith18:11:52

sounds like a DAG

eraserhd18:11:02

I think that's accurate. Definitely directed, and yes cycles can be avoided by unrolling.

nwjsmith18:11:19

You could use an adjacency map, one that looks like the examples here: https://github.com/nwjsmith/generators.graph#usage

nwjsmith18:11:57

{:a #{}
 :b #{:a}
 :c #{:b :d :a}
 :d #{:b :a}
 :e #{:c :b :a}}}

eraserhd18:11:44

I think that's too noisy as a DSL, as I'm trying to express "X then Y then Z happens" in a test, and this would separate the descriptions of X Y and Z from the ordering.

eraserhd18:11:18

If nothing ever happened in parallel, the DSL would just be Clojure functions that waited for things to happen.

eraserhd18:11:40

Wait, maybe I just want an in-parallel macro?

eraserhd18:11:43

This is for a testing a system

hiredman18:11:20

or a state machine

thelittlesipper18:11:42

Heya, does anyone know of a nice string formatting tool that gives a similar style of formatting that Python offers? i.e.

(nice-format "Hello my name is {name}, and I live in {country}" :name "Bobby" :country "Canada")

lukasz18:11:19

@sansaripour that looks like a templating library - there's plenty to choose from, https://github.com/fhd/clostache or https://github.com/yogthos/Selmer

parens 8
nwjsmith18:11:11

clojure.pprint/cl-format is pretty powerful if you need something fancy but built-in

thelittlesipper18:11:42

Those work, thanks!

lilactown19:11:55

I’m also a fan of just str

(let [name "Bobby"
      country "Canada"]
  (str "Hello my name is " name ", and I live in " country))

jherrlin19:11:09

Hey! I am trying to learn spec and how generator works. Trying to accomplish something like this:

(["FOO-1" "FOO-1"]
 ["FOO-2" "FOO-2"]
 ["FOO-3" "FOO-3"]
 ["FOO-4" "FOO-4"]
 ["FOO-5" "FOO-5"])
A serie of unique and increasing numbers.

Alex Miller (Clojure team)19:11:23

so uniqueness and increasing are properties of the collection?

jherrlin19:11:01

Yeah, each entry in the collection needs to be unique

Alex Miller (Clojure team)19:11:14

if so, you'll need to make a custom generator that conforms to those properties

Alex Miller (Clojure team)19:11:07

I would probably take the approach of 1. create numbers 2. make distinct 3. sort 4. make vector of string of each number

Alex Miller (Clojure team)19:11:26

gen/fmap is a good tool to use for most of that

Alex Miller (Clojure team)19:11:43

it applies a function to generated values

jherrlin19:11:53

I've followed your video series and found something like this.

(s/def ::id (s/and string?
                   #(str/starts-with? % "FOO-")))

(s/exercise ::id)

(defn foo-gen []
  (->> (s/gen (s/int-in 1 100))
       (gen/fmap #(str "FOO-" %))))
But this will generate random, and often entires that are not unique

Alex Miller (Clojure team)19:11:31

yeah, you need to go up a level - make a collection of ints, not an int, then work on the collection

Alex Miller (Clojure team)19:11:09

so start from (s/gen (s/coll-of (s/int-in 1 100)))

Alex Miller (Clojure team)19:11:39

then apply distinct sort and (map #(str "FOO-" %) ...)

Alex Miller (Clojure team)19:11:08

the key is that the uniqueness and sorting are properties of the collection, not the values

jherrlin19:11:49

wondeful! thank you for pointing me in the right direction! ❤️

Gabriel19:11:25

been trying to figure out why this code doesn't compile for me

(ns sample
  (:refer-clojure :exclude [get]))

(defprotocol P
  (get [this a]))

(defrecord R []
  P
  (get [this a]))

Gabriel19:11:46

guessing it has to do with records being maps under the hood and therefore adding a get method to the generated class, but couldn't justify my guess by looking at the implementation of defrecord. any clue?

noisesmith19:11:36

maybe you want deftype? there are libraries that try to simplify making things that are almost like hash-maps but override specific behaviors (like potemkin https://github.com/ztellman/potemkin#def-map-type)

Gabriel19:11:30

ooh, makes sense. thanks for pointing that out!