Profile

Cover photo
John Merrill
48 followers|11,665 views
AboutPostsPhotosVideos

Stream

John Merrill

Shared publicly  - 
 
(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.
1
Add a comment...

John Merrill

Shared publicly  - 
 
is 51 today. Deal with it, youngsters.
2
Karen Sjöström's profile photoJohn Merrill's profile photoRachel Sullivan's profile photoNathalie Criou's profile photo
5 comments
 
HAPPY BIRTHDAY
Add a comment...

John Merrill

Shared publicly  - 
If you were to take all the babies and arrange them by awesomeness, and then make a boxplot of that data, you may notice that there is one baby that
2
Lea Kissner's profile photo
 
Cute! Unfortunately, she is sufficiently unusual in terms of size that she outgrew that long ago.
Add a comment...

John Merrill

Shared publicly  - 
1
Lea Kissner's profile photoJim Merrill's profile photo
2 comments
 
I want that shirt.

Also - yeah. That was kinda the point of my paper, Dad. That and she was craaaaazy. :P
Add a comment...

John Merrill

Shared publicly  - 
 
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.
1
Add a comment...

John Merrill

Shared publicly  - 
 
82F and sunny. Even the dragonflies are out enjoying the weather.
1
Add a comment...

John Merrill

Shared publicly  - 
 
Pronunciation matters. (H/t +Lea Kissner)
1
Add a comment...

John Merrill

Shared publicly  - 
 
Columbus zoo photos
1
Add a comment...
In his circles
55 people
Have him in circles
48 people
Tyler Mathison's profile photo
Susan Merrill's profile photo
Theodore Vassilakis's profile photo
Rene Fuller's profile photo
Pei Yin's profile photo
Jeanne Griggs's profile photo
Ian Greenfield's profile photo
Ladislav Székely's profile photo
Han-Wen Nienhuys's profile photo

John Merrill

Shared publicly  - 
 
Just needs a statue of Tom Lehrer to complete ths image.
**** originally shared:
 
Periodic table.
3
Karen Sjöström's profile photo
 
Your obscure reference really gives your age away, sonny!
Add a comment...

John Merrill

Shared publicly  - 
 
Evil Cauchy distribution
3
Rachel Sullivan's profile photoKaren Sjöström's profile photo
2 comments
 
At least it's not mean
Add a comment...

John Merrill

Shared publicly  - 
 
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?
Rick Klau originally shared:
 
This is the best article you'll read about baseball today. (h/t +Ken Norton)

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
1
John Merrill's profile photo
 
I personally liked the repetition of how Casilla was a plant. A potted plant, that is -- he was just standing there, waving his fronds.

And, as a pure bonus, Ceda faced four batters during that half inning...well, three batters and a plant. He walked the plant. The other three? Three for three.
Add a comment...

John Merrill

Shared publicly  - 
 
Neurobiology of dead cephalopods...
Spencer Chen originally shared:
 
This is a dish called Odori-Don. It has a dead squid on top that “dances” when Soy Sauce is poured on it, activating it’s neurons. (so f'ing cool! remember, it's DEAD!)
1
Rachel Sullivan's profile photoKaren Sjöström's profile photoKrista Elliott's profile photoJohn Merrill's profile photo
6 comments
 
All right, so it's a VERY FRESH zombie octopus.
Add a comment...
People
In his circles
55 people
Have him in circles
48 people
Tyler Mathison's profile photo
Susan Merrill's profile photo
Theodore Vassilakis's profile photo
Rene Fuller's profile photo
Pei Yin's profile photo
Jeanne Griggs's profile photo
Ian Greenfield's profile photo
Ladislav Székely's profile photo
Han-Wen Nienhuys's profile photo
Basic Information
Gender
Male
Story
Tagline
I are a porgarmer. I rot code.
Links
Contributor to