[R] Simulation

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu May 14 13:28:17 CEST 2009


Barry Rowlingson wrote:
>> As a beginner, I agree .... the for loop is much clearer to me.
>>
>>     
>
>  [Warning: Contains mostly philosophy]
>   

maybe quasi ;)

> To me, the world and how I interact with it is procedural. When I want
> to break six eggs I do 'get six eggs, repeat "break egg" until all
> eggs broken'. 

yeah, that's the implementation level.  a typical recipe would not say
'for n from 1 to 6, break the nth egg'.  it'd rather say 'break the
eggs', which is closer to 'apply break to the eggs'.  you do of course
break the eggs sequentially (or?), but that's below the abstraction
useful for the recipe purpose. 

the example is quite good, in fact:  the lapply approach is more
appropriate, since what you're interested in is actually starting with
six eggs and ending with six broken eggs;  neither the particular order
you might have chosen, nor whether you break the eggs sequentially or in
parallel.  in a sense, 'for n from 1 to 6, break the nth egg' is a
particular operationalization of 'apply break to the eggs'. 


> I don't apply an instance of the break egg function over
> a range of eggs. 

but you do apply the break function to the ith egg in a for loop?  and
actually, the procedural way fo breaking eggs can be easily written
without a for loop, e.g., using a ruby-ish notation:

    eggs.each { |egg| break egg }

which says, 'for each egg, take the egg and break it', without using a
dummy index.

vQ




More information about the R-help mailing list