Extending classes in a lexical scope?

2009-01-12 Thread Ovid
Let's say two people want to add a 'shuffle' method to all arrays. Alice wants to have it look like this: method shuffle (*...@array is rw) { @array .= pick(*); } Bob wants it to look like this: method shuffle (*...@array is rw) { @array = @array[0 .. @array/2] Z @arr...@array

Re: Not a bug?

2009-01-12 Thread Carl Mäsak
Ovid (>): > $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' > ~ foo ~ Easy solution: only use double quotes when you want to interpolate. :) This is not really an option when running 'perl6 -e' under bash, though. // Carl

Read access to class-scope variables from the class scope

2009-01-12 Thread Carl Mäsak
Writing something like this in Rakudo yesterday, I was slightly surprised to find it not working: class SomeClass { my $.warn_limit = 1000; my $.stern_warn_limit = $.warn_limit * 1.05; my $.expel_limit = $.warn_limit * 1.10; # ... } The specific error from Rakudo is "Lexical '

Re: Extending classes in a lexical scope?

2009-01-12 Thread Jon Lang
Ovid wrote: > Is it possible to modify the core Perl6Array class like that (without extra > keywords)? If so, is it possible for each programmer to make such a change > so that it's lexically scoped? AFAIK, it is not possible to modify a core class; however, I believe that it _is_ possible to d

Re: Not a bug?

2009-01-12 Thread Jon Lang
On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: > Ovid (>): >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' >> ~ foo ~ > > Easy solution: only use double quotes when you want to interpolate. :) > > This is not really an option when running 'perl6 -e' under bash, though. $ perl6 -e 'my

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: Ovid > > This patch implements the .trim() method for strings. > > Now that I'm reading S29, I see there is no .trim() method there. I got that > because it was referenced in pugs in the cookbook (not in tests, though) and > I > was trying to get the exam

Re: [PATCH] Add .trim method

2009-01-12 Thread Carl Mäsak
Ovid (>): > =item trim > > our Str multi Str::trim ( Str $string ) > > Removes leading and trailing whitespace from a string. > > =cut > > I could optionally make the following work: > > $string.trim(:leading<0>); > $string.trim(:trailing<0>); > > Setting leading or trailing to false (the

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > > =item trim > > > > our Str multi Str::trim ( Str $string ) > > > > Removes leading and trailing whitespace from a string. > > > > =cut > > > > I could optionally make the following work: > > > > $string.trim(:leading<0>); > > $string.trim(:trailing<0>); >

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > > > I could optionally make the following work: > > > > > > $string.trim(:leading<0>); > > > $string.trim(:trailing<0>); Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're going to trim, you'd couldn't just set va

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid [2009-01-12 16:05]: > Or all could be allowed and $string.trim(:leading<0>) could all > $string.rtrim internally. ++ Regards, -- Aristotle Pagaltzis //

Re: [PATCH] Add .trim method

2009-01-12 Thread Jonathan Worthington
Aristotle Pagaltzis wrote: * Ovid [2009-01-12 16:05]: Or all could be allowed and $string.trim(:leading<0>) could all $string.rtrim internally. ++ Note you can write it :!leading too. :-) Jonathan

Re: Not a bug?

2009-01-12 Thread Tim Bunce
On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote: > I really don't think this is a bug, but it did confuse the heck out of me at > first. This *is* expected behavior due to how {} is interpolated in strings, > yes? > > $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"' > > $ perl6 -e

Re: Not a bug?

2009-01-12 Thread TSa
HaloO, Tim Bunce wrote: On Sun, Jan 11, 2009 at 04:41:12PM -0800, Ovid wrote: I really don't think this is a bug, but it did confuse the heck out of me at first. This *is* expected behavior due to how {} is interpolated in strings, yes? $ perl6 -e 'my $foo = "foo";say "<" ~ $foo ~ ">"'

Re: [PATCH] Add .trim method

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: : ...the trivial $string.trim and trim($string) case. Hmm, I'd think .trim should work like .chomp, and return the trimmed string without changing the original. You'd use $str.=trim to do it in place. Can't say I really like the negated optio

Re: [PATCH] Add .trim method

2009-01-12 Thread Jonathan Worthington
Ovid wrote: - Original Message In the pir, doesn't the "s = self" line copy self, thus ensuring that I'm changing "s" and not "self"? No, it's binding. Or do I need "s = clone self" (or however it's written). Yeah, but also note that substr would return a copy... Can't sa

