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

Feature Request: trait for unimplemented subs/methods #6291

Closed
p6rt opened this issue May 29, 2017 · 7 comments
Closed

Feature Request: trait for unimplemented subs/methods #6291

p6rt opened this issue May 29, 2017 · 7 comments

Comments

@p6rt
Copy link

p6rt commented May 29, 2017

Migrated from rt.perl.org#131398 (status was 'rejected')

Searchable as RT131398$

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @BenGoldberg1

There should be a trait, called either nyi or unimplemented (choose your
favorite name and capitalization) which changes the subroutine or method
it's applied to so that, when it's called, it dies or fails with an X​::NYI
exception.

Alternatively, a slightly more generic solution might be more useful​:

role AutoDie[$class, $message?] {
  method CALL-ME(*@​_, *%_)) {
  die $class.new​: $message // |();
  }
};
role AutoFail[$class, $message?] {
  method CALL-ME(*@​_, *%_) {
  fail $class.new​: $message // |();
  }
}

sub foo does AutoFail[X​::NYI, "Sorry, we haven't gotten to foo yet!"] {...}

@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @zoffixznet

On Mon, 29 May 2017 16​:03​:29 -0700, ben-goldberg@​hotmail.com wrote​:

There should be a trait, called either nyi or unimplemented (choose your
favorite name and capitalization) which changes the subroutine or method
it's applied to so that, when it's called, it dies or fails with an X​::NYI
exception.

Alternatively, a slightly more generic solution might be more useful​:

role AutoDie[$class, $message?] {
method CALL-ME(*@​_, *%_)) {
die $class.new​: $message // |();
}
};
role AutoFail[$class, $message?] {
method CALL-ME(*@​_, *%_) {
fail $class.new​: $message // |();
}
}

sub foo does AutoFail[X​::NYI, "Sorry, we haven't gotten to foo yet!"] {...}

Thank you for the suggestion. However, I don't believe there's any serious demand for this feature, to justify it being included in core.

In fact, `does AutoFail[X​::NYI, "Sorry, we haven't gotten to foo yet!"] ` is 1 MORE characters to type than `die X​::NYI.new​: :feature<Sorry, we haven't gotten to foo yet!>`

Perhaps, you could publish it as a module​: https://docs.perl6.org/language/modules

@p6rt
Copy link
Author

p6rt commented May 29, 2017

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

@p6rt
Copy link
Author

p6rt commented May 29, 2017

@zoffixznet - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed May 29, 2017
@p6rt
Copy link
Author

p6rt commented May 29, 2017

From @AlexDaniel

But we already have ..., !!! and ???. Isn't it what you want?

<AlexDaniel> m​: sub foo() { … }; foo
<camelia> rakudo-moar 608e88​: OUTPUT​: «Stub code executed␤  in sub foo at <tmp> line 1␤  in block <unit> at <tmp> line 1␤␤Actually thrown at​:␤  in block <unit> at <tmp> line 1␤␤»
<AlexDaniel> m​: sub foo() { !!! }; foo
<camelia> rakudo-moar 608e88​: OUTPUT​: «Stub code executed␤  in sub foo at <tmp> line 1␤  in block <unit> at <tmp> line 1␤␤»
<AlexDaniel> m​: sub foo() { ??? }; foo
<camelia> rakudo-moar 608e88​: OUTPUT​: «Stub code executed␤  in sub foo at <tmp> line 1␤»

On 2017-05-29 16​:03​:29, ben-goldberg@​hotmail.com wrote​:

There should be a trait, called either nyi or unimplemented (choose your
favorite name and capitalization) which changes the subroutine or method
it's applied to so that, when it's called, it dies or fails with an X​::NYI
exception.

Alternatively, a slightly more generic solution might be more useful​:

role AutoDie[$class, $message?] {
method CALL-ME(*@​_, *%_)) {
die $class.new​: $message // |();
}
};
role AutoFail[$class, $message?] {
method CALL-ME(*@​_, *%_) {
fail $class.new​: $message // |();
}
}

sub foo does AutoFail[X​::NYI, "Sorry, we haven't gotten to foo yet!"] {...}

@p6rt
Copy link
Author

p6rt commented May 30, 2017

From 1parrota@gmail.com

That is so easy for a programmer to implement; I have an "nyi"
subroutine/function in the my skeleton scripts for both Perl 5 and
Bash. Is it worth cluttering the language?

@p6rt
Copy link
Author

p6rt commented May 30, 2017

From @geekosaur

As already mentioned, we have three such stubbers already. You can even put
a partial/incomplete implementation after them​: just terminate the ... or
w/e with a semicolon.

What none of them will do for you is allow a syntactically incorrect body.
But the proposed feature *also* will not allow that; you'd have to do it as
a slang to get that, and even then I suspect you will find error recovery /
parser resynchronization to be nontrivial.

On Tue, May 30, 2017 at 10​:21 AM, Parrot Raiser <1parrota@​gmail.com> wrote​:

That is so easy for a programmer to implement; I have an "nyi"
subroutine/function in the my skeleton scripts for both Perl 5 and
Bash. Is it worth cluttering the language?

--
brandon s allbery kf8nh sine nomine associates
allbery.b@​gmail.com ballbery@​sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

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