Fork me on GitHub
#beginners
<
2016-11-11
>
dorianc.b00:11:25

I’m trying to really nail the difference between cons and conj and this stackoverflow seems to cover it well enough but is there anything else that I should know [7:22] http://stackoverflow.com/questions/3008411/clojure-consseq-vs-conjlist

agile_geek08:11:05

@roelofw Nice to see you are making progress. Don't lose heart. We all feel like this to start (or I certainly did!). It's not so much that Clojure is hard, it's that if you are used to object oriented programming (oop) and imperative programming you need to 'rewire' your brain to think functionally. This is like learning a musical instrument...it takes time and practice to make it 'muscle memory' and you find yourself taking two steps forward and one back. I went through the same kind of relearning moving from procedural programming to object oriented programming 20 years ago but I think the transition from imperative style to functional style is harder (or it just might be me being a lot older this time with a lot to unlearn!) Stick with it and this community will try and help. If you can find a Clojure user group near you it helps enormously to get help in person. I spent months learning in isolation but when I started contracting in London I went to the ldn clj user group dojo's and that helped accelerate my learning.

joshkh11:11:55

noobie question here. can spec be used to force a map into a particular shape? specifically, i have a function that accepts a map as an argument and i want to drop all keys that aren't found in :req-un/:opt-un

roelofw12:11:27

@agile_geek thanks for the encourance words. I now trying the path of clojure koans and 4clojure after that.

roelofw12:11:03

Is this a good solution : "When things cannot be equal, they must be different" (not= :true true))

roelofw12:11:34

and why is here the answer 2 : (get [1 2 3] 1)

kauko12:11:04

you're accessing a vector using an index

kauko12:11:14

0 index is the first element

roelofw12:11:19

then I would expect a zero and not a two. 1 is the first element in the list

kauko12:11:51

(get [1 2 3] 0) returns the first element in the list

kauko12:11:01

I meant, the positions in a list always start from 0

roelofw12:11:45

oke, so the 1 is rhe index . so it will be the second item in the list because the counting starts with zero

roelofw14:11:44

how to solve this one : (string/last-index-of "hello world, hello" "hello") CompilerException java.lang.RuntimeException: No such namespace: string, compiling:(C:\Users\rwobb\AppData\Local\Temp\form-init3402967420287402181.clj:1:1)

st14:11:15

fully qualify string

roelofw14:11:57

and how do I do that

cschep14:11:07

you either want to require it to your file

cschep14:11:14

or in your REPL i guess

cschep14:11:18

or just type the whole name of it outright

cschep14:11:34

in this case it is

cschep14:11:51

(clojure.string/last-index-of “hello world, hello” “hello”)

roelofw14:11:33

Thanks both, I now can work on the rest of the clojure koans , string chapter

dpsutton14:11:57

@roelofw look through that chapter again. hopefully you just missed how to reference the clojure string namespace. If not, open an issue and point out that you had an issue with it and hopefully it can be udpated

dpsutton14:11:29

the less friction for newcomers the better, and I'm sure whoever runs the project would like the feedback

roelofw14:11:04

@dpsutton as far as I can see, there is no mentioned how to reference something ?

roelofw14:11:12

or I have overlooked it

st14:11:16

(clojure.string/last-index-of "hello world, hello" “hello”)

roelofw14:11:08

yep, but there is no mentioned how to reference to the string in the string exercise file

dpsutton14:11:36

its referenced in the koan namespace

dpsutton14:11:40

you need to be in that namespace

dpsutton15:11:21

so as you fill out the koans and get them to pass, you should be evaluating the file

dpsutton15:11:25

or running the script

roelofw15:11:06

oke, I was working in the repl to test a idea I had to solve a koan

dpsutton15:11:18

ah for sure

roelofw15:11:24

the koan run works without any problems

roelofw15:11:05

It is right that \n is not counting in a string. So this one is true `"Even if at first glance they aren't" (= true (string/blank? " \n \t ")) `

dpsutton15:11:41

just evaluate (string/blank? "\n")

dpsutton15:11:02

but from the docs > True if s is nil, empty, or contains only whitespace.

cschep15:11:59

“\n” is a whitespace character

roelofw15:11:00

(string/blank? "\n") gives true

dpsutton15:11:41

and if you're curious to figure out how to find out on your own, you can read the source

dpsutton15:11:56

I google for clojure string, got the api documentation, which had a link to the source

dpsutton15:11:14

and there you can see that it just calls Character/isWhiteSpace

dpsutton15:11:23

and from there, I just looked up what java thinks is white space

roelofw15:11:02

dpsutton thanks if I want to be a good clojure developer I have to learn to do things on my own

dpsutton15:11:32

oh for sure. doing the above is a great way to learn how things work on your own

dpsutton15:11:46

i was just giving you an example of how i learned the answer to your question "on my own"

roelofw15:11:26

and I appriciate that

seancorfield16:11:26

Some more good tips for learning on your own: in the REPL you can use these functions:

(apropos “blank”) ;; searches for functions in your loaded namespaces that have blank in the name or docstring
(doc string/blank?) ;; displays the docstring for a function
(source string/blank?) ;; displays the source code for a function
(javadoc Character) ;; returns true and opens your browser at the page for the Character class
So documentation and source code is directly accessible in your REPL.

roelofw17:11:26

Can someone explain this one :

(first {:fname "Aaron" :lname "Bedra"})
-> [:lname "Bedra"] 

roelofw17:11:14

I was expecting to see [:fname "Aaron"] because that is the first item

Prakash18:11:23

this is because maps are not ordered

roelofw18:11:28

oke, so the next time there could be another outcome ? @pcbalodi

donaldball18:11:46

not with the same map

donaldball18:11:07

seq order is guaranteed to be consistent for the same map at least within the same jvm

roelofw18:11:04

oke, very confusing but I will accept it

cschep18:11:57

it’s definitely best to not worry about the order of keys in a map, and if you need some order to use a data structure designed with order in mind.

jculp18:11:59

is it easier to use vim or cursive for a beginner?

jswart18:11:06

Do you already use vim?

jswart18:11:24

then use vim

jswart18:11:35

Fireplace is pretty simple

jswart18:11:55

As a vim user, there is no way to put the koolaid down. Not having vim bindings just feels cruel.

jswart18:11:15

I lasted ~1 year away, and 10 months of that was spent in Spacemacs. An emacs distro that uses vim keybindings.

jculp18:11:38

cool — is clojure for the brave and true still the best resource?

jswart18:11:51

Well, the author is a personal friend of mine so YES!

jswart18:11:00

but yeah, its a great book

jculp18:11:14

i bought it a few months ago but never had time to pick it up

jswart18:11:32

Yeah its a great book, I wish it existed when I was learning

jculp18:11:05

what other vim plugins are useful?

jswart18:11:10

not sure. I use fireplace sometimes. I mostly just use vim and a repl.

jswart18:11:34

It might be faster, but I’ve had some difficult bugs from stale REPL/CIDER states

jswart18:11:37

so I’m just not super into it

jculp18:11:38

how do you handle all the parens haha

jswart18:11:56

parens are easy. after awhile they become obvious. vim keybindings make parens simple.

jswart18:11:30

select a chunk of parens

jswart18:11:34

then just do stuff to it

jswart18:11:39

I really don’t like the Paredit stuff

jswart18:11:58

it is great I think if you’ve never used modal editing, but in general I like the flexibilty of just basic vim

jswart18:11:13

slurping and barfing is pretty great though

jswart18:11:17

you should try out all the things

jswart18:11:22

this is just what works for me

jculp18:11:59

whats the % doing in that find command?

jswart18:11:18

so that command is: select text, go to the next paren and then jump to the closing paren

jswart18:11:32

so on a paren, you can jump to the won that opens or closes it

jswart18:11:49

ie: you can “grab” an expression to delete it, move it, etc.

jswart18:11:57

that is enough for me most of the time

jswart18:11:08

In general I try not to have functions that are so big that parens are a problem.

jswart18:11:18

like > 5 lines is way too much

jswart18:11:30

if you are doing java interop, then maybe you have no choice

jswart18:11:50

but honestly… anymore after a few years of clojure it doesn’t look any different than python or javascript

jswart18:11:04

so I’m happier to have basic vim, because I work with several langauges each day

dorianc.b18:11:54

Clojure from the ground up is also a great resource. I’m using both clojure the brave and from the ground up

roelofw18:11:46

@cshepp that is what i also mean

roelofw19:11:45

IM using the clojure koans and programming clojure book

markx19:11:10

@jculp I personally find Parinfer very handy.

devo19:11:42

@jculp tpope and guns on git have a bunch of useful plugins.

josh_tackett21:11:14

Hey any Javascript guys know what I’m doing wrong here:

function removeProperty(obj, prop) {
  if ( obj.hasOwnProperty(prop) ){
    delete obj.prop;
    return true;
  } else {
    return false;
  }}

josh_tackett21:11:27

justtrying to remove the prop if its there and return true otherwise false

cschep22:11:14

what’s wrong about it?

cschep22:11:05

ohh are you passing prop as a string

cschep22:11:14

looks like you got the answer in cjscript