My WordPress Blog
So, I just discovered the Unix tool bc. Given that I’m a Mac guy as much for the Unix as for anything else, this got me interested. bc is a mathematical programming language and interactive calculator. The latter is useful, sometimes I need a calculator, and for what I’m doing that instant, a terminal app…
For instance, I could do this- fun op-(x,y) = x+y This makes the ‘-’ operator do integer addition. Reals? Hah, no subtracting them now! Fails type checking on anything but ints. I can also do: fun op-(x) = ~x; Now, the ‘-’ operator does nothing except spawn error messages wherever it is used. Well, wherever…
Yeah. Didn’t do that. Now I have half a dozen functions, 50 or so lines of code, I have no idea if it works or not. At least I’ve traced this function as for sure not working. And the other functions that it depends on are tested and work correctly. So even if the…
(if exp1 then exp2 else exp3) div (if exp4 then exp5 else exp6) Is valid and for at least some problems, is entirely reasonable. I think the key to SML, at least so far… *everything* is an expression. Any complete statement returns a value, and anything that returns a value counts as an expression. Ok,…
fun gcd (x,y) = if y = 0 then x else gcd(y, x mod y) I’ve wondered how to easily do this in code, without having to brute force it. Turns out Euclid worked out the algorithm over 2,000 years ago. Even if you aren’t a programmer, you can probably follow this code if you…
I was all like, “I need to write a perl script to make these M3u playlists”… then reality hit me and was all “Dumbass. OS X is Unix. Use IO redirection and pipes”. This shell command creates a playlist from files in the current directory. ls | grep -v *.m3u | cat – > playlist.m3u…
Finished the current assignments and lectures for my Programming Languages course on Coursera, so I figured I’d go and do some other stuff in ML. ML is a functional language, very heavy on recursion among other fun differences from imperative and OO languages. Here’s a solution to Project Euler problem 1, summing all multiples of…
Good resources. The Coursera “Learn To Program” course is quite nice. sourcetocode: Here is my compilation of sites offering online courses (most for free!) Coursera. Courses offered by many prestigious universities on different areas (Maths, Computing Science, Literature, Bussinnes, etc.). All of them are free and certificates of completion are given. The courses consist…