Re: multi return values

2008-11-21 Thread Ryan Richter
On Fri, Nov 21, 2008 at 08:16:21PM +0100, Moritz Lenz wrote:
> Andy Colson wrote:
> (The thing that's still wrong with your code is that you need a
> whitespace after the 'my', otherwise my(...) should be parsed as a
> function call).

Also this, I think:

> > return($a, $b);

-ryan


Re: [perl #57770] Empty regexp gives unhelpful error message in rakudo

2008-08-10 Thread Ryan Richter
On Sun, Aug 10, 2008 at 10:51:39AM -0500, Patrick R. Michaud wrote:
> On Sun, Aug 10, 2008 at 06:40:12AM -0700, Carl Mäsak wrote:
> > r30155:
> > $ ./perl6 -e '//'
> > Syntax error at line 1, near "//"
> > 
> > Could be something nicer, in line with "The empty pattern is now
> > illegal." from S05.
> 
> It would be worthwhile to do whatever STD.pm would generate on
> this input.  I don't have STD.pm running on any of my machines
> at the moment to be able to check.  But whatever STD.pm generates
> for this case, we should match if we can.

Can't understand next input--giving up at /tmp/x line 1:
--> //
expecting ws (alt 03)

(the first / is highlighted in green and the second in red)

-ryan


Re: Rakudo test miscellanea

2008-06-26 Thread Ryan Richter
On Thu, Jun 26, 2008 at 09:55:09AM -0700, Larry Wall wrote:
> We could go as far as to guarantee that Nums do rational arithmetic
> out to a certain point, but probably what the financial insitutions
> want is special fixed-point types that assume a divisor anyway.
> Would any financial institution care to comment?

IANAFI, but I think that's more or less right.  I think they actually
tend to use BCD.

http://www2.hursley.ibm.com/decimal/decifaq1.html#inexact

-ryan


Re: Rakudo test miscellanea

2008-06-26 Thread Ryan Richter
On Thu, Jun 26, 2008 at 04:50:21PM +0200, Moritz Lenz wrote:
> What's the alternative?
> I don't think it's a good idea to special-case numeric types, and I
> don't think it's a good idea to define multis for each numeric type either.
> 
> I assume that 'Num' is meant to be a non-complex.
> Then it seems to make sense to assume:
> Int is Rat
> Rat is Num
> Num is Complex
> or am I off again?

Yeah, that looks sane.  I should probably put Int under Rat in p6types,
and maybe Num under Complex.

I believe an implementation can choose to do the inheritance either way:

Rat is Num
Rat is Any does Num

Since both of those end up looking the same to the user, more or less.
I tended to use the first form in p6types.

> Anyway, for our work in the test suite it would be nice to have it
> specced somewhere. Or should I rely on Ryan's docs/p6types? If so, it
> would be nice to convert it to format that can smartlinked to.

Since it's unofficial and (in theory) just repeats what's in the
synopses I don't think tests should refer to it.  Or someone could make
an S30 (Standard perl library) out of it.

-ryan


Re: Rakudo test miscellanea

2008-06-26 Thread Ryan Richter
On Thu, Jun 26, 2008 at 11:36:05AM +0200, Moritz Lenz wrote:
> There seems to be a thorough confusion about numeric types. for example
> some tests read like this: is (1.1).WHAT, 'Num'; and then in a different
> file is (1.1).WHAT, 'Rat'; That raises two questions for me
> 1) should we test for the value of .WHAT at all (unless for testing WHAT
> of course)? It seems to me that a compiler should have the freedom to
> return a different subtype (for example 1 could be a PositiveInt as long
> as PositiveInt is an Int; that's a contrived example, but you get the
> picture)

Right, it's hard to imagine that ever being a correct test.  It should
probably be using ~~ Num etc.

> 2) How do we know which numeric type is a class and which is a role? Is
>  there an explicit spec about the types of number literals? That could
> have some impact on type checking in the tests. (Maybe I should prod p6l
> with that).

