Fork me on GitHub
#beginners
<
2021-07-11
>
sova-soars-the-sora00:07:55

Oh cool. Makes sense

Rob Haisfield01:07:54

Structural editors like Paredit and Parinfer make the claim that it makes more sense to manipulate Lisp / Clojure code by the expression instead of by the line... is there an equivalent to Grep / Ripgrep that queries Lisp code by the expression instead of by the line?

Cora (she/her)01:07:18

I'm not sure it makes sense to search lisp code by structure, but I am so interested to see if this is a thing

phronmophobic01:07:50

another borkdude project already has you covered, https://github.com/borkdude/grasp

‼️ 11
Rob Haisfield01:07:43

Hmm I’m not sure what it means to grep using Clojure.spec regexes

Rob Haisfield01:07:18

Is it basically that I write a predicate function and it finds s-expressions that match?

👍 3
phronmophobic01:07:13

regular expressions are almost always used to match against strings, but the regular expression operators (`*`, alt, +, etc) are really more generically about the order of stuff in a sequence. here's the spec docs, https://clojure.org/guides/spec#_sequences

phronmophobic01:07:31

as an example of using regex against data, you could have a predicate that is a number, followed by a string, followed by 0 or more keywords:

;; :my-number, :my-str, :my-keywords are simply labels/documentation
(s/cat :my-number number
       :my-str string?
       :my-keywords (s/* keyword?))

👍 3
Santiago06:07:16

I want to show the app version on the front page of my app. Where do I collect that information from? I’m using deps.edn and and update the pom.xml with version

Cora (she/her)07:07:57

could you parse it out of the pom.xml?

Santiago08:07:09

I guess I could, just never handled xml in clojure. Can use regex, but was wondering if there was a more “elegant” way 😄

oxalorg (Mitesh)08:07:43

We sometimes use this when doing git based deploys:

(defn get-version [_]
  (let [commit (-> (sh/sh "git" "rev-parse" "HEAD") :out string/trim)]
    {:status 200
     :body {:commit commit}
     :view #(:commit %)}))

lassemaatta11:07:53

Is this correct: when using e.g. extend-type with a record type (defined in another namespace), I need to use :import and refer to the generated Java class, e.g. (ns foo (:import [some.other_namespace NameOfRecord]))?

Edward Ciafardini13:07:55

I'm about to start working on a project that takes text documents and alters their format based on user inputs. Any libraries or functions you would recommend looking into? One example of what I'd be trying to do it taking text: This is is text then displaying it as T h i s i s t e x t There are lots of other patterns I want to try to implement too

Martin Půda14:07:44

Check clojure.string and clojure.pprint- your example can be achieved with (clojure.string/join "\n" "This is text") or, if you are familiar with Common Lisp format, with (clojure.pprint/cl-format false "{a^%~}" "This is text"). Use println for displaying that string in REPL.

Kenneth Gitere18:07:32

Hi I have a couple of functions as defn bindings that have destructuring on the arguments. This makes the documentation pretty ugly as the destructuring is visible. Is there a way to tweak the metadata of a defn binding to not show the destructured args or will I need to make a let binding?

dpsutton18:07:01

I actually usually like the destructuring appearing in the docstring but you can set your own arglists as shown here on (defn eduction ...)

Kenneth Gitere18:07:07

Thanks :thumbsup:

sova-soars-the-sora22:07:25

(defn- … with the dash is a private function?

Cora (she/her)23:07:20

my coworkers convinced me to use ^:private instead just because the - is easy to miss, so (defn ^:private foo [] ... )

Cora (she/her)23:07:24

turns out I like it

Cora (she/her)23:07:33

but you'll definitely see both out there, so...

sova-soars-the-sora23:07:29

Ooh the ^:private is a lot more in one’s face…

sova-soars-the-sora23:07:00

is there a name for the ^: dealio ? I see the phrase type hinting thrown around a lot

Cora (she/her)23:07:03

that's the idea, and it does make it clear, especially with code highlighting

Cora (she/her)23:07:17

it's metadata, it's a shorthand for ^{:private true} I believe