On Thu, Dec 18, 2008 at 1:37 PM, Wacek Kusnierczyk <
Waclaw.Marcin.Kusnierczyk@idi.ntnu.no> wrote:

> Kenn Konstabel wrote:
> >> ...foo({x = 2})
> ...
>
> This is legal but doesn't do what you probably expect -- although
> > documentation for `<-` says the value (returned by <-) is 'value' i.e.
> > whatever is on the right side ...
>

What do you expect this to do that is different from what it does, namely
assign 2 to x and call foo on the value 2, which is the same as the value of
x?  As long as foo doesn't do tricks with substitute, all the following
should be identical:

         foo(x<-2)
         foo((x<-2))
         foo((x=2))
         foo({x=2})
         foo({x<-2})
         foo(a=(x=2))
         {x=2; foo(invisible(x))}
         {x<-2; foo(invisible(x))}
         {x=2; foo(invisible(2))}
         {x<-2; foo(invisible(2))}
         foo(a=x<-2)

Oh, and this would work if the surface concrete syntax allowed it:

         foo(a=x=2)      # syntax error

as seen by

> q<-quote( foo(a=(x=2)) )
> r<-q
> r[[2]]<-r[[2]][[2]]
> q
foo(a = (x = 2))
> r
foo(a = x = 2)
> foo <- function (a) a/3
> identical(eval(q),eval(r))
[1] TRUE

To show what's going on here more clearly:

> lang.to.list <-
    function(ex){
      if (storage.mode(ex)=="language")
         c(class=class(ex),lapply(ex,lang.to.list))
      else ex}
> str(lang.to.list(q))
List of 3
 $ class: chr "call"
 $      : symbol foo
 $ a    :List of 3
  ..$ class: chr "("
  ..$      : symbol (
  ..$      :List of 4
  .. ..$ class: chr "="
  .. ..$      : symbol =
  .. ..$      : symbol x
  .. ..$      : num 2

> str(lang.to.list(r))
List of 3
 $ class: chr "call"
 $      : symbol foo
 $ a    :List of 4
  ..$ class: chr "="
  ..$      : symbol =
  ..$      : symbol x
  ..$      : num 2

Of course, if foo *does* use substitute, all bets are off, because it would
capture the argument as an unevaluated expression and could do whatever it
wanted with it.


> > If you really hate <-, you should do either
> > foo({(x=42)})   # or ....
>

Why the () nested within the {} ? Either one alone is enough.

> foo({x=42; x})  # or even ...
> > foo(a=force(x=43))
> yes, i think the last one should be the only valid version.


I don't see how force does anything useful here.


> who said = is more intuitive for assignments?  i said i prefer it, and
> that's because of aesthetics, silly me.  in an earlier post, someone
> said it is more natural for his students [1].  argue to the contrary.
>
> it depends on how you program, mostly.  if you're doing functional
> programming with no reassignments, = is just perfect.
>

The character string denoting assignment really has no deep importance,
whether it's = (Fortran, C); := (Algol, Pascal, Ada); <- (R); : (Maxima);
etc.  However, using the same symbol to denote two quite different things
which can be meaningful in the same contexts, namely assignment and argument
naming, strikes me as a poor design decision.

             -s

	[[alternative HTML version deleted]]