You can't instantiate a role so they're pretty much all classes I think.
The only role that I saw specced was Order, and Num does Order so all
Num types inherit that.  Complex is its own type separate from Num, and
everything else descends from Num.  See docs/p6types in pugs, it's meant
to answer these questions :)

-ryan


Re: [svn:perl6-synopsis] r14549 - doc/trunk/design/syn

2008-06-11 Thread Ryan Richter
On Wed, Jun 11, 2008 at 04:49:18PM -0700, [EMAIL PROTECTED] wrote:
> -$min ..^ $max$ min .. $max-1
> -$min .. ^$max# $min .. (0..$max-1)
> +0 ..^ 10 # 0 .. 9
> +0 .. ^10 # 0 .. (0..9)

Ah, I should have been more specific - I meant that, since ~~ treats
Ranges as continuous intervals, 0 ..^ 10 isn't the same as 0 .. 9.
Although I guess there's no way to unabbreviate 0 ..^ 10...

-ryan


Re: [svn:perl6-synopsis] r14547 - doc/trunk/design/syn

2008-06-11 Thread Ryan Richter
On Wed, Jun 11, 2008 at 02:09:41PM -0700, [EMAIL PROTECTED] wrote:
> +Note that these differ:
> +
> +$min ..^ $max$ min .. $max-1
> +$min .. ^$max# $min .. (0..$max-1)

The punctuation looks a little funny on the first line.  Also, are
$min ..^ $max and $min .. $max-1 really the same range?

I'm a little curious about the second line, is that even legal?  It
seems to me a Range should only allow itself to be constructed from
endpoints with a well-defined ordering, so a Range of Ranges should be
illegal.  Or does the .. end up pulling a num out of the ^$max range
iterator for its endpoint somehow via MMD?

-ryan


Re: building pugs under Fedora 9 doesn't work

2008-06-03 Thread Ryan Richter
On Tue, Jun 03, 2008 at 12:03:00PM +0200, Moritz Lenz wrote:
> My last successful build was r18093 with GHC 6.6.1.
> Maybe we should just die in Makefile.PL until somebody finds a fix.

Maybe we should just revert the pugs source to that rev.  Haven't the
modifications since then basically just broken the build for most
people?

-ryan


Re: The Inf type

2008-06-02 Thread Ryan Richter
On Mon, Jun 02, 2008 at 11:50:20AM -0700, Jon Lang wrote:
> TSa wrote:
> > John M. Dlugosz wrote:
> >> The sqrt(2) should be a Num of 1.414213562373 with the precision of the
> >> native floating-point that runs at full speed on the platform.
> >
> > That makes the Num type an Int with non-uniform spacing. E.g. there
> > are Nums where $x++ == $x. And the -Inf and +Inf were better called
> > Min and Max respectively. IOW, the whole type based aproach to Inf
> > is reduced to mere notational convenience.
> 
> Please give an example value for a Num where $x++ == $x.  Other than
> Inf, of course.

All floats run out of integer precision somewhere, e.g. in p5

$ perl -le '$x=1; while($x+1 != $x) { $x *= 2; } print $x'
1.84467440737096e+19

Arbitrary precision mantissas aren't practically useful, since they have
a strong tendency to consume all memory in a few iterations.

-ryan


Re: slurpy scalar parameter?

2008-04-11 Thread Ryan Richter
On Sat, Apr 12, 2008 at 05:06:53AM -, John M. Dlugosz wrote:
> What is the difference between:
> 
>  sub head(*$head, [EMAIL PROTECTED])
> 
> and
> 
>  sub head($head?, [EMAIL PROTECTED])
> 

If you call head(@foo), in the first $head gets @foo[0] and in the
second it gets nothing (you didn't pass a scalar).

-ryan


Re: Nomenclature Question - BEGIN etc.

2008-04-10 Thread Ryan Richter
On Thu, Apr 10, 2008 at 04:38:27PM -0400, Brandon S. Allbery KF8NH wrote:
> 
> On Apr 10, 2008, at 13:29 , John M. Dlugosz wrote:
> >I might have misremembered, but i thought labels were followed by a
> >colon in Perl 6.  A quick scan of the docs... "
> >
> >It is illegal for a provisional subroutine call to be followed by a
> >colon postfix, since such a colon is allowed only on an indirect  
> >object,
> >or a method call in dot form.  (It is also allowed on a label when a
> >statement is expected.) ...
> 
> The last sentence there implies that a label can exist *without* a  
> colon.

I think the intent there is to say that a label is only allowed at the
start of a statement, not that a label can have a : left off.

-ryan


Re: understanding STD.pm

2008-04-05 Thread Ryan Richter
On Sat, Apr 05, 2008 at 09:16:13AM -0400, Ryan Richter wrote:
> On Sat, Apr 05, 2008 at 08:22:42AM -, John M. Dlugosz wrote:
> > 
> > OK, you got me.  What is the "?" used for?  For example,  > === $!ws_to }>.
> > 
> > I only see that character as used in this manner (a variable name?),
> > never defined (e.g. as a variable or parameter) anywhere.
> 
> Something is choking on utf8, it should be a cent sign (242 is octal
> latin1 for '?').  $? is the current match continuation.  I don't think
> it's specced, it's just an internal Cursor.pm thing that leaked out into
> STD in a few places (I could be wrong about that, though).

Heh, my reply only makes sense if your mail is first misrendered as
invalid utf8 instead of latin1 which you sent it in...  And my reply is
even more screwed up wrt encoding, sorry for the confusion...

-ryan


Re: understanding STD.pm

2008-04-05 Thread Ryan Richter
On Sat, Apr 05, 2008 at 08:22:42AM -, John M. Dlugosz wrote:
> 
> OK, you got me.  What is the "�" used for?  For example,  === $!ws_to }>.
> 
> I only see that character as used in this manner (a variable name?),
> never defined (e.g. as a variable or parameter) anywhere.

Something is choking on utf8, it should be a cent sign (242 is octal
latin1 for '�').  $� is the current match continuation.  I don't think
it's specced, it's just an internal Cursor.pm thing that leaked out into
STD in a few places (I could be wrong about that, though).

-ryan


Re: Conceptual questions about Objects

2008-04-04 Thread Ryan Richter
On Fri, Apr 04, 2008 at 06:31:56PM -0500, John M. Dlugosz wrote:
> chromatic chromatic-at-wgz.org |Perl 6| wrote:
> >It shouldn't be.
> >  
> So you are saying that in the example of
> 
>class C {
>   has $.a;
>   method a ($self:)

You've declared method a twice here.  has $.a is equivalent to

has $!a;
method a { $!a }

The variable is always really the $! form.

-ryan


Re: Getting Started - Synopsis

2008-03-31 Thread Ryan Richter
On Mon, Mar 31, 2008 at 09:54:58AM +0800, Agent Zhang wrote:
> On Sun, Mar 30, 2008 at 9:23 PM, Ryan Richter
> <[EMAIL PROTECTED]> wrote:
> >
> >  Actually, that cron job hasn't been working for a long time...
> >
> 
> I've just checked the cronjob mails and it seems to me that the
> update-syn script is working fine. So the Synopses are still fresh :)

Sorry, it's actually the html stuff from pugs that's not making it onto
feather, e.g. syn_index.html.

> I think you meant the auto-smoke script, which indeed has been failing
> due to a build error while linking pugs (after make veryclean):

Are you building it with GHC 6.6.1?  I think that version doesn't work
anymore.  Maybe someone who's succeeded in building pugs lately can
elaborate...

-ryan


Re: Getting Started - Synopsis

2008-03-30 Thread Ryan Richter
On Sun, Mar 30, 2008 at 07:28:46PM +0800, Agent Zhang wrote:
> The latest HTML version of all the Synopses can be found at
> http://perlcabal.org/syn/ , which is automatically updated from both
> SVN repositories every one hour by a cron job running on feather.

