Hi Todd,

Do you not have a working Raku/Perl6 REPL install? If you do, when
copying (single-quoted) code out of https://docs.raku.org , you could
try the following strategy of pasting into the REPL first, before
pasting code at the command line:

> my $repl_code = Q[my $map = Map.new('a', 1, 'b', 2); say $map{'a'}; say $map{ 
> 'a', 'b' };]
my $map = Map.new('a', 1, 'b', 2); say $map{'a'}; say $map{ 'a', 'b' };
> my $dashE_code = $repl_code.subst("\'", "\"", :g);
my $map = Map.new("a", 1, "b", 2); say $map{"a"}; say $map{ "a", "b" };
> say $dashE_code
my $map = Map.new("a", 1, "b", 2); say $map{"a"}; say $map{ "a", "b" };
>
> $*VM
moar (2019.07.1)

(Yes, capital "E" does nothing as a Raku/Perl6 command line flag, I
just wrote camelCase "dashE" to distinguish the letter "e").

HTH, Bill.



On Wed, Dec 4, 2019 at 11:06 AM ToddAndMargo via perl6-users
<perl6-us...@perl.org> wrote:
>
> On 2019-12-04 02:31, Simon Proctor wrote:
> > You're using doubles quotes for the string you're passing to Raku.
> >
> > This means the Shell will do variable interpolation. So it see's "my
> > $map = Map.new()" and puts the value of it's variable $map in their.
> >
> > But it doesn't exist. So Raku gets "my = Map.new()" (Note the space
> > where $map was). And complains. (You can see that in the error).
> >
> > I'd advise *always* suing single quotes to pass strings into Raku on the
> > command line. If you need single quotes in your code use q[] instead.
> >
> > So :
> >
> > p6 'my $map = Map.new("a", 1, "b", 2); say $map{"a"}; say $map{ "a", "b"
> > };'
> >
> > Should work just fine.
> >
> > %e := Map.new binds %e to the Map if you did %e = Map.new it will treat
> > the Map as the first element in a list and probably complain.
> >
> > On the other hand $e = Map.new is assigning to a Scalar so it doesn't
> > expect to be taking a list of values.
> >
> > If that makes sense?
> >
> > On Wed, 4 Dec 2019 at 10:22, ToddAndMargo via perl6-users
> > <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:
> >
> >     Hi All,
> >
> >     I am going through the examples on
> >     https://docs.perl6.org/type/Map.html
> >
> >     $ p6 "my $map = Map.new('a', 1, 'b', 2); say $map{'a'}; say $map{ 'a',
> >     'b' };"
> >     ===SORRY!=== Error while compiling -e
> >     Malformed my
> >     at -e:1
> >     ------> my  = Map.new('a', 1, 'b', 2); say {'a'};
> >
> >     What the heck is a 'Malformed my"?  I copied and pasted
> >     from the second set of examples.
> >
> >     And why is the first example:
> >            %e := Map.new
> >     and the second example
> >            $e = Map.new
> >     ?
> >
> >     Many thanks,
> >     -T
> >
> >
> >
> > --
> > Simon Proctor
> > Cognoscite aliquid novum cotidie
> >
> > http://www.khanate.co.uk/
>
> Ah Ha!  Thank you!
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to