This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-15
Channels
- # beginners (138)
- # bigdata (2)
- # boot (45)
- # cljsrn (29)
- # clojure (108)
- # clojure-austin (1)
- # clojure-gamedev (1)
- # clojure-korea (9)
- # clojure-russia (50)
- # clojure-spec (2)
- # clojure-uk (28)
- # clojurescript (40)
- # component (1)
- # cursive (35)
- # datomic (39)
- # dirac (16)
- # emacs (22)
- # flambo (11)
- # funcool (6)
- # hoplon (74)
- # leiningen (4)
- # off-topic (1)
- # om-next (2)
- # onyx (141)
- # planck (7)
- # proton (10)
- # protorepl (4)
- # re-frame (21)
- # reagent (13)
- # remote-jobs (1)
- # ring (3)
- # specter (9)
- # sql (3)
- # test-check (14)
- # untangled (1)
- # vim (9)
- # yada (16)
When I've defined some-ns
with :require [clojure.string :as s]
, where can I find the string functions in the map resulting from (ns-map some-ns)
? Some keys I've tried include 's/join
, #'s/join
, s/join
; but none of those find the function.
Also, even when my ns
invocation doesn't use :refer-clojure
, I get a bunch of clojure.core stuff in there anyway.
oh, sure
I read that ns-map
is supposed to return the actual map Clojure uses for resolving symbols in that namespace, so I assume s/join
must be in there somewhere
or at least just s
You can call 'keys' on any map to look at it's keys
yes, I did... but it's huge
oh, just did it again because it dawned on me that I could search the output... but I didn't find join
or anything with string
in it that doesn't belong to clojure.core
Why does the text "aka" not be included in this code :
(let [[first-name last-name & aliases]
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
(map (str "aka %")) aliases)
when I change it to this: (map (str "aka %") aliases))
I see this error message : ClassCastException java.lang.String cannot be cast to clojure.lang.IFn clojure.core/map/fn--4785 (core.clj:2646)
(let [[first-name last-name & aliases]
(list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
(map #(str "aka " %) aliases))
# before a list makes it an anonymous function, for example (#(+ 1 %) 2 )
gives 3. here #(+ 1 %)
is a function called with argument 2
@roelofw yes. #(... %)
is syntactic sugar for (fn [x] (... x))
. So in your case #(str "aka " %)
would be the same as (fn [x] (str "aka " x))
#"regex_pattern" - this is regular expression in clojure
Regex patterns (#"pattern")
A regex pattern is read and compiled at read time. The resulting object is of type java.util.regex.Pattern. Regex strings do not follow the same escape character rules as strings. Specifically, backslashes in the pattern are treated as themselves (and do not need to be escaped with an additional backslash). For example, (re-pattern "\\s*\\d+") can be written more concisely as #"\s*\d+".
Map str
over the sequence
see @andfadeev's snippet above
I thought of that but str (map #(str "aka " %) aliases)
and (str #(map #(str "aka " %) aliases))` are both not working
You want one string?
idiomatic way to unpack a seq into a number of args for a fn call (like str
) is probably (apply str [1 2 3])
which is same as (str 1 2 3)
but in this case coljure.string/join
may be a better choice
oke, thanks, now a very late lunch and then I will try to make a fixed text before it
Yeah some of them are quite tricky
the ones that challenge the way you currently think are usually the hard but most rewarding...e.g recursive calls if you've never done them or closures and high order fns if you're not used to functional programming
@agile_geek exactly
@agile_geek is Luminus a good framework for beginners or can I better wait till Archnea is at version 1.0.0 ?
@roelofw I've not used Liminus other than to play with but it's more a collection of opinionated libraries with a template and some glue code than a true framework. Arachne shows a lot of promise but it's very early days. @luke (author of Arachne) is speaking at Clojure eXchange in London on December 1st/2nd and the video of his talk will probably be here https://skillsmatter.com/conferences/7430-clojure-exchange-2016#skillscasts within a day or so if you're interested in Arachne.
and then, if you have annoyances with it, after making several projects, investigate something else, and only try it if it seems like it makes your particular problem easier
but if you start making stuff with a framework, any one--it really doesn't matter-- you can learn another one if need be
BTW - vested interest warning. I'm a co-organiser of Clojure eXchange and invited @luke to speak so I would plug it!
Most ppl I know pick and choose from a number of libraries rather than using a 'framework'
So a server side rendered site would probably include the following libraries in it's stack: * ring * compojure * hiccup
For a Single Page App - as mentioned ^^ - reagent or reagent/re-frame or om.next
Interestingly just about all the SPA libraries wrap React.js
first I have to try to solve all clojure koans and understand some principles and doing some 4clojure problems
is a decent book. Basically a set of tutorials.
second edition covers SPAs as well
Anyone who can give me a hint here :
"All together now!"
(= "Test Testerson, 123 Test Lane, Testerville, TX"
(___ ["Test" "Testerson"] test-address)))
I can destruct the test adress this way : (let [{street-address :street-address, city :city, state :state} test-address]
or this way : (let [{:keys [street-address city state]} test-address]
and the test adres is given like this :
(def test-address
{:street-address "123 Test Lane"
:city "Testerville"
:state "TX"})
everyone is always happy to help when you're stuck but its important to learn how to unstuck yourself as well
The first part I have to take out of the list and the part after it . it looks I have to destruct it
@roelofw yes, and you can destructure arguments inside of a parameter list. http://clojure.org/guides/destructuring
Why does this output a object :
(= "Test Testerson, 123 Test Lane, Testerville, TX"
(fn [ [first_name last_name]
{:keys [street-address city state]} ]
(str street-address ", " city ", " state ))
["Test Testerson"] test-address)
You’re testing a string against a function
what is test-address
? I'm setting it to {:street-address "123 Test Lane" :city "Testerville" :state "TX"}]
and getting false
yes, you should be evaluating the function rather than just defining it
You have four expressions in your =
call…
"Test Testerson, 123 Test Lane, Testerville, TX”
(fn [ [first_name last_name]
{:keys [street-address city state]} ]
(str street-address ", " city ", " state ))
["Test Testerson”]
test-address
So =
will attempt to compare those four for equality against each other.
(let [test-address {:street-address "123 Test Lane"
:city "Testerville"
:state "TX"}]
(= "Test Testerson, 123 Test Lane, Testerville, TX"
((fn [[first-name last-name]
{:keys [street-address city state]}]
(str first-name " " last-name ", " street-address ", " city ", " state ))
["Test" "Testerson"] test-address)))
@seancorfield I didn't realize =
could take more than two.
@roelof it was trying to destructure ["Test Testerson"]
. Note that that's only one string in a vector, not two.
Yes, and that’s really nice for <
and <=
etc since you can say (< a b c)
and it tests if a < b
and b < c
in one expression.
Thanks, I m have problems again with my parenteses if I have to make the function myself
yes. constant practice
do you use an editor that balances the parentheses nicely?
@roelofw note also that if the exercise requires you to supply the whole name in one string (i.e. "Test Testerson"
), you can break that into the requisite first-name/last-name vector with (clojure.string/split "Test Testerson" #" ")
.
of course, that would fail if the person's name is more than just two space-separated strings
@echristopherson yes, I use cursive within intelij