From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Sat Mar  7 21:19:54 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Sat, 07 Mar 2009 21:19:54 +0100
Subject: [Rd] question
In-Reply-To: <971536df0903070846h3692e809ga195d126da37de5e@mail.gmail.com>
References: <000325575fc2f3201e046488263f@google.com>	
	<49B29233.7040205@idi.ntnu.no>	
	<971536df0903070806g38eee325q2e0cc5f2da8141b4@mail.gmail.com>	
	<49B2A2E1.20508@idi.ntnu.no>
	<971536df0903070846h3692e809ga195d126da37de5e@mail.gmail.com>
Message-ID: <49B2D6EA.4080907@idi.ntnu.no>

Gabor Grothendieck wrote:
>
> I've provided an argument against it and no one has provided one
> for it. The so-called identical code Ivo showed was not identical
> and, in fact, was flawed.  

no, you're wrong.  you think of the part where ivo shows what he'd like
to have;  the example i was referring to was almost identical with
yours, except for the explicit return and '=' used for assignment. 


> Your first/last example could be
> written:
>
> f <- function() letters
> L <- structure(f()[1:2], names = c("first", "last"))
>   

indeed, but:

- this still does not allow one to use the names directly, only as
L$first etc., with the syntactic and semantic (longer lookup times) penalty;

- using structure you add yet another source of performance penalty; a
quick naive benchmark hints that it doubles the time elapsed if the
returned list is inaccessible otherwise, and adds one order of magnitude
if the list has to be copied:

    f1= function() as.list(letters)
    f2 =local({ letters = as.list(letters);  function() letters })

    source('http://rbenchmark.googlecode.com/svn/trunk/benchmark.r')
    benchmark(replications=10000, columns=c('test', 'elapsed'),
       'f1 direct'=f1(),
       'f1 structure'=structure(f1(), names=letters),
       'f2 direct'=f2(),
       'f2 structure'=structure(f2(), names=letters))

    #           test elapsed
    # 1    f1 direct   0.171
    # 2 f1 structure   0.693
    # 3    f2 direct   0.048
    # 4 f2 structure   0.594

instead of a syntactically (and semantically, if done appropriately)
clean solution:

    c(a, b) = f()[1,3]
    # work with a and b

you offer a glut:

    l = structure(f()[1,3], names=c('a', 'b'))
    # work with l$a and l$b


> or one could define a function to do that without having
> to modify the language.   Given the relative infrequency
> of this it hardly seems to merit a language feature.
>   

infrequency of what?  of people's inventing ugly hacks to get arround
the inability to capture multiple return values directly?  sure, this is
a good argument against having someone do the job, but is it a good
argument against having the feature in the language?

vQ



[Rd] question
Wacek Kusnierczyk