Fork me on GitHub

I think I need some clojure regex help. I'd like to remove a pattern of characters toward the end of a string. For example "persons name ABC12345" would return "persons name". If there is a space after the in the string the pattern would not be removed. I've been experimenting with re-seq, replace and re-pattern but havent found the right regex. Also, any good articles on using boundaries in regex would be useful, as I suspect defining boundaries might help


(defn something [s] 
   (if-let [match (re-matches #"^(persons name) *\S+" s)]
     (second match)


(something "persons name *ABC12345") => "persons name"
(something "persons name * ABC12345") => "persons name * ABC12345"


Pretty sure it can be done more succinctly using a better capturing group and re-find


a note: there's no such thing as a "clojure regex" - on the jvm clojure uses java regex, in cljs clojure uses javascript regex - this is the best cross platform regex guide I've found and I return to it often: - it has great comparison of the featureset / syntax of various regex systems (from grep, ed, sed, java, perl, c ...)


bad site design / UI, but top quality info that's well organized once you figure out how it's meant to be navigated

Michaël Salihi09:05:34

Hi! If I want to concat 3 items: 1. A simple hash map {:url url :label "Previous"} 2. A vector of hash maps [{:url (str url item) :label (str item)}{:url (str url item) :label (str item)}...] return by a for loop 3. A simple hash map {:url url :label "Previous"} Is there a better way - more idiomatic - to do this than to surround simple maps with a vector like I do now?

(let [previous-link {:url url :label "Previous"}
      links (for [item (range 1 (inc page-number))]
              {:url (str url item) :label (str item)})
      next-link {:url url :label "Next"}]
  (concat [previous-link] links [next-link]))


Not really better or more idiomatic than what you have here,

(flatten [previous-link links next-link])


What would've been idiomatic is to have something like

(->> some-list
     (cons el2)
     (push el3))
But push doesn't exist for lists since it's O(n).

Michaël Salihi13:05:51

Perfect @UMPJRJU9E, thanks. I prefer your flatten solution that mine. 👍


how do I do get the same result as (rest (rest something)) without looking so stupid? 😄


(nthrest something 2)


user=> (def something [1 2 3 4 5 6 7 8])
user=> (rest (rest something))
(3 4 5 6 7 8)
user=> (nthrest something 2)
(3 4 5 6 7 8)


This talks about it more detail, in particular the difference between nthrest and drop, with drop being lazy.


and another thing I've been trying to solve for a while but can't do it, is there a way to get rid of the duplication in this macro code:

(if docstring
     ~'< reactive
     [email protected]
     ~'< reactive
     [email protected]))
I can't do the if inside because then the if gets added to the output...


well after spending another 30 min on this I feel stupid...

(let [definition `(rum/defc
                    ~'< reactive
                    [email protected])]
  (if docstring
      (take 2 definition)
      (drop 2 definition))


That looks brittle. How about using [email protected] splicing with the value (when docstring [docstring])? [email protected] on nil will not inject a nil or anything else. I think. :)


Hi, can someone help to transform a async/await js example into cljs? I use shadow-cljs, installed an npm package and required it in a namespace (package beckhoff-js ). The example is:

const AdsClient = require('beckhoff-js');

const options = {
  target: {
    host: "",
    netID: "",
    amsPort: 801

const client = new AdsClient.default(options);
  .then(async () => {
    // Read a tag
    const bTest = await client.readTag(".bTest");
    console.log('bTest value is', bTest);
The cljs version so far:
(ns app
  (:require [reagent.core :as r]
            [reagent.dom :as rdom]
            ["beckhoff-js" :as adsclient]))


  (def client (adsclient/default. #js{:target #js{:host "" :netID "" :amsPort 851}}))

  (.connect client)) 
Creating the client instance works fine. The .connect returns #object[Promise [object Promise]], but the browser console returns an error: Uncaught (in promise) TypeError: net_1.Socket is not a constructor... I had a look at cljs js promise interop and tried some things with .then, but no success