programming-beginners

sundarj 2018-03-12T00:02:52.000023Z

you might find looking up Lambda Calculus interesting; it shows you that all that is needed for a programming language is a notion of anonymous functions, and a notion of function application. with just those two things, you can write programs that do anything (though naturally it would take a much longer time than in bigger languages with more stuff provided for you, like arithmetic and variables)

sundarj 2018-03-12T00:04:51.000024Z

(it is the original mathematical system that lisps like Clojure are inspired by... as well as many other languages besides)

2018-03-12T00:09:28.000099Z

This is an area I really struggle with... I haven't done ANY maths since I was 16, and that was a long time ago. Calculus in general is something I can't imagine being able to get my head around just yet. Thank you for the video though - hopefully it will make it feel a little more accessible!

2018-03-12T00:11:25.000047Z

One thing that I like let statements for is you can use them for "executable documentation", like this

(defn std-deviation [values])
  (let [sum-of-values (reduce + values)
        average-of-values (/ sum-of-values (count values))
        deviations (map #(- % average-of-values) values)
        deviations-squared (map #(* % %) deviations)
        sum-of-deviations-squared (reduce + deviations-squared)
        mean-of-deviations-squared (/ sum-of-deviations-squared (count deviations-squared))]
       (Math/sqrt mean-of-deviations-squared))

2
sundarj 2018-03-12T00:11:39.000020Z

oh! don't worry, it's just called 'lambda calculus' - nothing to do with the other calculus (which i also struggle with) πŸ™‚

sundarj 2018-03-12T00:12:23.000065Z

mathematicians love to use the same words for completely different things

2018-03-12T00:12:47.000042Z

You can write this more concisely and/or elegantly, but the value of this style will come 3 months from now when you have to go in and fix something and you'd swear you've never seen this code before. But just by reading it, you can follow what each step is doing, even though there are no comments or docstrings.

2018-03-12T00:13:34.000131Z

I hope that math is at least close -- I've been travelling all week and I'm pretty bleary right now, but you get the idea.

1
2018-03-12T00:40:17.000138Z

That's helpful...!! πŸ˜‚ Thanks for the heads up, much appreciated.

😁 1
orestis 2018-03-12T08:52:57.000434Z

BTW this question is definitely suited for the #beginners channel β€” you are making progress πŸ™‚

πŸ‘ 2
😊 1
2018-03-12T12:09:55.000316Z

Definitely just a fluke, but that’s good to know! I’m going to a ClojureBridge event tonight, will try to recruit some more beginners to join me here.

4
practicalli-john 2018-03-12T23:37:02.000272Z

@amelia let can also be used to avoid repeating code inside a function. We did this at the dojo event this evening in the function to rotate a sequence of numbers by a given distance.

(defn rotate [distance number-sequence]
  (let [length (count number-sequence)
        position (mod distance length)]
    (drop position
          (take (+ length position) (cycle number-sequence)))))
In this example we used length and position several times. Using let makes the code smaller and also avoids running the same code several times.