This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-07
Channels
- # 100-days-of-code (13)
- # beginners (12)
- # business (6)
- # cider (6)
- # cljdoc (9)
- # cljs-dev (1)
- # cljsrn (4)
- # clojars (4)
- # clojure (31)
- # clojure-dev (12)
- # clojure-uk (11)
- # clojurescript (16)
- # cursive (1)
- # datascript (4)
- # datomic (10)
- # editors (1)
- # figwheel-main (3)
- # graphql (10)
- # lein-figwheel (29)
- # off-topic (1)
- # pedestal (1)
- # re-frame (31)
- # reitit (3)
- # shadow-cljs (27)
- # slack-help (5)
- # spacemacs (1)
- # yada (5)
Coming from Python... handling strings in clojure is a nightmare. Any advice?
Should I maybe embrace lisp and courageously face and embrace cl-format? :p
I know some Python, and more Clojure. Anything in particular you are looking to do that is giving you nightmares?
Clojure has subs
function that is similar to Python slices, but does not do negative indices. You can work around that by writing a function that lets you do negative indices if you want, or just use (- (count my-str) 5) instead of -5. Java regexes are available in Clojure, which for common simple things lets you do everything the Python import re
does. I try to stay away from the fancier regex features like forward/backwards context, Unicode character sets, etc.
Clojure has format
and printf
that is closer to C printf and Python ("Print int here %d and string here %s" % (my_int, my_str))
I wouldn't recommend embracing Clojure's cl-format
unless it sounds like your cup of tea.
Must have missed subs somehow... thanks :) and yeah on second thought it might be less of a headache just to make some helper functions like that
Hi Guys, I am trying to update value for some specific key in a map using .toUpperCase . But getting the Compiler exception java.lang.RuntimeException: Unable to resolve symbol: .toUpperCase in this context
(def books [{:name "The adventure of sherlock holmes", :author "Doyle"} {:name "Midnight's Children", :author "Rushdie"}])
(map #(if (contains? % :name) (update-in % [:name] .toUpperCase)) books)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: .toUpperCase in this context. Can someone please help me in understanding this issue?
figured out ... (map #(if (contains? % :name) (update-in % [:name] (fn [name] (.toUpperCase name) ) )) books)
This is a common problem. You can't pass a Java function expecting it to be a Clojure function. You've wrapped it in a (fn ...) here. Another approach is the shorthand: #(.toUpper %)