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

Function form of enum constructor #825

Closed
p6rt opened this issue Mar 22, 2009 · 8 comments
Closed

Function form of enum constructor #825

p6rt opened this issue Mar 22, 2009 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 22, 2009

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

Searchable as RT64102$

@p6rt
Copy link
Author

p6rt commented Mar 22, 2009

From @moritz

From S12​:

  There's also a pseudo-functional form​:

  $x = "Today" but day(Tue);

  which lets you cheat​:

  $x = "Today" but day(3);

Rakudo doesn't do that yet​:

$ perl6 -e 'enum A <B C D>; say A(1).perl'
invoke() not implemented in class 'Perl6Role'
current instr.​: '_block21' pc 106 (EVAL_20​:57)
called from Sub '!UNIT_START' pc 17513 (src/builtins/guts.pir​:350)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 950
(src/PCT/HLLCompiler.pir​:527)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1510
(src/PCT/HLLCompiler.pir​:798)
called from Sub 'parrot;Perl6;Compiler;main' pc 21852 (perl6.pir​:164)

@p6rt
Copy link
Author

p6rt commented May 14, 2009

From @masak

<masak> rakudo​: enum Month <Jan Feb Mar Apr May Jun Jul Aug Sep Oct
Nov Dec>; say May + 6.5
<p6eval> rakudo 612bcf​: OUTPUT«10.5␤»
<masak> is there any way I can get a month back from that?
<moritz_> masak​: NYI I think
<masak> moritz_​: but theoretically possible?
<moritz_> masak​: the spec says Month(10.5.int)
<masak> moritz_​: ooh, nice.
<pmichaud> rakudo​: enum Month <Jan Feb Mar Apr May Jun Jul Aug Sep Oct
Nov Dec>; say Month((May + 6.5).int).name;
<p6eval> rakudo 612bcf​: OUTPUT«invoke() not implemented in class
'Perl6Role'␤current
  instr.​: '_block30' pc 93 (EVAL_21​:54)␤»
* masak submits TODO ticket

@p6rt
Copy link
Author

p6rt commented Jul 30, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S12-enums/pseudo-functional.t

commit 82d963e5541998a12262bd5f66541a84ef6f0374
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Thu Jul 30 03​:37​:38 2009 +0000

  [t/spec] Tests for RT #​64102 (enum functional form)
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;27809 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-enums/pseudo-functional.t b/t/spec/S12-enums/pseudo-functional.t
new file mode 100644
index 0000000..bbdf121
--- /dev/null
+++ b/t/spec/S12-enums/pseudo-functional.t
@@ -0,0 +1,33 @@
+use v6;
+use Test;
+
+plan 13;
+
+# L<12/Enums/There's also a pseudo-functional form>
+
+enum day <<:Sun(1) Mon Tue Wed Thu Fri Sat>>;
+
+is day(Tue), day(3), 'day(Tue) same as day(3)';
+
+{
+    my $today_tue = 'Today' but day(Tue);
+    my $today_3   = 'Today' but day(3);
+
+    is $today_tue, $today_3, 'day(Tue) same as day(3) in variables';
+}
+
+my $x = 'Today' but day(Tue);
+
+ok $x ~~ day,      'day(Tue) is a day';
+ok $x ~~ Tue,      'day(Tue) is Tue';
+ok $x.does(Tue),   'day(Tue).does(Tue)';
+ok $x.day == Tue,  'day(Tue) == Tue';
+ok day($x) == Tue, 'day(day(Tue)) == Tue';
+ok $x.Tue,         'day(Tue).Tue';
+
+ok $x.day != Wed, 'day(Tue) != Wed';
+
+nok $x.does(Wed), '! day(Tue).does(Wed)';
+nok $x.Wed,       '! day(Tue).does(Wed)';
+nok 8.does(day),  '8 is not a day';
+nok 8 ~~ day,     '8 does not match day';

@p6rt
Copy link
Author

p6rt commented Jul 30, 2009

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

@p6rt
Copy link
Author

p6rt commented Oct 14, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S12-enums/thorough.t

commit 8785f522e418108dbccd2e289ed6829b6f1ecf83
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Wed Oct 14 03​:32​:23 2009 +0000

  [t/spec] Test for RT 65658
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;28783 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-enums/thorough.t b/t/spec/S12-enums/thorough.t
index 66598c6..d6fad0c 100644
--- a/t/spec/S12-enums/thorough.t
+++ b/t/spec/S12-enums/thorough.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 71;
+plan *;
 
 =begin description
 
@@ -110,4 +110,14 @@ ok Bool::True.perl ~~/^ 'Bool::True'/, 'Bool::True.perl';
     eval_dies_ok 'RT66886::c', 'accessing non-value of enum dies proper-like';
 }
 
+# RT #65658
+{
+    enum RT65658 <Todo Bug Feature Ticket>;
+    #?rakudo 2 skip 'RT 65658'
+    is RT65658(2), RT65658::Feature, 'can index enum by number';
+    is RT65658((Todo + 3.2).Int), RT65658::Ticket, 'enum and math and index';
+}
+
+done_testing;
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Oct 14, 2009

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

@p6rt
Copy link
Author

p6rt commented Mar 30, 2012

From @moritz

Works now, tests pass.

@p6rt p6rt closed this as completed Mar 30, 2012
@p6rt
Copy link
Author

p6rt commented Mar 30, 2012

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

@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant