Fork me on GitHub
#beginners
<
2016-11-15
>
echristopherson00:11:21

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.

echristopherson00:11:45

Also, even when my ns invocation doesn't use :refer-clojure, I get a bunch of clojure.core stuff in there anyway.

mtkp00:11:22

it seems to work when the fully qualified namespace is used

mtkp00:11:24

user=> ((get (ns-map 'clojure.string) 'join) [\a \b]) ;; "ab"

mtkp00:11:18

not sure about using a ns alias with ns-map though

echristopherson00:11:02

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

echristopherson00:11:20

or at least just s

Alex Miller (Clojure team)02:11:58

You can call 'keys' on any map to look at it's keys

echristopherson02:11:45

yes, I did... but it's huge

echristopherson02:11:08

oh, just did it again because it dawned on me that I could search the output... but I didn't find join

echristopherson02:11:49

or anything with string in it that doesn't belong to clojure.core

roelofw07:11:37

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) 

roelofw07:11:05

I see now this output :

("The Clojurer" "Go Time" "Lambda Guru") 

roelofw07:11:38

where I expect to see :

("aka The Clojurer" "aka Go Time" " aka Lambda Guru")

roelofw07:11:42

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)

andfadeev08:11:04

(let [[first-name last-name & aliases]
      (list "Rich" "Hickey" "The Clojurer" "Go Time" "Lambda Guru")]
                                (map #(str "aka " %) aliases))

andfadeev08:11:44

in your case let form returns the last statement which is aliases

andfadeev08:11:30

if you change to (map (str "aka %") aliases)), the syntax is wrong now

roelofw13:11:01

Can someone explain to me what the # before the str does exactly ?

Prakash13:11:13

# before a list makes it an anonymous function, for example (#(+ 1 %) 2 ) gives 3. here #(+ 1 %) is a function called with argument 2

roelofw13:11:37

oke, so with my code it makes a anymous function which makes the string I wanted

agile_geek13:11:41

@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))

roelofw13:11:07

Thanks, I still have a lot to learn

delaguardo13:11:29

#"regex_pattern" - this is regular expression in clojure

delaguardo13:11:38

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+".

roelofw14:11:04

Thanks. next problem making a string out of the seq

agile_geek14:11:30

Map str over the sequence

agile_geek14:11:00

see @andfadeev's snippet above

roelofw14:11:11

I thought of that but str (map #(str "aka " %) aliases) and (str #(map #(str "aka " %) aliases))` are both not working

agile_geek14:11:35

You want one string?

andfadeev14:11:09

(clojure.string/join [1 2 3])

andfadeev14:11:27

(reduce str [1 2 3])

andfadeev14:11:20

(apply str [1 2 3])

agile_geek14:11:59

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)

agile_geek14:11:40

but in this case coljure.string/join may be a better choice

roelofw14:11:06

oke, thanks, now a very late lunch and then I will try to make a fixed text before it

roelofw14:11:41

solved another koan

roelofw14:11:58

The koans get more and more difficult now

agile_geek14:11:13

Yeah some of them are quite tricky

roelofw14:11:51

but the tricky one are the ones who you learn the most 🙂

agile_geek14:11:34

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

roelofw16:11:10

@agile_geek is Luminus a good framework for beginners or can I better wait till Archnea is at version 1.0.0 ?

agile_geek16:11:00

@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.

dpsutton16:11:07

don't ever wait on the next thing coming out

dpsutton16:11:13

pick something that is in production and learn it

dpsutton16:11:18

and make many things with it

dpsutton16:11:49

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

dpsutton16:11:09

but if you start making stuff with a framework, any one--it really doesn't matter-- you can learn another one if need be

agile_geek16:11:20

BTW - vested interest warning. I'm a co-organiser of Clojure eXchange and invited @luke to speak so I would plug it!

roelofw16:11:20

oke, what do you experts then use when making website's ?

dpsutton16:11:47

just kdiding

cschep16:11:04

ha haaa, nooooo

dpsutton16:11:04

re-frame is nice, om.next is nice, and just a static site in hiccup is nice

agile_geek16:11:13

Most ppl I know pick and choose from a number of libraries rather than using a 'framework'

cschep16:11:48

yeah maybe check out compojure

dpsutton16:11:48

make 5 projects in luminous and then you'll have an opinion on stuff

dpsutton16:11:56

don't overthink it

cschep16:11:04

yeah, whatever site looks nicest, just make sure you finish a thing

dpsutton16:11:08

once you get used to creating things you'll not worry about stuff like this

cschep16:11:14

and whatever you hate about it, let that guide you to the next thing

agile_geek16:11:22

So a server side rendered site would probably include the following libraries in it's stack: * ring * compojure * hiccup

