[plt-scheme] Scheme and R
On Mar 26, Neil Toronto wrote:
> Eli Barzilay wrote:
> >
> > * We have a `void' value that is the common result of side-effect
> > functions[1] -- we even have (surprise) a `when' expression, and
> > one-sided `if's. (It's not clear to me whether R implements
> > this using a void value or using something like (values) -- but
> > the choice between the two is irrelevant.)
>
> In this case, he finally got to the real problem. It's not so much
> that "if" doesn't require an else branch or that a single-branch
> "if" returns NULL, but that the designers decided to make some uses
> of it "just work" by defining operations like this:
>
> > paste("Hello", NULL, "there", sep="|")
> [1] "Hello||there"
>
> So string-appending NULL appends nothing.
So this is a problem with implicit coercion -- that's a valid point.
But R is far from being a unique offender in this department. (Even
Scheme treats any non-#f value as true.) The point about numeric(0)
being a value with a fuzzy meaning is a valid point too, but much
smaller than the slides make it look like.
> Back to lexical scope. To get around = creating bindings and how
> that makes it difficult to mutate outer scope variables, R has a
> special assignment operator <<- that operates on the nearest outer
> scope. It also creates bindings there if they don't already
> exist. It's like Python's "global" but for any level. Funky.
I completely agree about the bad karma you get when you try to make
`=' both a mutator and a binder. But again, that's an extremely
popular thorn in many languages... (FWIW, I think that creating a
local binding is better than creating a global binding like JS does.)
One solution is to forbid (this kind of) mutation completely, which is
what ML does, and a less extreme one is to have a proper distinction
between definitions and assignments (which JS kind of does, except
that it becomes bogus when assignments can create bindings).
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!