Re: <<>> question
On Thu, Oct 5, 2017 at 11:44 AM, Andy Bach wrote: > >> is ><<>> >> synonymous with >qw[] > ? `<<>>` is the same as `qqww<<>>` Which is short for `Q :qq :ww <<>>` the `:qq` is short for `:double`, that is it turns on double quote behaviour `:double` is short for `:scalar :array :hash :function :closure :backslash` the `:ww` is short for `:quotewords` which is similar to `:words` except it allows quoting to override where it splits the strings. `Q :quotewords < a 'b c' d >` turns into `( 'a', 'b c', 'd' )` Note that if you explicitly use `q` `qq` or `Q` that the brackets will not change how the construct works. (So even if you use `Q<<…>>` it will be the same as `Q'…'`)
RE: Perl 6 Object Construction - General Advice
Perl 6 (Timo), In terms of new() uses… I’ve seen a clever use of new() that goes beyond turning ‘positionals’ into ‘named’ in https://github.com/retupmoca/P6-Net-SMTP/blob/master/lib/Net/SMTP.pm6. It wraps methods for debugging. Pretty great, imo. In terms of this thread’s subject… I am coming from a SysAdmin orientation, where I implement large software suites with enough options to choke a pig. I’m writing auto-deployment scripts that manage the trickier aspects of installation & configuration. Also some Perl 6 apps supporting the products. My primary desire is to specify defaults with ‘has’, which I consider concise, convenient, easy to operate, and a great place to standardize specifying attribute defaults. Then, while still in OC, have an opportunity to calculate better attribute values before returning up the call stack to new() – all without having to manage traits & defaults manually. Many of my classes simply want to read a system command/file and provide an interface with accessors. new() and its accompanying stack needs to slurp in all of the source information, resulting in well-loaded attributes with accessors ready to answer questions. If I can get new() to load up all attributes, then there will be no need for a clunky new()->my-more-complete-init() in my classes. Hundreds of classes… Perl 6 provides a comprehensive simplest-case for Object Construction (OC) when only attributes are specified -- defaults & traits are automatically managed. #!/usr/bin/env perl6 class ITDT { has $.itdt-path = '/usr/local/ITDT/itdt'; # nice! has $.media-changer is required; # nice! has %!robot = ( :ONE(1), :TWO(2) ); # nice! method robot{ %!robot; } } my ITDT $tape_library_inventory .= new(:itdt-path, :media-changer); say 'itdt-path:= ' ~ $tape_library_inventory.itdt-path; say 'media-changer = ' ~ $tape_library_inventory.media-changer; print 'robot = '; dd $tape_library_inventory.robot; # output: itdt-path: = /opt/ITDT/itdt media-changer = /dev/smc0 robot = Hash %!robot = {:ONE(1), :TWO(2)} If you craft your own BUILD and/or TWEAK to perform more elaborate attribute initializations, then you must manage all of that yourself, losing the elegant ‘has’ conveniences shown above. I may have missed it. new(), BUILD(), TWEAK(), !initialize – none seem to retain the magic of automatically managed defaults & traits. Please enlighten me if it’s there and I’m not seeing it. Thanks, Mark From: Timo Paulssen [mailto:t...@wakelift.de] Sent: Sunday, October 1, 2017 16:56 To: perl6-users@perl.org Subject: Re: Perl 6 Object Construction - General Advice I wrote another more in-depth (but potentially less useful to you) mail about this further down the thread, but I thought it'd be good to point this out near the top: I think the self.bless(|%args)!initialize idiom is a work-around for submethod TWEAK not yet existing when this code was written. TWEAK works in a very similar manner, with these differences: 1) Your "self" isn't fully built when TWEAK runs, therefore you can't call regular methods on it 2) It will even be executed when a subclass of your class gets constructed, whereas there's no simple way to get access to !initialize from a subclass. 3) TWEAK gets passed the named parameters that bless was called with method new is useful only if you want to take positional parameters for the .new — the default new you get from Mu only accepts named arguments and passes them on as-is to self.bless. They then get passed to every BUILD and TWEAK in the inheritance chain. The named parameters don't have to correspond to attribute names, as you can do any private attribute assignment in TWEAK that you like. I hope that helps - Timo
RE: Perl 6 Object Construction - General Advice
Timo, Oops. You're right. (I was unconditionally sending an argument in my test that zeroed it out the attribute that I was watching -- doh!) Now I can confirm that TWEAK is the logical place to further initialize attributes. I now see the light! Thanks, Mark -Original Message- From: Timo Paulssen [mailto:t...@wakelift.de] Sent: Thursday, October 5, 2017 13:56 To: Mark Devine ; perl6-users@perl.org Subject: Re: Perl 6 Object Construction - General Advice The main difference between BUILD and TWEAK is that BUILD will replace all default and requiredness handling, while TWEAK keeps it intact. TWEAK gets run after these aspects had their turn, so if you have an "is required" attribute that doesn't get a value passed, the BUILDALL process will throw the corresponding exception before TWEAK even gets invoked. Don't forget that with the assignment syntax for attribute defaults you're allowed to do calculations, too! You can even refer to other attributes in there, as long as you use the $!foo syntax. hope that helps - Timo
Re: Perl 6 Object Construction - General Advice
The main difference between BUILD and TWEAK is that BUILD will replace all default and requiredness handling, while TWEAK keeps it intact. TWEAK gets run after these aspects had their turn, so if you have an "is required" attribute that doesn't get a value passed, the BUILDALL process will throw the corresponding exception before TWEAK even gets invoked. Don't forget that with the assignment syntax for attribute defaults you're allowed to do calculations, too! You can even refer to other attributes in there, as long as you use the $!foo syntax. hope that helps - Timo
Re: <<>> question
> is <<>> > synonymous with qw[] ? IIUC - close, it like qqw: https://docs.perl6.org/language/quoting#index-entry-quote_qqww-quote_ <<_>>-quote_«_»-Word_quoting_with_interpolation_and_quote_protection:_qqww It's actually synonymous w/ qqww but depending upon your use of quotes w/i the list elements, it works out the same as qqww ... except for that whole "allomorph" aspect > my $a = 42 42 > say qww{"$a b" c}.perl ("42 b", "c") > say qw{"$a b" c}.perl ("\"\$a", "b\"", "c") > say qqw{"$a b" c}.perl ("\"42", "b\"", "c") > say qqww{"$a b" c}.perl ("42 b", "c") > say <<"$a b" c>>.perl ("42 b", "c") > say <<$a b c>>.perl (IntStr.new(42, "42"), "b", "c") > say qw{$a b c}.perl ("\$a", "b", "c") > say qqw{$a b c}.perl ("42", "b", "c") > say qqww{$a b c}.perl ("42", "b", "c") > say qww{$a b c}.perl ("\$a", "b", "c") On Wed, Oct 4, 2017 at 10:22 PM, Todd Chester wrote: > On 10/04/2017 08:20 PM, Todd Chester wrote: > >> So in this context "{$x}" means insert (interpolate) a >> variable into the list? I was thinking it meant to >> insert a variable into a string. Did saying <<>> >> automatically tell Perl6 that this was a list >> and not a sting? >> > > > is ><<>> > synonymous with >qw[] > ? > -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk
Re: <<>> question
MIME Is The Sacha Guitry Picture. On Oct 4, 2017 8:23 PM, "Todd Chester" wrote: > On 10/04/2017 08:20 PM, Todd Chester wrote: > >> So in this context "{$x}" means insert (interpolate) a >> variable into the list? I was thinking it meant to >> insert a variable into a string. Did saying <<>> >> automatically tell Perl6 that this was a list >> and not a sting? >> > > > is ><<>> > synonymous with >qw[] > ? >