Re: [PATCH] Add .trim method

2009-01-12 Thread Carl Mäsak
Jonathan (>), Ovid (>>), Larry (>>>): >>> Can't say I really like the negated options though. They smell funny. >> >> Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. >> Suggestions welcome as I can't think of anything better. > > The .Net framework calls 'em TrimStart an

Re: [PATCH] Add .trim method

2009-01-12 Thread Geoffrey Broadwell
On Mon, 2009-01-12 at 07:01 -0800, Ovid wrote: > - Original Message > > > > > > I could optionally make the following work: > > > > > > > > $string.trim(:leading<0>); > > > > $string.trim(:trailing<0>); > > Alternatively, those could be ltrim() and rtrim(). If you need to > dynamica

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > >> Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. > >> Suggestions welcome as I can't think of anything better. > > > > The .Net framework calls 'em TrimStart and TrimEnd (and has a Trim that does > > both). So maybe trim_start and trim_en

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: Geoffrey Broadwell > When I saw your proposed syntax above, instead of reading "don't trim > leading/trailing whitespace", I read "change the definition of > 'whitespace' to 'codepoint 0' for leading/trailing". > > That of course raises the question of how on

Re: [PATCH] Add .trim method

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 09:33:32AM -0800, Geoffrey Broadwell wrote: : That of course raises the question of how one *would* properly override : trim's concept of whitespace Well, given that .trim is essentially just .comb(/\S.*\S/), which in turn is really just m:g/(\S.*\S)/, I don't see much

Re: [PATCH] Add .trim method

2009-01-12 Thread Andy Colson
Larry Wall wrote: On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: : ...the trivial $string.trim and trim($string) case. Hmm, I'd think .trim should work like .chomp, and return the trimmed string without changing the original. You'd use $str.=trim to do it in place. Can't say I really li

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid [2009-01-12 18:40]: > 1. No params, trim all > 2. :start or :end, only trim that bit (not a negated option :) > 3. If both, goto 1 Also `:!start` to imply `:end` unless `:!end` (which in turn implies `:start` unless `:!end`)? I’d like not to have to type `.trim(:start)` when I could ju

Re: [PATCH] Add .trim method

2009-01-12 Thread Mark J. Reed
On Mon, Jan 12, 2009 at 2:50 PM, Aristotle Pagaltzis wrote: > I'd like not to have to type `.trim(:start)` when I could just do > `.ltrim` though. As long as we gloss .ltrim as "leading" trim rather than "left" trim. Then the other end could be .ttrim for "trailing"? We really ought to avoid usi

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > Also `:!start` to imply `:end` unless `:!end` (which in turn > implies `:start` unless `:!end`)? > > I’d like not to have to type `.trim(:start)` when I could just do > `.ltrim` though. So what would .ltrim do with this? " בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְע

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Aristotle Pagaltzis [2009-01-12 20:55]: > Also `:!start` to imply `:end` unless `:!end` (which in turn > implies `:start` unless `:!end`)? Ugh, forget this, I was having a blank moment. Actually that makes me wonder now whether it’s actually a good idea at all to make the function parametrisab

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid [2009-01-12 21:20]: > Since that's RTL (Right To Left) text, should ltrim remove the > leading or trailing whitespace? > > I like Jonathan's trim_start and trim_end. Let me ask you first: does a string that runs Right-to-Left start at the left and end at the right or start at the right and

