Fork me on GitHub
#beginners
<
2017-09-25
>
dpsutton00:09:44

i believe so

dpsutton00:09:51

(to are they they same command)

dpsutton00:09:43

in fact, you define your own test-runner (defun my-test-runner () (cider-refresh) (cider-run-all-tests)) I'm not sure what the actual commands are but elisp can be quite nice

vuuvi14:09:16

question guys - I don’t like doing 4clojure. The answers are too easy to find and I don’t feel like I’m learning anything from these puzzles. Are there techniques I can use to make 4clojure a more enjoyable experience or should I focus my learning efforts elsewhere?

ghadi14:09:01

Have you tried the harder problems?

noisesmith14:09:01

are you comparing your answers to others?

ghadi14:09:07

and that ^

noisesmith14:09:40

because for me the solving of the problem was pretty quick, but when I saw other people's answers I realized they were doing things in a very simple way I didn't quite get yet

dpsutton14:09:56

> The answers are too easy to find I don't understand this?

noisesmith14:09:05

but if your answer looks like the good ones - you probably don't need 4clojure any more

dpsutton14:09:10

don't look for them?

dpsutton14:09:42

i love seeing multiple ways to solve the same problem. compare your own to how someone else did it. sometimes you saw an easier path, sometimes they had a much more clever solution

vuuvi14:09:46

@dpsutton if I’m stuck on a problem I can simply google the question and the second result is an answer

vuuvi14:09:58

where can I compare answers to people? the only way I’ve found answers is by googling.

noisesmith15:09:04

oh, then don't do that

dpsutton15:09:24

yeah that seems like a self-imposed problem

chris15:09:57

or, if you don't like 4clojure, just don't use it

chris15:09:06

think of something you want to build and go do it

vuuvi15:09:12

@chris yeah that seems like the route I am going to take. I never have had much success with any kind of online problem solving website - I always finding myself just looking up the answer

sundarj15:09:51

my problem with 4clojure has always been that it's blind, you don't get any output to see where you're going wrong

sundarj15:09:14

i know you can use an external one, but still seems silly

dpsutton15:09:54

i was working on an emacs mode that would pull down the code and tests so that you could work in emacs and then just copy it back in

dpsutton15:09:14

i agree, writing lisp in a text box isn't great, but it was pretty simple to grab the things and throw them in a buffer locally

vuuvi15:09:47

yeah that’s definitely the way to do it. Although they should explain that using a REPL is the real way to practice writing clojure

asiegf16:09:24

@alexkeyes Maybe you could try http://exercism.io ; you get to progress with your own development environment and I really learned a lot by viewing other people answers

vuuvi16:09:45

@asiegfried thanks!

dpsutton16:09:39

i did that for a bit but got annoyed that you have to have a whole project.clj file and project structure for each problem

vuuvi16:09:20

@dpsutton but doesn’t that better represent the real world? More than a text box on a website?

dpsutton16:09:50

from a practical standpoint, if you want to do 50 exercises, there's just gonna be 50 projects rather than 50 namespaces. some are very simple and quick and the time to crank up jvm and tooling approaches the time to craft the solution. i would rather just work in a exercise project rather than 50 different exercise projects

vuuvi16:09:32

that’s a good point

dpsutton16:09:43

but that being said, the exercises were very good. so its worth the slight annoyance

vuuvi16:09:10

good to know

noisesmith17:09:46

if you were encouraged to use community libraries that would make for an odd set of exercises I think, but it might justify using leiningen

rcustodio17:09:55

I would like to know what you guys use for private dependencies, (corporation)

rcustodio17:09:28

archiva? I've found this one https://github.com/tobyhede/lein-git-deps but doesnt work properly

rcustodio17:09:44

Because the dependencies is on gitlab (or github)

noisesmith17:09:41

I have used s3-wagon-private which has some annoying quirks (like printing a pointless stack trace message when the repo is checked for an artifact that isn't there), but it works. We address the meaningless stack traces by reordering our :repositories with the ^:replace metadata so that the private repo is checked last https://github.com/s3-wagon-private/s3-wagon-private

vuuvi17:09:42

@noisesmith how was your weekend escape from the internet?

noisesmith17:09:44

it was good - and turned out to only be mostly an escape 😄 they had wifi but I didn't have much time for that, so many old friends to catch up with (it was a friend's wedding)

vuuvi18:09:02

oh that sounds great

rcustodio18:09:41

Thanks @noisesmith, I will test it

genec21:09:18

Hi. I'm trying to use core.match on record types but can't seem to get syntax right. Any help with this toy example would be appreciated. I'm familiar with OCaml's pattern matching and trying to do something similar based on the type of the record and also de-structure records field values. Thanks. (defrecord A []) (defrecord B [x]) (defrecord C [x y]) (defn eval [r] (match [(type r) r] [(:or (A []) "A" (B [x]) (str "B, x = " x) (C [x y]) (str "C, x = " x " y = " y))]))

genec21:09:54

Or would it be more idiomatic to use cond or should I just stick to Protocols and create an Evaluate protocol for each type?

genec22:09:04

this works (defn eval-cond [x] (condp = (type x) A "A" B "B" C "C")) (eval-cond (A.)) (eval-cond (B. 100)) (eval-cond (->C 100 200))

ghadi22:09:12

Stick to plain maps

ghadi22:09:26

If you're not implementing protocols

genec22:09:38

@ghadi and if I'm using records then I should be implementing protocols and not pattern matching on the type?

ghadi22:09:39

You don't need records

genec22:09:41

and when using maps, would you suggest adding a :type key / value to use for matching?

ghadi22:09:11

There are many ways to attack this problem. You might look at multimethods too

ghadi22:09:22

Typed maps (aka defrecords) aren't so ubiquitous in Clojure as they are in e.g. Python

genec22:09:16

I was leaning towards multi methods, but read Eric Nomads post on them and he seems to say use multi methods for language features and records / protocols for program types

genec22:09:38

I'm coming from OCaml where pattern matching on types is used everywhere

genec22:09:04

I'll read though this again and agree that maps and multi-methods seem like more than enough for what I'm doing. https://www.braveclojure.com/multimethods-records-protocols/

ghadi22:09:08

I love OCaml but sure, it's a very different world over here. Type dispatch isn't central, but it's available when you need it

ghadi22:09:34

I haven't used core.match in 8 years, have been just fine

ghadi22:09:05

(though pattern matching is a separate thing from type dispatch)

genec22:09:55

@ghadi thanks for the help

genec22:09:20

seems like maps with multi-methods are the cleanest, just dispatch on :type. This post lead me to trying records, but I think I miss-understood him at first. http://www.lispcast.com/deftype-vs-defrecord

seancorfield23:09:02

This blog post from 2011 is probably still good advice when trying to get your head around Clojure's different kinds of types: https://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/