Re: experiential exercises

[email protected] Mon, 08 Jul 2002 08:22:10 -0500
Newsgroups perl.trainers
Message-ID <[email protected]>
sounds like this could work well for perl references. I can imagine a
series of examples students are supposed to represent by acting out
roles. The examples cause them to change the roles they use as they
realize there are more things to track than they initially thought. You
could expand this to cover things like closures and local variables as well.


my $x = "hello\n";
print $x;
    # students might have one role "$x"
    # or maybe two, "$x" and "hello\n"


my $x = "hello\n";
my $rx = \$x;
print $$rx;
    # students will need to add an "$rx" role
    # might add a "memory address" sort of role


my $x = "hello\n";
my $rx = \$x;
print $rx, "\n";
    # now they need a "reference type" role
    # and memory address if they didn't have it


my $x = "hello\n";
my $rx = \$x;
print $rx, $x;
$$rx = "farewell\n";
print $rx, $x;
print $x;
    # if value wasn't separate from memory address
    # before this point, it should be now


This is off the top of my head, and there's probably better examples to
use. In fact, if you were to actually try this, you might want to
conjure up examples on the fly to "steer" their understanding. Some
groups would probably come up with completely valid ways of representing
all of the relevant information which don't at all reflect what perl
actually does. In those cases, you could either applaud them for comming
up with a workable way of understanding things and/or you could point
out how perl actually accomplishes the same thing in a different manner.

-matt