Re: [PATCH] Add .trim method

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 09:18:03PM +0100, Aristotle Pagaltzis wrote: : Plus if there are separate `.ltrim` and `.rtrim` functions it : would be better to implement `.trim` by calling them rather than : vice versa, so it wouldn’t even be less efficient two make two : calls rather than a parametrised

Re: [PATCH] Add .trim method

2009-01-12 Thread Austin Hastings
Aristotle Pagaltzis wrote: Actually that makes me wonder now whether it’s actually a good idea at all to make the function parametrisable at all. Even `.ltrim.rtrim` is shorter and easier than `.trim(:start,:end)`! How about .trim(:l, :r) with both as the default? And if the rtl crowd makes

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: Aristotle Pagaltzis > > I like Jonathan's trim_start and trim_end. > > Let me ask you first: does a string that runs Right-to-Left start > at the left and end at the right or start at the right and end at > the left? > > Now to answer your question, *I* know

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Larry Wall [2009-01-12 21:55]: > * Aristotle Pagaltzis [2009-01-12 21:20]: > > Plus if there are separate `.ltrim` and `.rtrim` functions it > > would be better to implement `.trim` by calling them rather > > than vice versa, so it wouldn’t even be less efficient two > > make two calls rather t

Re: Not a bug?

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 03:43:47AM -0800, Jon Lang wrote: : On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: : > Ovid (>): : >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' : >> ~ foo ~ : > : > Easy solution: only use double quotes when you want to interpolate. :) : > : > This is not rea

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid [2009-01-12 22:05]: > I see your point And now I see yours. I was visualising the memory layout of a string, wherein a right-to-left string gets displayed from the right end of it’s in-memory representation so “left” and “right” are absolutes in that picture. But of course RTL reverses the

Re: Not a bug?

2009-01-12 Thread Jon Lang
On Mon, Jan 12, 2009 at 1:08 PM, Larry Wall wrote: > On Mon, Jan 12, 2009 at 03:43:47AM -0800, Jon Lang wrote: > : On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak wrote: > : > Ovid (>): > : >> $ perl6 -e 'my $foo = "foo";say "{" ~ $foo ~ "}"' > : >> ~ foo ~ > : > > : > Easy solution: only use doub

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Austin Hastings [2009-01-12 22:00]: > How about .trim(:l, :r) with both as the default? Liveable. > And if the rtl crowd makes a furor, we can add :a/:o or :ת/:א > or something. *grin* Maybe :h and :t (head/tail). > Useful for doing infrequent things. IMO, left and right > trimming are inf

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: Aristotle Pagaltzis > * Austin Hastings [2009-01-12 22:00]: > > How about .trim(:l, :r) with both as the default? > > Liveable. I've just committed the pugs tests for trim. However, it's just 'trim' with no left/right, leading/trailing, Catholic/Protestant

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: jesse > > On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote: > > > > > I could optionally make the following work: > > > > > > > > > > $string.trim(:leading<0>); > > > > > $string.trim(:trailing<0>); > > > > Alternatively, those could be ltrim() and rtri

Re: [PATCH] Add .trim method

2009-01-12 Thread Gianni Ceccarelli
On 2009-01-12 Ovid wrote: > Um, er. Damn. Now I'm wondering how my "leading" and "trailing" > trimming works with Hebrew. How are the strings implemented > internally? RTL (and bidi) languages are written in strings so that the character order is the logical, reading, order. That is, the chara

Re: [PATCH] Add .trim method

2009-01-12 Thread Jonathan Scott Duff
On Mon, Jan 12, 2009 at 9:01 AM, Ovid wrote: > - Original Message > > > > > > I could optionally make the following work: > > > > > > > > $string.trim(:leading<0>); > > > > $string.trim(:trailing<0>); > > Alternatively, those could be ltrim() and rtrim(). If you need to > dynamically d

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: Larry Wall > On Mon, Jan 12, 2009 at 05:04:50AM -0800, Ovid wrote: > : ...the trivial $string.trim and trim($string) case. > > Hmm, I'd think .trim should work like .chomp, and return the trimmed > string without changing the original. You'd use $str.=trim t