agile_geek16:11:07

For a Single Page App - as mentioned ^^ - reagent or reagent/re-frame or om.next

agile_geek16:11:08

Interestingly just about all the SPA libraries wrap React.js

roelofw16:11:26

oke, thanks

roelofw16:11:01

first I have to try to solve all clojure koans and understand some principles and doing some 4clojure problems

roelofw16:11:27

then looking for some good tutorials or books about web development

agile_geek16:11:54

is a decent book. Basically a set of tutorials.

agile_geek16:11:10

second edition covers SPAs as well

roelofw16:11:41

oke, I wil look for that one. Does this book only covers luminus ?

roelofw17:11:26

Anyone who can give me a hint here :

"All together now!"
  (= "Test Testerson, 123 Test Lane, Testerville, TX"
     (___ ["Test" "Testerson"] test-address)))   

roelofw17:11:28

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]

roelofw17:11:46

but it looks to me that this is not what the challenge wanted

dpsutton17:11:50

do you just want to string join themn?

dpsutton17:11:00

looks like you need to supply the correct function?

dpsutton17:11:16

but we don't know what test you are doing

roelofw17:11:05

This is all I get from the clojure koans that I have to solve

roelofw17:11:25

I have to enter something on the _ line to make this work

dpsutton17:11:49

and its in the position that you would put a function

dpsutton17:11:55

but also, the koans are organized by topic

roelofw17:11:58

I could do str but then the test-adress is not in the right order

dpsutton17:11:07

so this might be a string library koan

roelofw17:11:12

I have to destruct it somehow

dpsutton17:11:13

but you're asking about destructuring

roelofw17:11:37

it is on the destruct topic

dpsutton17:11:40

so is this a destructuring koan or a string library one

dpsutton17:11:01

how long have you spent on this?

roelofw17:11:13

and the test adres is given like this :

(def test-address
  {:street-address "123 Test Lane"
   :city "Testerville"
   :state "TX"}) 

roelofw17:11:22

not very long.

dpsutton17:11:29

well take some time and play around with it

dpsutton17:11:46

its always good to get stuck and then figure it out on your own

dpsutton17:11:04

everyone is always happy to help when you're stuck but its important to learn how to unstuck yourself as well

roelofw17:11:30

of course. At this moment Im, confused how to play with it

roelofw17:11:05

The first part I have to take out of the list and the part after it . it looks I have to destruct it

roelofw17:11:33

hmm, map str or map identity does not make the first part

roelofw17:11:38

It looks like I have to make a function which destruct everything first

roelofw17:11:48

Am I on the right track ?

devo17:11:34

@roelofw yes, and you can destructure arguments inside of a parameter list. http://clojure.org/guides/destructuring

roelofw17:11:53

@devo thanks. time to experiment more on that way

roelofw18:11:46

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) 

seancorfield19:11:40

You’re testing a string against a function

echristopherson19:11:42

what is test-address? I'm setting it to {:street-address "123 Test Lane" :city "Testerville" :state "TX"}] and getting false

echristopherson19:11:02

yes, you should be evaluating the function rather than just defining it

roelofw19:11:20

oke, so I need to use apply here ?

roelofw19:11:05

I thought ' (str street-address ", " city ", " state )` evalute the function

seancorfield19:11:39

You have four expressions in your = call…

seancorfield19:11:48

"Test Testerson, 123 Test Lane, Testerville, TX”

seancorfield19:11:59

(fn [ [first_name last_name]
          {:keys [street-address city state]} ]
       (str street-address ", " city ", " state ))

seancorfield19:11:13

["Test Testerson”]

seancorfield19:11:34

So = will attempt to compare those four for equality against each other.

echristopherson19:11:55

(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)))

roelofw19:11:20

oke, I thought that [first_name last_name] destruct the ["test" "testeron"] part

echristopherson19:11:23

@seancorfield I didn't realize = could take more than two.

roelofw19:11:56

and {:keys [street-address city state]} destruct the test-adress

echristopherson19:11:13

@roelof it was trying to destructure ["Test Testerson"]. Note that that's only one string in a vector, not two.

seancorfield19:11:28

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.

roelofw19:11:53

Thanks, I m have problems again with my parenteses if I have to make the function myself

roelofw19:11:34

so more exercises to do , so I learn which part belongs to which part

echristopherson19:11:54

yes. constant practice

echristopherson19:11:11

do you use an editor that balances the parentheses nicely?

echristopherson19:11:46

@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" #" ").

echristopherson19:11:41

of course, that would fail if the person's name is more than just two space-separated strings

roelofw19:11:00

@echristopherson yes, I use cursive within intelij

roelofw20:11:27

time to sleep now