Fork me on GitHub
#beginners
<
2017-04-22
>
sbauer01:04:04

For your project.clj, what version of clojure are you using?

sbauer01:04:25

ah, 1.8.0 based on the log?

vitruvia01:04:33

yes. I actually started with clojure today; downloaded the most recent version

sbauer01:04:14

i know lighttable can have problems with 1.9 at the moment, so just wanted to be sure

vitruvia01:04:18

I found on google that many people had this problem even on previous versions, but their solutions did not work for me

noisesmith01:04:58

vitruvia: what happens if you run lein repl directly in your project directory in a terminal?

sbauer01:04:23

I agree with noisesmith, making sure your project runs fine via lein would help

vitruvia01:04:19

starts normally

vitruvia01:04:42

That's what shows up

noisesmith01:04:04

OK - so we know the project is fine, it's specifically a lighttable issue...

vitruvia01:04:30

yeah.. maybe I should open an issue there

vitruvia01:04:36

But I'd still like to solve it on the short term, though =(

sbauer01:04:49

I think opening an issue is a good idea since I can't tell what is exactly wrong, unfortunately. For the issue, if you could provide the project.clj, or even better, a link to the github repo, it would make reproducing the problem easier

sbauer01:04:28

Short term, I don't have a better solution than using lein repl or giving cursive a try 😞

vitruvia01:04:30

There isn't a repo for this project, I'm just trying to make a repl in lighttable (and I'm copying someone else's tutorial, I don't even know how to commit and pull on github yet). Also it happens whenever I try to run any code, and even when I try to update the plugin.

sbauer01:04:50

ah, interesting

vitruvia01:04:01

But I'll open an issue, that is indeed the best choice. Thanks for trying, too, I'll stick with the lein repl for now =]

sbauer01:04:40

if you can provide the link to the tutorial, that might help as well

noisesmith01:04:03

there's a few things that make lein repl a lot less painful (though of course not as powerful of what instarepl does for you) - load-file, the :reload optional arg to require, find-doc, source - all are worth checking out

noisesmith01:04:24

oh and apropos too

vitruvia01:04:33

Thanks, I guess I'll try lein repl, then

vitruvia01:04:57