Re: [PATCH] Add .trim method

2009-01-12 Thread Dave Whipp
Ovid wrote: $string.trim(:leading<0>); $string.trim(:trailing<0>); Setting leading or trailing to false (they default to true) would result in either leading or trailing whitespace not being trimmed Alternatively, those could be ltrim() and rtrim(). If you need to dynamically de

Re: Not a bug?

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 01:19:12PM -0800, Jon Lang wrote: : As well, isn't there a way to escape a character that would otherwise : be interpolated? If the intent were as you suppose, the original : could be rewritten as: : : $ perl6 -e 'my $foo = "foo";say "\{" ~ $foo ~ "}"' Sure, though in a

Re: Extending classes in a lexical scope?

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 03:38:04AM -0800, Jon Lang wrote: : Ovid wrote: : > Is it possible to modify the core Perl6Array class like that (without extra keywords)? If so, is it possible for each programmer to make such a change so that it's lexically scoped? : : AFAIK, it is not possible to modi

Re: [PATCH] Add .trim method

2009-01-12 Thread jesse
On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote: > > > > I could optionally make the following work: > > > > > > > > $string.trim(:leading<0>); > > > > $string.trim(:trailing<0>); > > Alternatively, those could be ltrim() and rtrim(). 'left' and 'right' are probably not the right name

Re: Extending classes in a lexical scope?

2009-01-12 Thread Moritz Lenz
Larry Wall wrote: > : however, I believe > : that it _is_ possible to derive a new class whose "name" differs from > : an existing class only in terms of version information, such that it > : is substituted for the original class within the lexical scope where > : it was defined, barring explicit i

Re: [PATCH] Add .trim method

2009-01-12 Thread Andy Lester
On Jan 12, 2009, at 11:27 AM, Carl Mäsak wrote: How about .trim(:start) and .trim(:end)? And .trim(:both) for orthogonality. -- Andy Lester => a...@petdance.com => www.petdance.com => AIM:petdance

Re: Extending classes in a lexical scope?

2009-01-12 Thread Ovid
- Original Message > From: Moritz Lenz > > That is the preferred way to avoid action-at-a-distance in P6. > > so if I do that, will a 'my @a' use that new Array class? > > Actually I'd prefer it if there were some kind of mechanism to set a > default implementation type, so that I cou

Re: [PATCH] Add .trim method

2009-01-12 Thread Moritz Lenz
Carl Mäsak wrote: > Jonathan (>), Ovid (>>), Larry (>>>): Can't say I really like the negated options though. They smell funny. >>> >>> Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. >>> Suggestions welcome as I can't think of anything better. >> >> The .Net framew

Trimming arrays

2009-01-12 Thread Ovid
What should this output? my @array = ' foo ', ' bar '; @array .= trim; say @array.perl; And what if I have an array of hashes of hashes of arrays? Currently you can call 'trim' on arrays, but it's a no-op. Similar issues with chomp and friends. Cheers, Ovid -- Buy the book

Re: Trimming arrays

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 03:05:21PM -0800, Ovid wrote: : What should this output? : : my @array = ' foo ', ' bar '; : @array .= trim; : : say @array.perl; : : And what if I have an array of hashes of hashes of arrays? : : Currently you can call 'trim' on arrays, but it's a no-op.

Re: Trimming arrays

2009-01-12 Thread Ovid
- Original Message > From: Larry Wall > : my @array = ' foo ', ' bar '; > : @array .= trim; > : > : say @array.perl; > : > : And what if I have an array of hashes of hashes of arrays? > : > : Currently you can call 'trim' on arrays, but it's a no-op. Similar issues >

