Skip to content

Instantly share code, notes, and snippets.

@stmuk

stmuk/GLR Secret

Last active September 10, 2015 17:31
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 stmuk/de108fc081e45876d1e4 to your computer and use it in GitHub Desktop.
Save stmuk/de108fc081e45876d1e4 to your computer and use it in GitHub Desktop.
FLATTENING
> my @array = (1,(2,3),4)
[1 (2 3) 4]
> @array.elems
3
# to get old behaviour
> my @array = (1,(2,3),4).flat
[1 2 3 4]
> @array.elems
4
SINGLE ARG RULE
[[1,2]] != [[1,2],]
LIST - (shallowly) Immutable sequence of values
> say (1,2,3).WHAT
(List)
> say (1,2,3).[2]
3
> my @otherthings := (1,2,3) # note :=
(1 2 3) # List
> @otherthings[0]=2
Cannot modify an immutable Int
# nine; List has shallow immutability, i.e. one cannot change the list after construction, but the contained items may be changeable (think an Array contained in a List).
ARRAY - Mutable sequence of values
> say [1,2,3].WHAT
(Array)
> say (Array).^mro
((Array) (List) (Cool) (Any) (Mu))
> say [1,2,3].[2]
3
> say [1,2,3].push(4)
[1 2 3 4]
# note assignment changes data type
> my @things = (1,2,3)
[1 2 3] # Array
SLIP - Immutable sequence of values that dissolve into parent lists
> my $slip = slip(1,2,3)
(1 2 3)
> say $slip.WHAT
(Slip)
> dd $slip
$slip = $(1, 2, 3)
SEQ
> my $grep = (1,2,3).grep(2)
(2)
> say $grep.WHAT
(Seq)
OLD
> say [1,2]<>.perl
[1, 2]<>
> say (1,).perl
(1,)
NEW
> say [1,2]<>.perl
[1, 2]
> say (1,).perl
(1)
OLD
% perl6
> [1,2].lol
NEW
> "{[1,2]}"
1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment