John Merrill
49 followers -
I are a porgarmer. I rot code.
I are a porgarmer. I rot code.

49 followers
John's posts
(This is a programming languages post. If you don't care about them, you might want to skip it.)

I do a lot of machine learning, and a number of my customers like using a stats package. I use R in that case, which I like very much. Unfortunately, though, like a lot of domain-specific-languages, R's behavior is sometimes quirky. You see, R is essentially functional, with pass-by-demand syntax. What does pass-by-demand mean? Well, it's like pass-by-value, except when it's pass-by-name, unless something gets evaluated, in which case, it's exactly like pass-by-value. Confused? You should be.

Well, let's look at the following two assignments:

a <- function(x) {
function(y) x + y
}

b <- function(x) {
a <- x
function(y) x + y
}

If I run a(17), I get back a function. When I run b(17), I get a function. The two functions behave identically on all inputs, each function call returns a function which adds seventeen (17) to its argument.

Cool.

Now look at the following snippets:

seventeen <- 17
a_ret <- a(seventeen)
b_ret <- b(seventeen)

In a call-by-value language, these functions would be identical. seventeen would be evaluated (to 17), that value would be stacked, and the return values would both be "the function which adds seventeen (17) to its argument." In R, though...

Well, look it's easy:

> a_ret <- a(seventeen)
> b_ret <- b(seventeen)
>
> a_ret(21)
[1] 38
> b_ret(21)
[1] 38
> seventeen = 21
> a_ret(21)
[1] 38
> a_ret <- a(seventeen)
> seventeen = 21
> a_ret(21)
[1] 42
> seventeen <- 17
> b_ret <- b(seventeen)
> a_ret <- a(seventeen)
> seventeen <- 21
> a_ret(21)
[1] 42
> b_ret(21)
[1] 38
> seventeen <- 17
> a_ret(21)
[1] 42

Now, let's look at this session in detail. The first time through, we call all the functions, and they behave the same. Then, we change the value of seventeen, and the still behave the same. Then we reconstitute them, change the value of seventeen before calling either function, and they behave differently. (Try it yourself. The text isn't going anywhere.)

Stop and look at the definition of the function b. The variable x is NEVER USED. An optimizing compiler for an Algol-like language would look at a pure assignment to a variable which doesn't ever get used and eliminate it. You can't do that in R.﻿
is 51 today. Deal with it, youngsters.﻿
Post has shared content
Just needs a statue of Tom Lehrer to complete ths image.﻿
Periodic table.﻿
Post has attachment
Post has attachment
Evil Cauchy distribution﻿
Post has attachment
, who is interested in Ada Lovelace.

http://blog.jgc.org/2011/09/lovelaces-leap.html﻿
OK, I didn't know that it was possible for an eight-port switch to fail. I've never heard of it before...but guess what happened today? Yeah...our wired network went belly up.

Grrr.﻿
Post has shared content
OK, this is just...weird. I mean, given the batter's stance, he had a strike zone a mile wide...and the pitcher still didn't get him to strike out?﻿
This is the best article you'll read about baseball today. (h/t )

Favorite line (there are many hilarious lines, but this one had me laugh out loud):

"Casilla stepped in, but only barely, standing more than a full Pedroia away from home plate."

http://mlb.sbnation.com/2011/8/15/2364354/santiago-casilla-batting-video-jose-ceda-giants-marlins﻿
Post has attachment
82F and sunny. Even the dragonflies are out enjoying the weather.﻿
Post has shared content