Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Perl6 PDF: Some subroutine examples don't work when declared before call #2069

Closed
p6rt opened this issue Aug 14, 2010 · 10 comments
Closed

Comments

@p6rt
Copy link

p6rt commented Aug 14, 2010

Migrated from rt.perl.org#77218 (status was 'resolved')

Searchable as RT77218$

@p6rt
Copy link
Author

p6rt commented Aug 14, 2010

From sohtil@gmail.com

Hi!

A class declaration without C<;> at the end gives a confusing error
when followed by a module declaration.
(Confusing if the class actually has several lines of content.)

Lithos

$ cat test.pl
class C { }
module M { }
$ ./perl6 test.pl
===SORRY!===
Confused at line 1, near "class C { "
$ ./perl6 --version

This is Rakudo Perl 6, version 2010.07-115-g0839993 built on parrot 2.6.0 r48341

With a semicolon at the end of the first line it works​:

$ cat test.pl
class C { };
module M { }
$ ./perl6 test.pl
$

@p6rt
Copy link
Author

p6rt commented Aug 14, 2010

From @jkeenan

The New York City Rakudo Star study group is working its way through
the Using Perl PDF from Rakudo's github site. Working through the
examples in Chapter 4, Subs and Signatures, we are puzzled by the
fact that, at least *some of the time*, when you declare a subroutine
*before* you call it, the sub will fail to run. When you move the
sub declaration *after* the call, it works.

WORKS​:

use v6;

orderbeer('Hobgoblin', 1);

sub orderbeer($type, $pints) {
  say ($pints == 1 ?? 'A pint' !! "$pints pints") ~ " of $type,
please.";
}

FAILS​:

use v6;

sub orderbeer($type, $pints) {
  say ($pints == 1 ?? 'A pint' !! "$pints pints") ~ " of $type,
please.";
}

orderbeer('Hobgoblin', 1);

Error message

===SORRY!===
Confused at line 3, near "sub orderb"

shell returned 1

On the other hand, other subroutines work regardless of whether they
are declared before or after the point at which they are called.

WORKS EITHER WAY​:

use v6;

sub announce-time(​:dinner($supper) = '8pm') {
  say "we eat dinner at $supper";
}

announce-time(dinner => '9pm');

Can you clarify?

Thank you very much.
kid51

@p6rt
Copy link
Author

p6rt commented Aug 14, 2010

From @pmichaud

On Sat, Aug 14, 2010 at 10​:55​:57AM -0700, James Keenan wrote​:

FAILS​:

use v6;

sub orderbeer($type, $pints) {
say ($pints == 1 ?? 'A pint' !! "$pints pints") ~ " of $type,
please.";
}

orderbeer('Hobgoblin', 1);

The problem here is that Rakudo is mis-interpreting the "or" that
follows the sub as being an infix​:<or>, at which point it gets confused.
In other words, the expression parser doesn't yet recognize the
closing brace as being the end of a statement.

Anyway, it's definitely a bug in Rakudo, and I'll try to fix it soon.

Pm

@p6rt
Copy link
Author

p6rt commented Aug 14, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 15, 2010

From sohtil@gmail.com

The problem with

  sub orderbeer {
  }
  orderbeer

looks similar to the problem I reported as #​77208

  class C { }
  module M { }

which might be due to "module" starting with "mod".

@p6rt
Copy link
Author

p6rt commented Aug 15, 2010

From sohtil@gmail.com

See also #​77218 about a problem with

  sub orderbeer {
  }
  orderbeer()

that might have a similar cause.

@p6rt
Copy link
Author

p6rt commented Aug 15, 2010

sohtil@gmail.com - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Aug 24, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S02-names/identifier.t

commit e4bce85a069b2b0af6fb9b71d719ebaf9f296b36
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Tue Aug 24 08​:47​:16 2010 +0000

  [t/spec] tests for RT #​77218, identifiers that start with an operator name
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;32095 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S02-names/identifier.t b/t/spec/S02-names/identifier.t
index 8bc9b52..60515e3 100644
--- a/t/spec/S02-names/identifier.t
+++ b/t/spec/S02-names/identifier.t
@@ -1,7 +1,7 @@
 use v6;
 use Test;
 
-plan 18;
+plan 20;
 
 # L<S02/Names/An identifier is composed of an alphabetic character>
 
@@ -84,6 +84,25 @@ plan 18;
     is my($x), 23, 'call to sub named "my" works';
 }
 
+# RT #77218
+# Rakudo had troubles with identifiers whos prefix is an alphanumeric infix
+# operator; for example 'sub order' would fail because 'order' begins with
+# 'or'
+{
+    my $res;
+    sub order-beer($what) { $res = "a $what please!" };
+    order-beer('Pils');
+    is $res, 'a Pils please!',
+        'can call subroutines whos name begin with an alphabetic infix (or)';
+
+    my $tempo;
+    sub andante() { $tempo = 'walking pace' }
+    andante;
+
+    is $tempo, 'walking pace',
+        'can call subroutines whos name begin with an alphabetic infix (and)';
+}
+
 done_testing;
 
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Aug 24, 2010

From @moritz

Thanks for the report, I've fixed the problem in Rakudo.

@p6rt
Copy link
Author

p6rt commented Aug 24, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Aug 24, 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant