Re: Introspection
Thanks. That's exactly what I wanted. On 8/29/18, Fernando Santagata wrote: > That's documented here: > > https://docs.perl6.org/language/variables#&?ROUTINE > > On Wed, Aug 29, 2018 at 5:51 PM Parrot Raiser <1parr...@gmail.com> wrote: > >> Could someone supply a link to a clear example of a Perl 6 subroutine >> finding its own name, please? >> I know there's a method, but haven't managed to produce an effective >> search string for an example of its use. >> > > > -- > Fernando Santagata >
Re: Introspection
That's documented here: https://docs.perl6.org/language/variables#&?ROUTINE On Wed, Aug 29, 2018 at 5:51 PM Parrot Raiser <1parr...@gmail.com> wrote: > Could someone supply a link to a clear example of a Perl 6 subroutine > finding its own name, please? > I know there's a method, but haven't managed to produce an effective > search string for an example of its use. > -- Fernando Santagata
Introspection
Could someone supply a link to a clear example of a Perl 6 subroutine finding its own name, please? I know there's a method, but haven't managed to produce an effective search string for an example of its use.
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 5:25 PM, Henk van Oers wrote: >>> From 2005, but still a fantastic primer on testing in Perl. > Sorry Tom. > I think you must read a book about OO. I will go back and review OO, Henk. Thanks. Best, -Tom
Re: Object Introspection for Existence of Methods: How?
[...] From 2005, but still a fantastic primer on testing in Perl. Sorry Tom. I think you must read a book about OO. Unsubscribing from this list now, Regards, Henk
Re: Object Introspection for Existence of Methods: How?
(resending to p6u) Tom (>>), Henk (>): > > That doesn't seem to work with private methods. Any trick to accomplish > > that? > > What part of 'private' did you mis? Henk, that's an unnecessarily harsh way to say "Private methods are private and not visible or testable outside of the class." In my copious spare $dayjob, I teach. Any kind of teaching seems to involve taking both the teacher's stance (of knowing stuff and being able to phrase it right) and the learner's stance (trying to remember what it was like *not* to know something). Pulling that off, and being able to speedily convey people along all intermediate points from not-knowing to knowing, is a weirdly satisfying experience. Questioning the querent's knowledge sends the message (to the querent and to passive beginner onlookers) that it's somehow a bad idea to ask direct questions. It's also a non-constructive response, putting the focus on how much someone knows or doesn't know, rather than the subject matter. The querent responded very well in this case ("I think I need to learn a lot more about testing in general."), but lesser provocations than yours have led to flame wars online. (A) "Private methods are private and not visible or testable outside of the class." is only the most proximal answer to the question. There's also (B) "You can do most things using the MOP, including finding private methods." (Pointed out by moritz++.) $ perl6 -e 'class C { method !foo {} }; say C.^find_private_method("foo")' foo Or how about (C) "The underlying reason we only test on the public interface is so that the internal bits of an object can change freely without breaking the test." as a response? Or maybe even (D) "There are ways to test just on the *consequences* of a (public) message-send, such that you don't even *want* to introspect the private parts." (Which leads to a more BDD-y style of testing.) Either of these answers helps convey the querent to a better understanding. Teaching is about compassion. Literally "feeling with" the querent. If you find yourself unable to do that when replying, consider whether you're simply having a bad day. If the problem persists, ask yourself whether your reply is representative of the people on p6u who enjoy helping scurry people forwards along the learning curve. // Carl
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 9:35 AM, Bruce Gray wrote: >> Any recommendations for books on the subject? > http://shop.oreilly.com/product/9780596100926.do > Perl Testing: A Developer's Notebook > by Ian Langworth and Chromatic > > From 2005, but still a fantastic primer on testing in Perl. Thanks, Bruce. -Tom
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 11:28 AM, B. Estrade wrote: > As good as this book is, it's still Perl 5 specific. So watch out if you're > coming from Perl 5 land and Heaven forbid you're looking to do traditional > things, you might get scolded for asking a reasonable question. o_O. Roger! Thanks, Brett. -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 23, 2015, at 8:11 AM, Tom Browder wrote: > On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder wrote: >> From your and Henk's comments, I think I need to learn a lot more about >> testing in general. > > Any recommendations for books on the subject? > > -Tom http://shop.oreilly.com/product/9780596100926.do Perl Testing: A Developer's Notebook by Ian Langworth and Chromatic From 2005, but still a fantastic primer on testing in Perl. — Hope this helps, Bruce Gray (Util of PerlMonks)
Re: Object Introspection for Existence of Methods: How?
As good as this book is, it's still Perl 5 specific. So watch out if you're coming from Perl 5 land and Heaven forbid you're looking to do traditional things, you might get scolded for asking a reasonable question. o_O. Brett On Mon, Mar 23, 2015 at 10:41 AM, Elizabeth Mattijsen wrote: > > On 23 Mar 2015, at 14:11, Tom Browder wrote: > > On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder > wrote: > >> From your and Henk's comments, I think I need to learn a lot more about > >> testing in general. > > Any recommendations for books on the subject? > > Perl Testing - A Developer’s notebook: > > http://shop.oreilly.com/product/9780596100926.do > > > Liz
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 10:41 AM, Elizabeth Mattijsen wrote: >> On 23 Mar 2015, at 14:11, Tom Browder wrote: >> Any recommendations for books on the subject? > > Perl Testing - A Developer’s notebook: Thanks, Liz--getting it! -Tom
Re: Object Introspection for Existence of Methods: How?
> On 23 Mar 2015, at 14:11, Tom Browder wrote: > On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder wrote: >> From your and Henk's comments, I think I need to learn a lot more about >> testing in general. > Any recommendations for books on the subject? Perl Testing - A Developer’s notebook: http://shop.oreilly.com/product/9780596100926.do Liz
Re: Object Introspection for Existence of Methods: How?
On Mon, Mar 23, 2015 at 7:04 AM, Tom Browder wrote: > From your and Henk's comments, I think I need to learn a lot more about > testing in general. Any recommendations for books on the subject? -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 23, 2015 3:19 AM, "Moritz Lenz" wrote: > That said, I wonder why tests need introspection at all. I mean, you test by > doing example calls and comparing to expected example return values. No argument from me. I am at the point of trying to replicate, in Perl 6, somene else's test suite (done for a Perl 5 class) and I have not, in general, been questioning the need for each test. And I must admit I may have gone overboard doing some things just because they can be done in Perl 6 and seem to be in the spirit of the original author's intent. >From your and Henk's comments, I think I need to learn a lot more about testing in general. Thanks. Best, -Tom
Re: Object Introspection for Existence of Methods: How?
Hi, On 03/23/2015 01:48 AM, Henk van Oers wrote: On Sun, 22 Mar 2015, Tom Browder wrote: On Sun, Mar 22, 2015 at 7:13 PM, Henk van Oers wrote: On Sun, 22 Mar 2015, Tom Browder wrote: I'm trying to write a test. To test what? Your own typo's? The tests are for a public Perl 6 module translated from an existing Perl 5 module. Do Perl 6 modules not need tests? Yes they need tests. If so, which ones do they need? The public interface. I agree with this part (test the public interface), but if you really want/need to, you *can* introspect the private methods too. See http://doc.perl6.org/type/Metamodel::PrivateMethodContainer#method_private_method_table Note that private methods aren't inherited, so getting the private methods from one level in the class hierarchy (the one that you want to call the private method of) is enough. That said, I wonder why tests need introspection at all. I mean, you test by doing example calls and comparing to expected example return values. (If those are generated methods, IMHO there is no point in testing all generated instances). Cheers, Moritz
Re: Object Introspection for Existence of Methods: How?
On Sun, Mar 22, 2015 at 7:48 PM, Henk van Oers wrote: > On Sun, 22 Mar 2015, Tom Browder wrote: >> Do Perl 6 modules not need tests? > Yes they need tests. >> If so, which ones do they need? > The public interface. >> and which can be left off? > The private stuff. > You can not test for 'random_name'. > This is not about Perl. It's OO-programming. Okay, Henk. Thanks. Best, -Tom
Re: Object Introspection for Existence of Methods: How?
On Sun, 22 Mar 2015, Tom Browder wrote: On Sun, Mar 22, 2015 at 7:13 PM, Henk van Oers wrote: On Sun, 22 Mar 2015, Tom Browder wrote: I'm trying to write a test. To test what? Your own typo's? The tests are for a public Perl 6 module translated from an existing Perl 5 module. Do Perl 6 modules not need tests? Yes they need tests. If so, which ones do they need? The public interface. and which can be left off? The private stuff. You can not test for 'random_name'. This is not about Perl. It's OO-programming. -- Henk
Re: Object Introspection for Existence of Methods: How?
On Sun, Mar 22, 2015 at 7:13 PM, Henk van Oers wrote: > On Sun, 22 Mar 2015, Tom Browder wrote: >> I'm trying to write a test. > To test what? Your own typo's? The tests are for a public Perl 6 module translated from an existing Perl 5 module. Do Perl 6 modules not need tests? If so, which ones do they need? and which can be left off? -Tom
Re: Object Introspection for Existence of Methods: How?
On Sun, 22 Mar 2015, Tom Browder wrote: On Sun, Mar 22, 2015 at 6:22 PM, Henk van Oers wrote: On Sun, 22 Mar 2015, Tom Browder wrote: On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder wrote: On Mar 20, 2015 1:51 PM, "Tobias Leich" wrote: if $obj.^can($method_name) {... That doesn't seem to work with private methods. Any trick to accomplish that? What part of 'private' did you mis? If you write private methods you do not need introspection. I'm trying to write a test. To test what? Your own typo's? -- Henk
Re: Object Introspection for Existence of Methods: How?
On Sun, Mar 22, 2015 at 6:22 PM, Henk van Oers wrote: > On Sun, 22 Mar 2015, Tom Browder wrote: >> On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder >> wrote: >>> On Mar 20, 2015 1:51 PM, "Tobias Leich" wrote: >>>> if $obj.^can($method_name) {... >> That doesn't seem to work with private methods. Any trick to accomplish >> that? > What part of 'private' did you mis? > If you write private methods you do not need introspection. I'm trying to write a test. -Tom
Re: Object Introspection for Existence of Methods: How?
On Sun, 22 Mar 2015, Tom Browder wrote: On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder wrote: On Mar 20, 2015 1:51 PM, "Tobias Leich" wrote: if $obj.^can($method_name) {... That doesn't seem to work with private methods. Any trick to accomplish that? What part of 'private' did you mis? If you write private methods you do not need introspection. -- Henk
Re: Object Introspection for Existence of Methods: How?
On Fri, Mar 20, 2015 at 2:02 PM, Tom Browder wrote: > On Mar 20, 2015 1:51 PM, "Tobias Leich" wrote: >> if $obj.^can($method_name) {... That doesn't seem to work with private methods. Any trick to accomplish that? -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 2:07 PM, "Will Coleda" wrote: > > > use Test; > > class bar { method foo () {}} > > ok bar.can("foo"), "stuff"; > ok 1 - stuff Oops (I say as I slap my forehead)! Thanks, Will. -Tom
Re: Object Introspection for Existence of Methods: How?
> use Test; > class bar { method foo () {}} > ok bar.can("foo"), "stuff"; ok 1 - stuff On Fri, Mar 20, 2015 at 3:00 PM, Tom Browder wrote: > On Mar 20, 2015 1:50 PM, "Will Coleda" wrote: >> class bar { method foo () {}} >> my bar $a = bar.new(); >> say so $a.can("foo"); > > Great! > >> I'm not sure this warrants a new _ok method. > > How would you do it with an existing test? > > Thanks, Will. > > Cheers! > > -Tom -- Will "Coke" Coleda
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 1:51 PM, "Tobias Leich" wrote: > if $obj.^can($method_name) {... Thanks, Tobias. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
On Mar 20, 2015 1:50 PM, "Will Coleda" wrote: > class bar { method foo () {}} > my bar $a = bar.new(); > say so $a.can("foo"); Great! > I'm not sure this warrants a new _ok method. How would you do it with an existing test? Thanks, Will. Cheers! -Tom
Re: Object Introspection for Existence of Methods: How?
if $obj.^can($method_name) {... Am 20.03.2015 um 19:38 schrieb Tom Browder: > I am trying to create a testing subroutine to detect if a class object > has a certain method. > > I want it to look something like this: > > my $obj = Foo.new(); > can_ok($obj, 'method1'); > > sub can_ok($obj, Str $method_name) { > if $obj.{$method_name}:exists { > say "ok"; > return True; > } > else { > say "not ok"; > return False; > } > } > > A similar function can detect valid attributes, but this or variants > I've tried don't. > > How can I test for the existence of a method? > > Thanks. > > Cheers! > > -Tom
Re: Object Introspection for Existence of Methods: How?
class bar { method foo () {}} my bar $a = bar.new(); say so $a.can("foo"); True my Int $b; say so $b.can("foo"); False I'm not sure this warrants a new _ok method. On Fri, Mar 20, 2015 at 2:38 PM, Tom Browder wrote: > I am trying to create a testing subroutine to detect if a class object > has a certain method. > > I want it to look something like this: > > my $obj = Foo.new(); > can_ok($obj, 'method1'); > > sub can_ok($obj, Str $method_name) { > if $obj.{$method_name}:exists { > say "ok"; > return True; > } > else { > say "not ok"; > return False; > } > } > > A similar function can detect valid attributes, but this or variants > I've tried don't. > > How can I test for the existence of a method? > > Thanks. > > Cheers! > > -Tom -- Will "Coke" Coleda
Object Introspection for Existence of Methods: How?
I am trying to create a testing subroutine to detect if a class object has a certain method. I want it to look something like this: my $obj = Foo.new(); can_ok($obj, 'method1'); sub can_ok($obj, Str $method_name) { if $obj.{$method_name}:exists { say "ok"; return True; } else { say "not ok"; return False; } } A similar function can detect valid attributes, but this or variants I've tried don't. How can I test for the existence of a method? Thanks. Cheers! -Tom
Re: Introspection and list question
On Wed, Dec 13, 2006 at 10:55:28AM +0200, Gaal Yahas wrote: : L stipulates the : results of a gather are flattened to a lazy list. I'm not sure how far : that flattenning goes, but one of these should do the trick, I think It would only flatten a recursive structure with the help of something that recurses. The flattening of gather/take itself is only one level, insofar as the various takes are treated as "pushes" onto the list being gathered. : (Pugs does not yet implement gather/take): Actually, it does, but only the block form. The generalization to any statement (using C syntax) was a very recent change. The following prints (1, 2, 3, 4, 5) in current pugs: #!/usr/bin/pugs my $a = [1,2,[3,4],5]; multi flattener ($x) { take $x; } multi flattener (Array @array) { for @array -> $elem { flattener($elem); } } sub flatten ([EMAIL PROTECTED]) { for @args -> $arg { return gather { flattener($arg) } } } $a.flatten.perl.say; Larry
Re: Introspection and list question
On Tue, Dec 12, 2006 at 02:19:46PM -0800, Ovid wrote: > First, how do I do introspection in Pugs? CPAN's Perl6::Bible hasn't > been updated in a while, but the various ways to get a list of methods > (from > http://search.cpan.org/dist/Perl6-Bible/lib/Perl6/Bible/S12.pod#Introspection > or http://tinyurl.com/yxukar) don't appear to work. They all throw > syntax errors or "No compatible subroutine" errors. In general you're better off looking at http://spec.pugscode.org/ for more updated synopses, but in regard to introspection, the APIs aren't well specced yet. > Also, I'm having trouble with problem 7 in > http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html > or http://tinyurl.com/tt9e7. Basically, it's flattening nested lists > and I'm embarrassed to admit that I can't figure this out in Perl6. > Thoughts? I've been reading synopses and grepping through Pugs, but to > no avail. L stipulates the results of a gather are flattened to a lazy list. I'm not sure how far that flattenning goes, but one of these should do the trick, I think (Pugs does not yet implement gather/take): sub flatten1 (@list) { gather for @list { take $_; } } sub flatten2 (@list) { gather for @list { take $_.does("List") ?? flatten2 $_ !! $_; } } -- Gaal Yahas <[EMAIL PROTECTED]> http://gaal.livejournal.com/
Re: Introspection and list question
On 12/12/06, Ovid <[EMAIL PROTECTED]> wrote: Hi all, A couple of quick things. First, how do I do introspection in Pugs? CPAN's Perl6::Bible hasn't been updated in a while, but the various ways to get a list of methods (from http://search.cpan.org/dist/Perl6-Bible/lib/Perl6/Bible/S12.pod#Introspection or http://tinyurl.com/yxukar) don't appear to work. They all throw syntax errors or "No compatible subroutine" errors. it seems much of this is unimplemented. from the pugs test dir, C returns some tests, but most of them are decorated with C<< :todo >>. Also, I'm having trouble with problem 7 in http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html or http://tinyurl.com/tt9e7. Basically, it's flattening nested lists and I'm embarrassed to admit that I can't figure this out in Perl6. Thoughts? I've been reading synopses and grepping through Pugs, but to no avail. * in index position flattens an array. it's mentioned in S02 (http://dev.perl.org/perl6/doc/design/syn/S02.html), among other places. a quick test at http://run.pugscode.org/ suggests that it works, too: pugs> my @a=[1,2,[3,4],5]; say @a[*]; 1 2 3 4 5 ~jerry
Introspection and list question
Hi all, A couple of quick things. First, how do I do introspection in Pugs? CPAN's Perl6::Bible hasn't been updated in a while, but the various ways to get a list of methods (from http://search.cpan.org/dist/Perl6-Bible/lib/Perl6/Bible/S12.pod#Introspection or http://tinyurl.com/yxukar) don't appear to work. They all throw syntax errors or "No compatible subroutine" errors. Also, I'm having trouble with problem 7 in http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html or http://tinyurl.com/tt9e7. Basically, it's flattening nested lists and I'm embarrassed to admit that I can't figure this out in Perl6. Thoughts? I've been reading synopses and grepping through Pugs, but to no avail. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
RE: class introspection and extention
> From: max demmelbauer [mailto:[EMAIL PROTECTED] [...] > i am new to this list. > i wrote a small web-framework called webtek ( http://max.xaok.org/ > webtek ) in perl 5.8 and try now to port this to perl6 (inspired by Unfortunately I only know very few German words, but webtek looks very interesting. Is (http://max.xaok.org/webtek/wiki) part of webtek? > the speak from juerd at the austrian perl workshop :). but i have Juerd++ > i read the lists and docs and i found some solutions, but none of > this worked for me in pugs... hmm.. If you don't get all your questions answered here after a day or two, then you should ask on the #perl6 IRC channel. (Juerd also uses it.) I put some information about #perl6 in the "Perl 6 Users FAQ": (http://perl.net.au/wiki/Perl_6_Users_FAQ). The developers on #perl6 can also tell you for sure what is implemented and what is working. I'm sure they would be very happy to help you. (By the way, the newest Pugs release is almost ready.) Best regards, Conrad Schneiker http://perl.net.au/wiki/Perl_6_Users_FAQ (Moved from AthenaLab to Perl 6 Wiki.) www.AthenaLab.com (Nano-electron-beam and micro-neutron-beam technology.)
Re: class introspection and extention
max demmelbauer schrieb: > * how can i serialize objects (like the use Storable qw(freeze thaw) in > perl5.8) Try $object.perl(.say) as stated in http://svn.openfoundry.org/pugs/docs/articles/tpr.pod (or http://gedankenkonstrukt.de/perl6doc/articles/tpr.html ;) ) -Thomas
class introspection and extention
hello.. i am new to this list. i wrote a small web-framework called webtek ( http://max.xaok.org/ webtek ) in perl 5.8 and try now to port this to perl6 (inspired by the speak from juerd at the austrian perl workshop :). but i have some problems: * how can i serialize objects (like the use Storable qw(freeze thaw) in perl5.8) -> i think this work is not done yet, so how can i inspect classes, something like: for Class.methods -> $method { ... } to build my own Storable logic. * how can i extend an class (like *{"Class::method"} = sub { ... } in perl5.8) i read the lists and docs and i found some solutions, but none of this worked for me in pugs... hmm.. thank's for your help. max.