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

Re: Not a bug?

2009-01-12 Thread Jon Lang
On Mon, Jan 12, 2009 at 2:15 AM, Carl Mäsak cma...@gmail.com 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 publiustemp-perl6interna...@yahoo.com 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

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(:leading0); $string.trim(:trailing0); Setting leading or trailing to false (they default to true)

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(:leading0); $string.trim(:trailing0); Setting leading or

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); 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 variables to do

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 16:05]: Or all could be allowed and $string.trim(:leading0) could all $string.rtrim internally. ++ Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/

Re: [PATCH] Add .trim method

2009-01-12 Thread Jonathan Worthington
Aristotle Pagaltzis wrote: * Ovid publiustemp-perl6langua...@yahoo.com [2009-01-12 16:05]: Or all could be allowed and $string.trim(:leading0) 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 ~ ' foo $ perl6 -e 'my $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

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 say I

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 and TrimEnd (and

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(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). If you need to dynamically determine what you're

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_end if we

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message From: Geoffrey Broadwell ge...@broadwell.org 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

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

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

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid publiustemp-perl6langua...@yahoo.com [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

Re: [PATCH] Add .trim method

2009-01-12 Thread Mark J. Reed
On Mon, Jan 12, 2009 at 2:50 PM, Aristotle Pagaltzis pagalt...@gmx.de 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

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 pagalt...@gmx.de [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

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid publiustemp-perl6langua...@yahoo.com [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

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

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

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message From: Aristotle Pagaltzis pagalt...@gmx.de 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,

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Larry Wall la...@wall.org [2009-01-12 21:55]: * Aristotle Pagaltzis pagalt...@gmx.de [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

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 cma...@gmail.com wrote: : Ovid (): : $ perl6 -e 'my $foo = foo;say { ~ $foo ~ }' :~ foo ~ : : Easy solution: only use double quotes when you want to interpolate. :) : : This is not

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Ovid publiustemp-perl6langua...@yahoo.com [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

Re: Not a bug?

2009-01-12 Thread Jon Lang
On Mon, Jan 12, 2009 at 1:08 PM, Larry Wall la...@wall.org 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 cma...@gmail.com wrote: : Ovid (): : $ perl6 -e 'my $foo = foo;say { ~ $foo ~ }' :~ foo ~ : : Easy solution:

Re: [PATCH] Add .trim method

2009-01-12 Thread Aristotle Pagaltzis
* Austin Hastings austin_hasti...@yahoo.com [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

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message From: Aristotle Pagaltzis pagalt...@gmx.de * 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,

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message From: jesse je...@fsck.com On Mon, Jan 12, 2009 at 07:01:25AM -0800, Ovid wrote: I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). 'left'

Re: [PATCH] Add .trim method

2009-01-12 Thread Gianni Ceccarelli
On 2009-01-12 Ovid publiustemp-perl6interna...@yahoo.com 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,

Re: [PATCH] Add .trim method

2009-01-12 Thread Jonathan Scott Duff
On Mon, Jan 12, 2009 at 9:01 AM, Ovid publiustemp-perl6langua...@yahoo.comwrote: - Original Message I could optionally make the following work: $string.trim(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). If you need to

Re: [PATCH] Add .trim method

2009-01-12 Thread Ovid
- Original Message From: Larry Wall la...@wall.org 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

Re: [PATCH] Add .trim method

2009-01-12 Thread Dave Whipp
Ovid wrote: $string.trim(:leading0); $string.trim(:trailing0); 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 determine

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 any

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(:leading0); $string.trim(:trailing0); Alternatively, those could be ltrim() and rtrim(). 'left' and 'right' are probably not the right names for functions which

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 mor...@faui2k3.org 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

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 framework calls 'em TrimStart

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 la...@wall.org : 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

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. : Suggestions welcome as I

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' imports its

Re: Extending classes in a lexical scope?

2009-01-12 Thread Ovid
- Original Message From: Jon Lang datawea...@gmail.com 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

Re: [PATCH] Add .trim method

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 9:07 AM, jesse je...@fsck.com 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

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 jswit...@gmail.com 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

Re: Not a bug?

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 3:54 PM, Larry Wall la...@wall.org 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: :

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 datawea...@gmail.com 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,

Re: [PATCH] Add .trim method

2009-01-12 Thread jason switzer
On Mon, Jan 12, 2009 at 6:26 PM, Ovid publiustemp-perl6langua...@yahoo.comwrote: - Original Message From: jason switzer jswit...@gmail.com If we wanted language dependent version, use :leading, :trailing, and :both. That will require each implementation properly handle the

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