Skip to content

Instantly share code, notes, and snippets.

@pmichaud
Created January 25, 2010 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmichaud/286131 to your computer and use it in GitHub Desktop.
Save pmichaud/286131 to your computer and use it in GitHub Desktop.
"List":
($a, @b, 1..1000, $c).map( { ... } );
We need the lazy interpolating characteristics of list
context, but we don't want to be preserving every value
(e.g., the 1..1000) that is processed. Also, the elements
that are processed by .map are the original containers.
A "List" (but not the Parcel that produced it) is mutable
because we consume the values as we iterate over the list.
"Array":
my @x = ($a, @b, 1..1000, $c);
my $y = [$a, @b, 1..1000, $c];
We again have interpolation in list context, but the
values produced from iterating the List/Parcel
are remembered in the reified portion of the Array.
Also, the elements in the Array are "eager" "copies" of
the rhs values from the List/Parcel, as opposed to
binding to any containers directly, thus after
the above assignment any changes to $a, @b, or $c
aren't reflected in @x.
"Seq":
my $z = ($a, @b, 1..1000, $c);
An immutable form of Array -- values produced from
iterating the List/Parcel are remembered in the reified
portion of the Array, and are "eager" "copies", but
neither the Seq nor its elements can act as lvalues.
Slurpy parameter:
sub foo(*@v) { ... }
foo($a, @b, 1..1000, $c);
@v is Positional like an Array, but like a List the
elements of @v are bound to the (flattened) argument
containers as opposed to being "eager" "copies". Also,
it would seem that @v is itself mutable like an Array
(one can push/unshift values into @v).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment