Skip to content
Prev 180299 / 398502 Next

Simulation

Barry Rowlingson wrote:
seriously, i do;  but it does depend on who those beginners are.  if
they come directly from c and the like, you're probably right.
well, that's one of the first things you learn on a programming
languages course that is not procedural programming-{centered,biased}. 
no need for prior lisp experience.  if messing with closures in not
involved (as here), no need for advanced discussion is needed.

also, the for looping may not be as trivial stuff to explain as you
might think.  note, you're talking about r, not c, and the treatment of
iterator variables in for loops in scripting languages differs:

    perl -e '
       $i = 0;
       for $i (1..5) { # iterate with $i
           };
       print "$i\n" '
    # 0

    ruby -e '
       i = 0
       for i in 1..5 # iterate with i
           end
       printf "%d\n", i '
    # 5
      
and you've gotten into explaining lexical scoping etc.
which population have you sampled from?  you may not be wrong, but give
some data.
you may be unhappy to learn that you're unaware of how the lapply
solution can still be nicely adapted here:

    lapply(1:n, rnorm, n=100, mean=0)
for a complete beginner, jump into for loops may not be that trivial as
you seem to think.  there's still quite some stuff to be explained to
clarify that

    i = 0
    for (i in 1:n)
       # do stuff
    print(i)

will print n, not 0.  unless n=0, of course.

vQ