although I got used to having my code all marked in pretty colors =(

sbauer01:04:12

would you know which version of light table you were using?

vitruvia01:04:33

seems to be the latest

sbauer01:04:41

it is for the moment

sbauer01:04:30

so i was able to follow the first few steps of that tutorial and connect to the project fine via light table

sbauer01:04:02

im on lein 2.7.1 if that helps

vitruvia01:04:29

that is good to know

vitruvia01:04:37

there must be something wrong with my setup

noisesmith01:04:20

a common issue on windows is permission to open network ports - though if lein gets away with it I'd think lighttable would too...

vitruvia01:04:27

I wouldn't know how to fix that

vitruvia01:04:37

I'm thinking of reinstalling clojure using lein

vitruvia01:04:54

I used the windows installer and found some people saying it has issues

noisesmith01:04:02

clojure is just a jar

noisesmith01:04:20

if lein repl works, you have clojure

vitruvia01:04:34

I guess I'll open the issue and see what happens

vitruvia01:04:41

I'm ultra sleepy anyways

vitruvia01:04:47

but really thanks a lot for the support

foamdino13:04:17

given a lazy seq of [ [:keyword value] [:keyword value] [:keyword value] ], how can I create a hash-map so that all the values associated with the same :keyword are summed?

foamdino13:04:57

I've attempted (doseq) (map) and (reduce) however I'm trying to use (update) to mutate an initialize empty map, but it just seems incorrect to do this and I'm positive that there is an elegant solution that I'm missing

dpsutton13:04:07

and pay attention to your types: you have a seq of key value pairs and merge with works on maps. but luckily keyvalue pair => map is very easy

foamdino13:04:49

^^ since I was constructing the kv pairs myself I can just as easily create hash-maps - the issue now is that I'm getting duplicates

dpsutton13:04:06

well that's a desired intermediate step. now play with merge-with

dpsutton13:04:25

didn't you expect duplicates and you wanted a way to combine them?

dpsutton13:04:00

nope. it asks if 0 is less than 1 which is almost always true

dpsutton13:04:23

and in the case that 0 is less than 1 it returns b

dpsutton13:04:32

so your function is (fn [a b] b)

dpsutton13:04:03

so your reducer function is more or less identity and will return the last item in the collection you are reducing over

vitruvia13:04:19

is 0 ever not less than 1?

dpsutton13:04:11

if its equal then yeah

dpsutton13:04:47

so how do you want to compare your a and b here?

vitruvia13:04:49

this is actually from koans; it already works but I'm trying to undertand why

vitruvia13:04:11

I'm having trouble understanding how this returns the longest word

dpsutton13:04:07

because the longest word is last

dpsutton13:04:10

put longest first

dpsutton13:04:30

your function returns the second of two words you compare, not the last. so over a list it returns the last in the list

dpsutton13:04:53

but your function only returns true

vitruvia13:04:40

well that is pretty confusing xD if you always want to return b then why cant you just write (fn [a b] b)?

dpsutton13:04:59

this is your function

vitruvia13:04:51

yeah but the people who wrote the koans made a strange choice by writing it like this xD pretty confusing for a beginner. I spent hours trying to figure what this if(0<1) could possibly mean

dpsutton13:04:02

which koan?

vitruvia13:04:27

clojure koans, I don't suppose there is more than 1, is there?

dpsutton13:04:47

but the meaning of (if (< 0 1) ..) should be clear. it's comparing the numbers

dpsutton13:04:59

well inside the clojure koans there are a hundred or so...

vitruvia13:04:21

oh yeah, this is the last exercise of number 8 (higher order functions)

vitruvia13:04:09

yeah the meaning is obvious, but since they could have just returned b I started thinking there was a reason for this comparison that I was not seeing

vitruvia13:04:12

but anyways, thanks

dpsutton13:04:18

there's a lot in this style:

dpsutton13:04:22

(meditations
  "You will face many decisions"
  (= __ (if (false? (= 4 5))
          :a
          :b))

  "Some of them leave you no alternative"
  (= __ (if (> 4 3)
          []))

  "And in such a situation you may have nothing"
  (= __ (if (nil? 0)
          [:a :b :c]))

  "In others your alternative may be interesting"
  (= :glory (if (not (empty? ()))
              :doom
              __))

dpsutton13:04:34

(= 4 5), (> 4 3), etc

vitruvia13:04:05

I guess its my fault for not being used to it

dpsutton13:04:14

nah no faults

vitruvia13:04:22

but thinking about it was a good exercise

dpsutton13:04:30

just looks like they like this little surprising style

vitruvia13:04:47

gotta get used to different styles

dpsutton13:04:48

@foamdino did you make some progress?

dpsutton13:04:51

(merge-with + {:a -1} {:a -1} {:a -1} {:a -1})
;; => {:a -4}

wallydrag14:04:12

hi all, i am trying to solve this problem where i need to create a string of first 3 characters of a string and I am trying to use clojure.string/replace i am trying to write something like this

(clojure.string/replace "14451" #"^.{0,2}" "")

wallydrag14:04:59

but i am able to either remove first few chars or the last few chars and since the input string can be of arbitrary length, that won’t work

noisesmith14:04:51

@wallydrag if it's just by count, then subs might be simpler

noisesmith14:04:21

you just have to do some math to make the 0, 1, and 2 char strings work

wallydrag14:04:52

yeah, i can use subs or i can use map to fetch them

wallydrag14:04:00

i was just curious to use replace

noisesmith14:04:39

for map, lazy-seqs on strings are almost never appropriate. I recommended subs because it's specialized for exactly the case of using N characters of a string or dropping N chars of a string by position.

vitruvia17:04:18

is there a way to get help with functions on lein? Like get what args they take, what they return, etc

noisesmith17:04:42

@vitruvia in any repl you can run (doc f) or (find-doc re-or-string)

noisesmith17:04:08

(rarely that doesn't work and you can fix it by running (use 'clojure.repl))

vitruvia18:04:41

where can I learn more about keywords?

vitruvia18:04:11

for example I don't undertand why there is a when funtion and then a :when keyword that somehow does the same thing

noisesmith18:04:15

:when is a special case for specific forms

noisesmith18:04:22

it's not a general thing

noisesmith18:04:13

generally keywords act as a function that looks the keyword up in an associative data structure

noisesmith18:04:57

and they are often used as switches for function behavior or enums, or as you've seen, they can also be syntax in some forms

noisesmith18:04:35

no, because :when is a special syntax in for and doseq forms

noisesmith18:04:58

similarly you can use (spit "file.txt" "some text" :append true) - the keyword is just use as a way to name a syntactic option

noisesmith18:04:33

and it's up to the code you are calling to look for keywords and decide what to do with them

vitruvia19:04:07

alright, thanks!