Re: [PATCH] Add .trim method

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 06:36:55PM +0100, Moritz Lenz wrote: : Carl Mäsak wrote: : > Jonathan (>), Ovid (>>), Larry (>>>): : Can't say I really like the negated options though. They smell funny. : >>> : >>> Agreed, but ltrim and rtrim will disappoint Israelis and dyslexics alike. : >>> Sugge

Re: Extending classes in a lexical scope?

2009-01-12 Thread Jon Lang
Ovid wrote: > Actually, I'd prefer to go much further than this: > > use Core 'MyCore'; > > And have that override core classes lexically. > > That solves the "but I want it MY way" issue that many Perl and Ruby > programmers have, but they don't shoot anyone else in the foot. Since 'use' import

Re: [PATCH] Add .trim method

2009-01-12 Thread Mark J. Reed
On Mon, Jan 12, 2009 at 4:19 PM, Aristotle Pagaltzis wrote: > Maybe :h and :t (head/tail). I like the echo of the csh pathname modifiers there. Unless that confuses people into thinking that .trim has something to do with pathname canonicalization... -- Mark J. Reed

Re: Extending classes in a lexical scope?

2009-01-12 Thread Ovid
- Original Message > From: Jon Lang > > Actually, I'd prefer to go much further than this: > > > > use Core 'MyCore'; > > > > And have that override core classes lexically. > > > > That solves the "but I want it MY way" issue that many Perl and Ruby > programmers have, but they don't

Re: [PATCH] Add .trim method

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 9:07 AM, jesse wrote: > > 'left' and 'right' are probably not the right names for functions which > trim leading and/or trailing space, since their meanings get somewhat > ambiguous if a language renders right-to-left instead of left-to-right > or vice-versa > I'm in favo

Trimming; left or start? (was: Re: [PATCH] Add .trim method)

2009-01-12 Thread Timothy S. Nelson
Can I make a suggestion? From my point of view, it'd be nice if the trim method supported: - left/right (leftmost/rightmost part of the string; language-independent) - start/end (start and end of string; could be leading/trailing instead) - both How would that work?

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message > From: jason switzer > If we wanted language dependent version, use :leading, :trailing, and :both. > That will require each implementation properly handle the language > variations. I think :start and :end are my favorites. Huffman++ (maybe :begin and :end for c

Re: Not a bug?

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 3:54 PM, Larry Wall wrote: > On Mon, Jan 12, 2009 at 01:19:12PM -0800, Jon Lang wrote: > : As well, isn't there a way to escape a character that would otherwise > : be interpolated? If the intent were as you suppose, the original > : could be rewritten as: > : > : $ per

Re: Extending classes in a lexical scope?

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 02:43:37PM -0800, Ovid wrote: : Actually, I'd prefer to go much further than this: : : use Core 'MyCore'; : : And have that override core classes lexically. We're already speccing a way to substitute a different prelude from the command line, in order to desugar -n and

Re: Extending classes in a lexical scope?

2009-01-12 Thread Jon Lang
Ovid wrote: > - Original Message > >> From: Jon Lang > >> > Actually, I'd prefer to go much further than this: >> > >> > use Core 'MyCore'; >> > >> > And have that override core classes lexically. >> > >> > That solves the "but I want it MY way" issue that many Perl and Ruby >> programme

Re: [PATCH] Add .trim method

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 6:26 PM, Ovid wrote: > - Original Message > > > From: jason switzer > > > If we wanted language dependent version, use :leading, :trailing, and > :both. > > That will require each implementation properly handle the language > > variations. > > I think :start and :

Re: Extending classes in a lexical scope?

2009-01-12 Thread Larry Wall
On Mon, Jan 12, 2009 at 04:38:07PM -0800, Jon Lang wrote: : No, you don't understand me. The Foo/Bar example I was giving was : independent of your example. Rephrasing in your terms, consider the : possibility of a class that's derived from Array, for whatever reason; : call it "Ring". Now you d