Actually, that cron job hasn't been working for a long time...

-ryan


Re: pluralization idea that keeps bugging me

2008-02-10 Thread Ryan Richter
On Sun, Feb 10, 2008 at 12:56:14PM +0300, Richard Hainsworth wrote:
> How - in sketch form - would I go about creating a module to do what I 
> suggest? I am not suggesting someone writes a module I have suggested, 
> but the barebones steps to creating a new metacharacter.
> 
> I have written infix multidispatch functions in pugs with Unicode 
> characters to investigate that part of the language. But I dont quite 
> see how to go about creating a new interpolatable metacharacter.

The category is called qq_backslash, so you'd define a new
qq_backslash:s or whatever.  I don't think pugs allows new ones to be
defined, though.

-ryan


Re: [svn:perl6-synopsis] r14485 - doc/trunk/design/syn

2008-01-17 Thread Ryan Richter
On Thu, Jan 17, 2008 at 10:57:11AM +0100, Moritz Lenz wrote:
> what happens if some of the characters aren't cased at all, like white
> spaces?
> 
> my $str = "AB DE";
> $str ~~ s:ii/.*/abcde/;
> 
> is the result ABcDE ? or is the space ignored and the substition is
> performed as if $str was "ABDE" in the first place?

I think chars in the target string should be left alone when the
corresponding pattern char is uncased, so I vote for "ABcDE".

> my $str = "määh";
> $str =~ s:bb/.*/mo i/;
> 
> is $str now 'mö i' ? Or does the space get a \N{COMBINING DIAERESIS}? Or
> is it tranlated to \N{DIAERESIS}? What about other non-letter characters?

This case is actually pretty clear, combining codes will combine with
space (0020), in fact that's the canonical way to display them on their
own.  And in graph mode, Perl 6 will consider a space with COMBINING
DIAERESIS and a plain DIAERESIS to be the same character, because their
representations in NFD are the same.

A hard case would be \n instead of space, because combining chars won't
combine with it - "\n\N{COMBINING DIAERESIS}" is two graphemes.  I'm not
sure what samebase should do in that case.

-ryan


Re: Factoring Arguments

2007-12-21 Thread Ryan Richter
On Fri, Dec 21, 2007 at 08:41:54AM -0800, Jonathan Lang wrote:
> and so on, you might do something like:
> 
>   with &qq :(c => false) {

I think this can be done with normal currying, something like

temp &circumfix:<" "> := "e:.assuming(:!c);

-ryan


Re: Pair notation for number radix

2007-12-04 Thread Ryan Richter
On Tue, Dec 04, 2007 at 07:39:16AM -0800, Larry Wall wrote:
> On Sun, Oct 07, 2007 at 03:01:06PM -0600, David Green wrote:
> > What happened to the suggestion of using ` to designate units?
> 
> It's kinda caught between two other notions.  On the one hand,
> we're trying to reserve ` for user definition, in part because it's
> so difficult to tell from ' in many fonts so we're avoiding it for
> standard usage.  On the other hand, it's not clear that units aren't
> generally just simple multiplication by a scaling factor: 1*in, where
> 1*in == 2.54*cm, for instance.  Units could also be viewed as type
> conversion, which would give us kg(1) and 1.kg as conversion forms
> in current Perl 6.  Since 1.kg is essentially using the units as a
> postfix, presumably the 1kg form could also work on literals, just as
> we currently allow 1i to convert 1 to i via the postfix: operator.
> (And I suppose there's a sense in which 10e-2 is specifying the
> scaling factor of the left side explicitly.)
> 
> In any case, though, if we treated them as type names rather than
> just methods, we'd probably want to require predeclaration of unit
> names since a type name like "kg" or "in" or "fortnight" could easily
> collide with a user-defined routine.  Or maybe they still want some
> special sigil-ish mark to stay in their own namespace.  Dunno.  I don't
> think we have to solve that for 6.0.0 in any case, especially if we
> require predeclaration of which unit names are wanted, in which case
> there might just be a units pragma that can pull in selections of
> the predefined units:
> 
> use units :cgs, :nasa, <μfortnight gibibyte>;
> my newton $thrust = 42.lbf;
> 
> But with a sigilish mark we could just pull in all the units from
> /usr/share/units.dat, I suppose.

I don't know if I ever mentioned it on the mailing list, but a while
back I did some work on a units module that uses units.dat
(examples/rules/unitsdat-grammar.pm in the pugs repo).  I think
that a simple postfix syntax (e.g.) doesn't give you the ability to
specify the kind of composite units that are common in scientific
applications where units are heavily used (e.g. Gauss per square root
Hertz).  Those kind of units also rule out simple type-based units, e.g.
having roles for length, mass, etc. - you can't do a role to the -7/3
power.  I settled on a syntax that allows a mini-language similar to
units(1):

9.8.:as
$field_noise.:as

But someone may be able to come up with something better.  My
implementation does unit type-checking at runtime, but compile-time
checking would be much nicer where possible.  It would also be cool to
be able to define roles that can represent themselves in several
different units:

role Photon does NumUnit { ??? }
my Photon $p .=new( energy => 42.:as );
say "energy is $p.:as zeptojoules";
say "wavelength is $p.:as Å";
say "frequency is $p.:as THz";

-ryan


Re: Is Perl 6 too late?

2007-05-14 Thread Ryan Richter
On Mon, May 14, 2007 at 20:41:35 +0300, Gabor Szabo wrote:
> On 5/14/07, John Macdonald <[EMAIL PROTECTED]> wrote:
> >  Removing the sigil
> > on a function call (it used to always be written &sub(args...))
> > did, I think, lead to the difficulty in perl5 where it became
> > difficult to add new keyword operators to the language - because
> > they could conflict with subroutine names in existing code.
> 
> Actually I think I never understood  this issue.
> We claim that having the sigils saves us from stepping on our future
> feet by making sure keywords of the language are always different
> from any variable we might create.
> 
> The fact that function don't need a sigil any more and it is even
> AFAIK discouraged to be used makes *this* argument mute.
> 
> Thought this thread might not be the best place to ask this
> I'd be glad to read some explanation about this.

In Perl 6, the & sigil is used to distinguish between

foo bar

which calls bar and passes the return value to foo, and

foo &bar

which passes bar as a Code object to foo.

-ryan

(sorry, I deleted your message by mistake, I'm attempting to fake up a reply)


Re: Some questions about miltislices and other things

2007-03-13 Thread Ryan Richter
On Mon, 12 Mar 2007 17:41:27 -0700, Larry Wall wrote:
> On Fri, Mar 02, 2007 at 01:33:50PM -0500, Ryan Richter wrote:
> : while ($_ = %state{@@w}.pick).say {
> 
> You maybe don't want each word on a separate line...

They did that in the original for some reason.  In the unlikely event
that I want to sit down and read the output I can use |fmt :)

> : - Does shift do what I'm expecting it to do with a multidim array?
> 
> I have my doubts.  Overloading that word to mean shifting the entire
> dimension seems like it could cause conceptual collisions down the
> road.  There a good chance it should just shift the value out of the
> first Capture without removing the Capture from the list of Captures.
> 
> And a shaped array might be different yet, shifting off the entire slice
> corresponding to first element of the first dimension.
> 
> But in either case I wouldn't expect it to remove a dimension.  Now,
> it's possible that @@w.shift would remove the dimension, since it
> treats the slice Capture as an individual element.

OK, that sounds good.

> Rather than trying to maintain @w as a multidimensional array where
> each slice ever only has one value, why not just use ordinary shift
> and push on an ordinary array, and then %state{[;[EMAIL PROTECTED] instead?  
> Should
> still have the theoretical advantage of storing the keys in a tree over
> duplicating all the prefix keys.  (For that reason I wouldn't go as far
> as to recommend a hash keyed on tuples, which presumably would duplicate
> prefixes.)

Yeah, I wrote it that way to begin with.  The version I posted was sort
of designed to maximize the number of language questions.

> : - Am I using the @ and @@ sigils correctly?  I think I could just use @@
> :   everywhere (right?), but I tried to use it only where needed.  Do I
> :   need an @@ on the method invocant or anywhere else?
> 
> Should only need it where you want to distinguish chunky from smooth,
> at least according to the current definition.  But I'm not entirely
> sure we aren't confusing things here.

What do you mean by that?

> : - As I understand it, the way I have it written the anonymous mixin is
> :   applied to the value in @w and not to the @w container.  If I did
> :   something like @w = 1,2,3 that would clobber the mixin, right?  Does
> :   the hyperop-assignment avoid that?
> 
> I don't think you want the mixin on the value, since @w.adv will be called
> on the container, not on the value.  An array container is not required
> to be able to treat its value as a single object.
> 
> In any case, by precedence you're applying the mixin to result of
> the xx, not the result of the [;], which makes @w.adv even less
> likely to work.

Yeah, that was a really weird idea...  I have a lot of those in case you
can't tell :)

Should we just assume that any of those things replaces the immutable
list and therefore clobbers any mixins?  I.e. a mixin on a value is part
of the immutableness?

> : - Can for <>.slurp.split {...} be trusted to not use a huge amount of
> :   memory for large inputs?
> 
> No, any .slurp is pretty much guaranteed to use memory.  Also, split no

Right, I expected an eager slurp but a lazy split (comb).  I envisioned
an eager split/comb consuming much more memory than an eager slurp, but
I guess that doesn't make much sense.

> longer has a default.  You probably want
> 
> for $*ARGS.comb {...}

Perfect, thanks.

-ryan


Some questions about miltislices and other things

2007-03-02 Thread Ryan Richter
As a little Perl 6 exercise I translated the Perl 5 Markov chain /
dissociated-press script from _The Practice of Programming_:

http://cm.bell-labs.com/cm/cs/tpop/markov.pl

Here's my Perl 6 attempt, with support for different prefix lengths.

my $n = 2;  # prefix length
my $max = 1;# max output words
my %state;
my $o = 0;
my @w = [;] "\n" xx $n  # initial sate
does { method adv(@w: $i){ @w <== $i; @w.shift; } };

for <>.slurp.split {# read each word of input
%state{@@w}.push: $_;
@w.adv: $_; # advance chain
}
%state{@@w}.push: "\n"; # add tail

@w »=» "\n";# reset initial state
while ($_ = %state{@@w}.pick).say {
last if /\n/ or $o++ >= $max;
@w.adv: $_; # advance chain
}

Since pugs doesn't seem to have full multislice support yet, can anyone
comment on whether I have the syntax and semantics right here?

In particular:

- Does shift do what I'm expecting it to do with a multidim array?

- Am I using the @ and @@ sigils correctly?  I think I could just use @@
  everywhere (right?), but I tried to use it only where needed.  Do I
  need an @@ on the method invocant or anywhere else?

- Does @w »=» "\n" leave the multidimensionality intact?

- As I understand it, the way I have it written the anonymous mixin is
  applied to the value in @w and not to the @w container.  If I did
  something like @w = 1,2,3 that would clobber the mixin, right?  Does
  the hyperop-assignment avoid that?

- Is there some concise syntax for attaching the mixin to the container,
  like 

  my @w is (Array does {...}) = ...;

  Is this the correct non-golf way to do it?

  Role R {...}
  class A is Array { does R }
  my @w is A = ...;

- Can I call methods on <> or do I have to say $*ARGS?

- Can for <>.slurp.split {...} be trusted to not use a huge amount of
  memory for large inputs?

Any commentary or suggestions for improvement are welcomed.

-ryan (rhr on #perl6)