Fwd: eval

2006-05-24 Thread Michael Mathews

Oh "try"! I like that! But is CATCH implemented in pugs? Anyone care
to give a working example of try/CATCH?

--michael

On 25/05/06, Yuval Kogman <[EMAIL PROTECTED]> wrote:

To complement string eval with eval { } (now called try):

try {
die "foo";
} or say "error: $!"

On Thu, May 25, 2006 at 01:08:42 +0100, Michael Mathews wrote:
> This works...
>
>  #!/usr/bin/pugs
>  my $code = "sqawk(";
>  eval $code or say $!;
>  say "but still running.";
>
> it prints out...
>  unexpected end of input
>  expecting comment, ":", identifier, term or ")"
>  but still running.



> >On Wed, May 24, 2006 at 19:54:53 +0300, Gabor Szabo wrote:
> >> if eval "command" fails, where can I get the error message ?
> >>
> >> aka  $@ in P5 ?
> >
> >$!


Re: perl 6 hosting?

2006-05-24 Thread Gabor Szabo

On 5/25/06, David Cantrell <[EMAIL PROTECTED]> wrote:

I might be able to host a virtual machine with perl6 on it and give out
accounts.  I need to think about how to stop people being naughty
though.


Probably the easy part is to to remove the most dangerous calls such as
eval and system and then chroot the users.

The hard part is to make sure they won't write code to exploit other sites or
create hug load on your machine...
... but if someone does it in Perl6 that might be a good sign of the
maturity of Pugs.

Ah and you could also declare that all the code uploaded to that
server is automatically copyright Perl Foundation and can have a
public log of it.

Gabor


Re: eval

2006-05-24 Thread Larry Wall
On Wed, May 24, 2006 at 06:54:53PM +0300, Gabor Szabo wrote:
: if eval "command" fails, where can I get the error message ?
: 
: aka  $@ in P5 ?

All error variables have been unified into $!, so it should show up there.

Larry


Re: Simple Print/Say Question

2006-05-24 Thread Larry Wall
On Wed, May 24, 2006 at 11:43:59AM +0100, Daniel Hulme wrote:
: shouldn't the >>*<< be >>* as the right-hand operand is a scalar?), then

It used to be like that once upon a time, but we later changed it
so infix operators are always written with "hypers" on both sides,
and only the prefix and postfix operators are written lopsided.
After all, with

$foo »*« $bar

we can't actually tell which side might be an array till run time, so
the "hyper" mark indicates the intent to be smart with that argument
regardless.  And with infix you can't really be smart about one side
without also being smart about the other side.

Larry


Logic Programming for Perl6 (Was Re: 3 Good Reasons... (typo alert!))

2006-05-24 Thread David Romano

Hi Ovid,
On 5/24/06, Ovid <[EMAIL PROTECTED]> wrote:

As an aside for those who, like me, wanted to see support for logic 
programming:  the only significant disappoinment I have with Perl6 is also, 
oddly enough, accompanied by a sigh of relief.  Perl6 will easily support 
imperative, functional and OO syntax.  But what about logic programming?  Perl6 
rules might help, but there will be no support for things that Prolog and 
Mercury do naturally.

The "sigh of relief" stems from my realization that logic programming in Perl6 
would probably be implemented incorrectly because the easiest way to implement it is 
usually wrong, though this can be very tough to see at first.  It's my understanding that 
logic programming wasn't incorporated due to the desire to not delay the initial release 
of Perl6 (I could be wrong).  However, after having done a fair amount of work with logic 
programming, I realize that one of the greatest implementation mistakes with it is that 
results tend to be bags and not sets (SQL shares this problem).  Thus, when one naturally 
wants all of the answers to a query, one often gets duplicate results and this is almost 
always wrong. (See http://use.perl.org/~Ovid/journal/28378 for an SQL example of this 
problem).

I re-read your journal entry and comments (I had read it back when you
first had posted it), and I'm curious about what obstacles that you
think need to be overcome for Perl6 to support logic programming.

Just to let you know, I only used Prolog for a month during a course
called "Programming Languages: Principles and Paradigms", so I don't
have a strong background in it. From what I remember, everything is
about binding in Prolog: if the given data can bind to the predicate
(I think that's what it's called in Prolog) in some way, then the
predicate returns successfully. Why can't grammars (in the sense of
Perl6) be used for this kind of stuff (and here I'm asking about what
Mercury and Prolog can do naturally)? Is it that so much more needs to
be added to Perl6 grammars/rules for them to be as powerful and
versatile as predicates in logic programming, and that these additions
cannot be reconciled with the rest of the Perl6 language? I'm
interested in everyone's opinions.

David


Re: 3 Good Reasons...

2006-05-24 Thread A. Pagaltzis
* Michael Mathews <[EMAIL PROTECTED]> [2006-05-25 00:45]:
> Is there something in Perl 6 akin to a "use strict" switch that
> will apply the straightjacket some projects need, and thus
> force typing of all variables. (Then I could have a good
> comeback for those damned Java guys.)

It’s called Company Coding Style. Yes, the compiler doesn’t
enforce that, but you can check the source itself for type
declarations where Style says they should be; this is a different
situation from Perl 5, where you have to rely on much softer
metrics external to the source.

Regards,
-- 
Aristotle Pagaltzis // 


Re: 3 Good Reasons...

2006-05-24 Thread Michael Mathews

Thanks for that Ovid. I agree that any language must stand on it's
merits in the long-term, but there is an undeniable "hump" every new
language must get over to convince people it's worth trying in the
first place.


From your excellent summary I think speed, CLR and real OO should

definitely make the short list. I personally never had a problem with
Perl's speed. If I wanted speed I'd write it in C -- for what I do
Perl is already fast enough -- but manager-types have a natural
affinity to efficiency. Faster, better, easier? Yeah that's salable.
:-)

--michael

On 24/05/06, Ovid <[EMAIL PROTECTED]> wrote:

- Original Message 
From: Michael Mathews <[EMAIL PROTECTED]>

> So my question to the list is, in simple terms even an IT manager
> could grasp, explain what problems Perl 5 has that Perl 6 fixes, such
> that they would want to undergo the pain of ever switching.




Hi Michael,

Many companies eventually switch to new languages.  The switch is painful, but 
when they see their current technologies aren't working, they reach for 
something else.  The question is, why Perl6?

Perl6, for those who have been paying attention, is revolutionary.  Not only 
will the language run much faster, but programmers will be more productive, 
they'll be able to seamlessly interact with code written in other languages and 
they'll be able to easily do things that is hard to do in other languages.

That's the short answer, but it sounds like a marketroid.  Here's (some of) the 
beef, though I'd be happy for corrections on any misconceptions below.

Perl5 is a very powerful language, but it does have plenty of cruft and is 
showing its age.  Perl6 not only fixes a lot of that cruft but also adds new, 
powerful features which makes programmers more productive and thus can churn 
out apps quicker.  Further, because it will be running on top of Parrot, it 
will be far faster than Perl5.  So you gain both programmer and runtime 
performance.

The most serious problems I have with Perl5 tend to center around its flexible 
but limited OO model.  Right now there's not a clear distinction between class 
and instance data.  This means that it's very easy to create class data which 
makes subclassing difficult at times.  Further, Perl5's poor argument handling 
is a constant source of bugs:

  sub some_value {
  my ($self, $value) = @_;
  return $self->{value} unless $value; # whoops!  Is "0" OK?
  $self->{value} = $value;
  return $self;
  }

Also, Perl6 will offer much strong encapsulation than one can "naturally" do in 
Perl5 (without resorting to inside-out objects, but I tend to recommend that folks not 
use those).

Perl6 offers optional strong typing, meaning that you can declare the above 
argument to some_value to be an integer and have less worries that someone will 
pass a string.  The strong typing means you can also do this:

  my int @array;

That will allow optimizations that are currently not possible, but since it's 
optional, you can choose the flexibility of late binding or the comfort of 
early binding (a bit of hand waving there).

Multimethods are also very powerful, but difficult to do with Perl5 without 
extra (and slow) modules.  The can alleviate many bugs associated with methods 
(feel free to correct my syntax):

  method name () { return $.name }
  method name ( $name ) { $.name = $name; return $self }

Being able to overload methods and subroutines based on signatures is going to 
be a huge win.

Further, when other languages target Parrot, Perl6 will be able to comunicate 
with them *without* extra scaffolding code or you having to rewrite them!

Or how about the power of junctions?  Want to verify that none of the elements 
in one list are present in another?

  if all(@numbers) == none(@disallowed) {
 ...
  }

Ordinarily, writing code to do that is complicated and can be buggy and slow.  
This makes it much easier to read and can be run in parallel if your system 
supports it (is this correct?  I *think* it is).

And to multiple all items in an array by some value?

  @items = @items >>*<< 1.05; # add 5% sales tax

Anyone who's programmed OO code long enough knows the problems inherent in multiple 
inheritance.  These problems are so serious that some language simply forbid MI.  Java 
uses interfaces and Ruby uses mixins.  Both have problems limiting their use in 
large-scale code.  Perl6 will be the first mainstream language to incorporate traits 
(known as "roles" in Perl6) to eliminate these problems.  Traits are easy to 
use, very flexible and I found them more natural to use once I understood them (they've 
saved me major headaches in some of my code.  See Class::Traits for a fairly 
full-featured Perl5 implementation).

The list goes on and on.  Perl6 will run on Parrot and Parrot will the the CLR 
(common language runtime) for dynamic languages.  C# advocates *love* having 
the CLR available.  Now we'll have one too, but it will be geared towards 
dynamic langu

Re: perl 6 hosting?

2006-05-24 Thread David Cantrell
On Tue, May 23, 2006 at 06:29:06PM +0100, Michael Mathews wrote:

> Um, yes anyone wanna work on a tryperl6 virtual shell?

I might be able to host a virtual machine with perl6 on it and give out
accounts.  I need to think about how to stop people being naughty
though.

-- 
David Cantrell | top google result for "internet beard fetish club"

Computer Science is about lofty design goals and careful algorithmic
optimisation.  Sysadminning is about cleaning up the resulting mess.


Re: 3 Good Reasons...

2006-05-24 Thread Michael Mathews

Ah, perfect example Daniel. I know people say things like "Java is
better for big projects because of the strictness of it's typing". I
respond that Perl isn't intrinsically sloppy if you practice good
coding, it just doesn't straightjacket you into that all the time.

So here's Perl 6 and it has lovely typing! Yay. I can now say "$foo is
Scalar;" but erm, that's optional. To get the benefit you must still
hope for developer self-discipline (my day-job is maintaining and
refactoring other people's Perl, so I may be a teensy bit bitter about
relying on developer self-discipline).

Is there something in Perl 6 akin to a "use strict" switch that will
apply the straightjacket some projects need, and thus force typing of
all variables. (Then I could have a good comeback for those damned
Java guys.)

--michael

On 24/05/06, Daniel Hulme <[EMAIL PROTECTED]> wrote:

> what problems Perl 5 has that Perl 6 fixes

A type system to die for.

I think that is enough of a win on its own that mentioning any of the
other features will only muddy the issue :->

--
"The fact that some geniuses were laughed at does not imply that all who
are laughed at are geniuses.  They laughed at Columbus,  they laughed at
Fulton,  they laughed  at the Wright brothers.  But they also laughed at
Bozo the Clown."   --  Carl Sagan  http://surreal.istic.org/





Re: 3 Good Reasons... (typo alert!)

2006-05-24 Thread Ovid
Sheesh.  I type things too fast and then I see the horrifying typos I've made 
(blush)

- Original Message 
From: Ovid <[EMAIL PROTECTED]>

> do things that is hard to do in other languages.

"do things that *are* hard to do in other languages"

> Perl6 not only fixes a lot of that cruft but also adds new, powerful features 
> which
> makes programmers more productive and thus can churn out apps quicker.
 
"which make"

> The can alleviate many bugs

"This can alleviate many bugs"

> And to multiple all items in an array by some value?

"multiply"

OK, I'll stop now even though there's more.  Wow.  What a terrible mess.

As an aside for those who, like me, wanted to see support for logic 
programming:  the only significant disappoinment I have with Perl6 is also, 
oddly enough, accompanied by a sigh of relief.  Perl6 will easily support 
imperative, functional and OO syntax.  But what about logic programming?  Perl6 
rules might help, but there will be no support for things that Prolog and 
Mercury do naturally.

The "sigh of relief" stems from my realization that logic programming in Perl6 
would probably be implemented incorrectly because the easiest way to implement 
it is usually wrong, though this can be very tough to see at first.  It's my 
understanding that logic programming wasn't incorporated due to the desire to 
not delay the initial release of Perl6 (I could be wrong).  However, after 
having done a fair amount of work with logic programming, I realize that one of 
the greatest implementation mistakes with it is that results tend to be bags 
and not sets (SQL shares this problem).  Thus, when one naturally wants all of 
the answers to a query, one often gets duplicate results and this is almost 
always wrong. (See http://use.perl.org/~Ovid/journal/28378 for an SQL example 
of this problem).

Cheers,
Ovid





Re: 3 Good Reasons...

2006-05-24 Thread Ovid
- Original Message 
From: Michael Mathews <[EMAIL PROTECTED]>

> So my question to the list is, in simple terms even an IT manager
> could grasp, explain what problems Perl 5 has that Perl 6 fixes, such
> that they would want to undergo the pain of ever switching.




Hi Michael,

Many companies eventually switch to new languages.  The switch is painful, but 
when they see their current technologies aren't working, they reach for 
something else.  The question is, why Perl6?

Perl6, for those who have been paying attention, is revolutionary.  Not only 
will the language run much faster, but programmers will be more productive, 
they'll be able to seamlessly interact with code written in other languages and 
they'll be able to easily do things that is hard to do in other languages.

That's the short answer, but it sounds like a marketroid.  Here's (some of) the 
beef, though I'd be happy for corrections on any misconceptions below.

Perl5 is a very powerful language, but it does have plenty of cruft and is 
showing its age.  Perl6 not only fixes a lot of that cruft but also adds new, 
powerful features which makes programmers more productive and thus can churn 
out apps quicker.  Further, because it will be running on top of Parrot, it 
will be far faster than Perl5.  So you gain both programmer and runtime 
performance.

The most serious problems I have with Perl5 tend to center around its flexible 
but limited OO model.  Right now there's not a clear distinction between class 
and instance data.  This means that it's very easy to create class data which 
makes subclassing difficult at times.  Further, Perl5's poor argument handling 
is a constant source of bugs:

  sub some_value {
  my ($self, $value) = @_;
  return $self->{value} unless $value; # whoops!  Is "0" OK?
  $self->{value} = $value;
  return $self;
  }

Also, Perl6 will offer much strong encapsulation than one can "naturally" do in 
Perl5 (without resorting to inside-out objects, but I tend to recommend that 
folks not use those).

Perl6 offers optional strong typing, meaning that you can declare the above 
argument to some_value to be an integer and have less worries that someone will 
pass a string.  The strong typing means you can also do this:

  my int @array;

That will allow optimizations that are currently not possible, but since it's 
optional, you can choose the flexibility of late binding or the comfort of 
early binding (a bit of hand waving there).  

Multimethods are also very powerful, but difficult to do with Perl5 without 
extra (and slow) modules.  The can alleviate many bugs associated with methods 
(feel free to correct my syntax):

  method name () { return $.name }
  method name ( $name ) { $.name = $name; return $self }
 
Being able to overload methods and subroutines based on signatures is going to 
be a huge win.

Further, when other languages target Parrot, Perl6 will be able to comunicate 
with them *without* extra scaffolding code or you having to rewrite them!

Or how about the power of junctions?  Want to verify that none of the elements 
in one list are present in another?

  if all(@numbers) == none(@disallowed) {
 ...
  }

Ordinarily, writing code to do that is complicated and can be buggy and slow.  
This makes it much easier to read and can be run in parallel if your system 
supports it (is this correct?  I *think* it is).

And to multiple all items in an array by some value?

  @items = @items >>*<< 1.05; # add 5% sales tax

Anyone who's programmed OO code long enough knows the problems inherent in 
multiple inheritance.  These problems are so serious that some language simply 
forbid MI.  Java uses interfaces and Ruby uses mixins.  Both have problems 
limiting their use in large-scale code.  Perl6 will be the first mainstream 
language to incorporate traits (known as "roles" in Perl6) to eliminate these 
problems.  Traits are easy to use, very flexible and I found them more natural 
to use once I understood them (they've saved me major headaches in some of my 
code.  See Class::Traits for a fairly full-featured Perl5 implementation).

The list goes on and on.  Perl6 will run on Parrot and Parrot will the the CLR 
(common language runtime) for dynamic languages.  C# advocates *love* having 
the CLR available.  Now we'll have one too, but it will be geared towards 
dynamic languages.

Oh, and did I mention Perl6 rules?  That's probably one of the single most 
important things about Perl6.  Regular expressions have needed updating for a 
long time and @Larry has had the guts to bite the bullet.

All of these things (and many more) mean a language that's more productive for 
the programmer, runs much faster and is more flexible.  Further, the easy 
things are even easier than Perl5.  All of this translates to more $$ for 
companies.

Personally, I want to thank Larry, Damian, Luke, chromatic, Allison, Audrey and 
many more for their fine work in designing and implementing Perl6 (gush

Re: 3 Good Reasons...

2006-05-24 Thread Daniel Hulme
> what problems Perl 5 has that Perl 6 fixes

A type system to die for.

I think that is enough of a win on its own that mentioning any of the
other features will only muddy the issue :->

-- 
"The fact that some geniuses were laughed at does not imply that all who
are laughed at are geniuses.  They laughed at Columbus,  they laughed at
Fulton,  they laughed  at the Wright brothers.  But they also laughed at
Bozo the Clown."   --  Carl Sagan  http://surreal.istic.org/


pgpKvsEgdmrX8.pgp
Description: PGP signature


3 Good Reasons...

2006-05-24 Thread Michael Mathews

Open Question:

I realise I haven't kept up with every detail since the Perl6 RFC I
submitted way back in August 2000, but boy was I surprised to find,
now that I can actually use Perl6, it isn't just an improvement to
Perl (5), it's actually a "different language" (I'm quoting Michael
Schwern there, I'm not the first to notice this).

Now personally, I like learning new languages. I'm studying Ruby now,
and will probably play with Haskell, as well as Perl6. It's fun for
me. But knowing the people who have to sign paycheques over to us
developers as I do, I can say with some certainty: 1) they aren't at
all interested in our fun, 2) they actually consider lots of new and
different languages in their production code base to be scary, and 3)
if it ain't broke they will not want to spend money or effort to fix
it.

So my question to the list is, in simple terms even an IT manager
could grasp, explain what problems Perl 5 has that Perl 6 fixes, such
that they would want to undergo the pain of ever switching.

--michael



Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Steffen Schwigon <[EMAIL PROTECTED]> [2006-05-24 15:05]:
> "A. Pagaltzis" <[EMAIL PROTECTED]> writes:
> > Err I think you misread my mail. I meant that the code
> > modifies the hash, but does nothing to modify the reference,
> > so there is no need to make the reference read-write.
> 
> In my understanding, the '->' makes an alias to the elements of
> the hash, which is different from being a reference. And the
> "is rw" modifies that alias (the loop element).
> 
> You are right, in that the "is rw" shouldn't be needed because
> the loop element alias should be "rw" by default. Which in turn
> it isn't, because of the pugs bug.

You are still missing the point.

In Perl 5 terms:

use Readonly;
Readonly::Scalar my $hashref => {};
$hashref->{foo} = 1; # does not die

The read-only variable here is a reference to a hash. I can
freely modify the *hash*, regardless of whether the *reference*
to it is readonly or not.

Regards,
-- 
Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Ovid <[EMAIL PROTECTED]> [2006-05-24 18:00]:
> First off, thanks to Aristotle for clearing some of my
> thinking.

NP, it’s a good way for me to pick up the disparate Perl 6 clues
I picked up haphazardly over time, too.

> In my version of Pugs (6.2.11 (r10390)), that fails for two
> reasons, both of which I suspect are bugs.

These definitely sound like bugs – both of them.

>for %buckets.kv -> $i, $w {
> 
> Is .kv supposed to work there?  You're accessing an array, not
> a hash.

Yes, `.kv` is supposed to work on arrays, where it returns a list
of `$index => $value` pairs. This is very high on the list of
Perl 6 features I am anticipating eagerly, as it means you can
use natural `for(LIST)` constructs even when you need indices
while iterating, instead of having to use the familiar ugly
construction from Perl 5:

for my $i ( 0 .. $#array ) {
# use both $i and $array[ $i ] here
}

In Perl 6, indexing into [EMAIL PROTECTED] explicitly will *not* be
necessary here. Hooray!

Regards,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;


Re: eval

2006-05-24 Thread Yuval Kogman
On Wed, May 24, 2006 at 19:54:53 +0300, Gabor Szabo wrote:
> if eval "command" fails, where can I get the error message ?
> 
> aka  $@ in P5 ?

$!

http://dev.perl.org/perl6/doc/design/syn/S04.html#Exception_handlers

-- 
  Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org  0xEBD27418



pgpX95TPwbiEP.pgp
Description: PGP signature


Re: (Existing) Perl 6 Wiki: (http://perl.net.au/wiki/Perl_6)

2006-05-24 Thread Michael Mathews

As a competing suggestion, how about...
   http://pugs.kwiki.org/?perl6

I'm not really set on any option as long as it works and makes sense
to everyone, including those outside this list. I probably missed it,
but could you give the stated purpose for the wiki again, as I think a
reminder (for me at least) would help.

--michael


On 24/05/06, Michael Mathews <[EMAIL PROTECTED]> wrote:

Hi Conrad,

It's only an issue of coordination and findability. But that question
depends on what the intended purpose of the wiki would be. For example
there is nothing stopping anyone (including members of this list) from
creating and populating pages on www.wikipedia.org about Perl6 and
this user group. Then those pages would be available to the wikipedia
search engine. <--- Insert any other popular wiki there.

If, however, it is meant for mailing-list specific issues then only we
need to be able to easily find and search it, so there is no issue.
And of course with the ominipresence of google, finding and searching
is always becoming less of a problem.

What would be annoying though is to invest work in a "perl 6 wiki"
that is only one of many "perl 6 wikis" and with no coordination of
efforts between them. (is there an official "perl 6 user's wiki" or
will there be, or is that a different question?)

--michael


On 24/05/06, Conrad Schneiker <[EMAIL PROTECTED]> wrote:
> > From: Michael Mathews
> >
> > I for one, think a Perl6-users wiki would be extremely useful, I'm
> > just not sure why a site that distinguishes itself as "a portal for
> > the Australian and New Zealand Perl community" makes the most sense
>
> I was only thinking of the availability of an existing Perl 6 Wiki, not the
> site as such.
>
> > (particularly to anyone trying to find the Perl6-users wiki from
> > outside this mailing list).
>
> My guess is that that's a pretty much location-independent problem, unless
> (for examples), (1) you get perl.org to host a Perl 6 users wiki, (2) you
> get perl.org and allied sites to put a prominent link to it on their main
> Perl 6 pages, and so on.
>
> > Okay, New Zealand and Australia have "parrots" but the connection is a
> > stretch. Isn't Larry and/or Damian from Australia? Maybe that's the
> > connection?
>
> The only connection was that it turned up fairly high on the list when I
> googled for "perl6" and "wiki".
>
> (However: "Damian Conway holds a Ph.D. in Computer Science and is an
> Honorary Associate Professor with the School of Computer
> Science and Software Engineering at Monash University,
> Melbourne, Australia.")
>
> > I'm just askin'...
>
> HTH
>
> Best regards,
> Conrad Schneiker
>
> www.athenalab.com/Perl_6_Users_FAQ.htm
>
> www.AthenaLab.com (Nano-electron-beam technology.)
>
>



Re: Simple Print/Say Question

2006-05-24 Thread Ovid
First off, thanks to Aristotle for clearing some of my thinking.

- Original Message 
From: A. Pagaltzis <[EMAIL PROTECTED]>

>my %buckets = (
>w => {
>count => 4,
>scale => 10.5,
> },

>);
>
>for %buckets.values -> $arg_for {
>$arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ];
>}

In my version of Pugs (6.2.11 (r10390)), that fails for two reasons, both of 
which I suspect are bugs.  First, unless the hash elements have an "array => 
[]" pair, I seem to get the following error:

  *** Can't modify constant item: VUndef
  at bucket.p6 line 21, column 5-73

Line 21 in my code is the assignment to $arg_for.

However, even putting that back in results in the exact same error, so I had to 
change the line to:

  $arg_for.push((0 .. $arg_for) >>*<< $arg_for );

Now you might be thinking that I simply needed change the $arg_for 
assignment to a push and not included the "array => []" pair, but as it turns 
out, I need the pair *and* the push lest I get the VUndef error.

for %buckets.kv -> $i, $w {

Is .kv supposed to work there?  You're accessing an array, not a hash.

> I assume all those temporaries that I cleaned out were there for
> speed, in which case this will run slower, but they were too
> unsightly to keep around.

Yeah, that's why they were there.  However, the ($x, $y, $z).sum > $target is a 
much more useful performance hack, so you could get rid of the temporaries.

Cheers,
Ovid






eval

2006-05-24 Thread Gabor Szabo

if eval "command" fails, where can I get the error message ?

aka  $@ in P5 ?

Gabor


Re: Simple Print/Say Question

2006-05-24 Thread Ovid
- Original Message 
From: Jonathan Scott Duff <[EMAIL PROTECTED]>

> pushes an array reference onto @results (rather than things that are
> int). If you're going to type @results, maybe it needs to be:
>
> my @results is Array of Array of int;
>
> or maybe
>
> my Array of int @results;


Yes, I believe you're right.  Nice catch!

Too bad that generates the following error:

  *** 
  unexpected "o"
  expecting comment, variable name or "("
  at bucket.p6 line 24, column 10


As I recall, Pugs only uses the "int" and "array" stuff as comments right now, 
though I could be mistaken.

Cheers,
Ovid






Re: (Existing) Perl 6 Wiki: (http://perl.net.au/wiki/Perl_6)

2006-05-24 Thread Michael Mathews

Hi Conrad,

It's only an issue of coordination and findability. But that question
depends on what the intended purpose of the wiki would be. For example
there is nothing stopping anyone (including members of this list) from
creating and populating pages on www.wikipedia.org about Perl6 and
this user group. Then those pages would be available to the wikipedia
search engine. <--- Insert any other popular wiki there.

If, however, it is meant for mailing-list specific issues then only we
need to be able to easily find and search it, so there is no issue.
And of course with the ominipresence of google, finding and searching
is always becoming less of a problem.

What would be annoying though is to invest work in a "perl 6 wiki"
that is only one of many "perl 6 wikis" and with no coordination of
efforts between them. (is there an official "perl 6 user's wiki" or
will there be, or is that a different question?)

--michael


On 24/05/06, Conrad Schneiker <[EMAIL PROTECTED]> wrote:

> From: Michael Mathews
>
> I for one, think a Perl6-users wiki would be extremely useful, I'm
> just not sure why a site that distinguishes itself as "a portal for
> the Australian and New Zealand Perl community" makes the most sense

I was only thinking of the availability of an existing Perl 6 Wiki, not the
site as such.

> (particularly to anyone trying to find the Perl6-users wiki from
> outside this mailing list).

My guess is that that's a pretty much location-independent problem, unless
(for examples), (1) you get perl.org to host a Perl 6 users wiki, (2) you
get perl.org and allied sites to put a prominent link to it on their main
Perl 6 pages, and so on.

> Okay, New Zealand and Australia have "parrots" but the connection is a
> stretch. Isn't Larry and/or Damian from Australia? Maybe that's the
> connection?

The only connection was that it turned up fairly high on the list when I
googled for "perl6" and "wiki".

(However: "Damian Conway holds a Ph.D. in Computer Science and is an
Honorary Associate Professor with the School of Computer
Science and Software Engineering at Monash University,
Melbourne, Australia.")

> I'm just askin'...

HTH

Best regards,
Conrad Schneiker

www.athenalab.com/Perl_6_Users_FAQ.htm

www.AthenaLab.com (Nano-electron-beam technology.)




RE: (Existing) Perl 6 Wiki: (http://perl.net.au/wiki/Perl_6)

2006-05-24 Thread Conrad Schneiker
> From: Michael Mathews
> 
> I for one, think a Perl6-users wiki would be extremely useful, I'm
> just not sure why a site that distinguishes itself as "a portal for
> the Australian and New Zealand Perl community" makes the most sense

I was only thinking of the availability of an existing Perl 6 Wiki, not the
site as such.

> (particularly to anyone trying to find the Perl6-users wiki from
> outside this mailing list).

My guess is that that's a pretty much location-independent problem, unless
(for examples), (1) you get perl.org to host a Perl 6 users wiki, (2) you
get perl.org and allied sites to put a prominent link to it on their main
Perl 6 pages, and so on.

> Okay, New Zealand and Australia have "parrots" but the connection is a
> stretch. Isn't Larry and/or Damian from Australia? Maybe that's the
> connection?

The only connection was that it turned up fairly high on the list when I
googled for "perl6" and "wiki". 

(However: "Damian Conway holds a Ph.D. in Computer Science and is an
Honorary Associate Professor with the School of Computer
Science and Software Engineering at Monash University,
Melbourne, Australia.")

> I'm just askin'... 

HTH

Best regards,
Conrad Schneiker
 
www.athenalab.com/Perl_6_Users_FAQ.htm

www.AthenaLab.com (Nano-electron-beam technology.)



Re: Simple Print/Say Question

2006-05-24 Thread Jonathan Scott Duff
My two cents ...

On Wed, May 24, 2006 at 10:52:29AM +0200, A. Pagaltzis wrote:
> my int @results;

The above line says that @results is an array of integers, but ...

>  @results.push( [$i, $j, $k, $l] );

pushes an array reference onto @results (rather than things that are
int). If you're going to type @results, maybe it needs to be:

my @results is Array of Array of int;

or maybe

my Array of int @results;

Or something like that :-)

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]


Re: Simple Print/Say Question

2006-05-24 Thread Steffen Schwigon
"A. Pagaltzis" <[EMAIL PROTECTED]> writes:
> * Steffen Schwigon <[EMAIL PROTECTED]> [2006-05-24 13:55]:
>> "A. Pagaltzis" <[EMAIL PROTECTED]> writes:
>> > * Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 12:25]:
>> >> I understand this as the hash entry with key 'array' get
>> >> assigned a array consisting of $count number multiplied by
>> >> $scale. If that is right, we must be modifying $arg_for
>> >> (%buckets) since we are adding an entry to the hash.
>> >
>> > $arg_for is a reference to a hash. The hash is modified, but
>> > not the reference to it.
>> 
>> It's probably an unimplemented/buggy feature of Pugs.
>
> Err I think you misread my mail. I meant that the code modifies
> the hash, but does nothing to modify the reference, so there is
> no need to make the reference read-write.

In my understanding, the '->' makes an alias to the elements of the
hash, which is different from being a reference. And the "is rw"
modifies that alias (the loop element).

You are right, in that the "is rw" shouldn't be needed because the
loop element alias should be "rw" by default. Which in turn it isn't,
because of the pugs bug.

That's I think why the discussed problem and the pugsbug could be
related.

Steffen
-- 
Steffen Schwigon <[EMAIL PROTECTED]>
Dresden Perl Mongers 


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Steffen Schwigon <[EMAIL PROTECTED]> [2006-05-24 13:55]:
> "A. Pagaltzis" <[EMAIL PROTECTED]> writes:
> > * Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 12:25]:
> >> I understand this as the hash entry with key 'array' get
> >> assigned a array consisting of $count number multiplied by
> >> $scale. If that is right, we must be modifying $arg_for
> >> (%buckets) since we are adding an entry to the hash.
> >
> > $arg_for is a reference to a hash. The hash is modified, but
> > not the reference to it.
> 
> It's probably an unimplemented/buggy feature of Pugs.

Err I think you misread my mail. I meant that the code modifies
the hash, but does nothing to modify the reference, so there is
no need to make the reference read-write.

Regards,
-- 
Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread Steffen Schwigon
"A. Pagaltzis" <[EMAIL PROTECTED]> writes:
> * Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 12:25]:
>> I understand this as the hash entry with key 'array' get
>> assigned a array consisting of $count number multiplied by
>> $scale. If that is right, we must be modifying $arg_for
>> (%buckets) since we are adding an entry to the hash.
>
> $arg_for is a reference to a hash. The hash is modified, but
> not the reference to it.

It's probably an unimplemented/buggy feature of Pugs.

I didn't completely follow every detail of your discussion but I know
of a problem where aliasing only works readonly, currently. There is a
pugsbugs-test for that problem. See

  http://svn.perl.org/perl6/pugs/trunk/t/pugsbugs/value_alias_readonly.t

Currently one has to workaround that, e.g. work with hash elements and
explicitly assign the result back via "%hash{$_} = ..." or similar.

AFAIR.

GreetinX
Steffen 
-- 
Steffen Schwigon <[EMAIL PROTECTED]>
Dresden Perl Mongers 


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Daniel Hulme <[EMAIL PROTECTED]> [2006-05-24 12:45]:
> > $arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ]; 
>
> btw, shouldn't the >>*<< be >>* as the right-hand operand is a
> scalar?

I don’t know. S03 says:

| If either argument is insufficiently dimensioned, Perl
| "upgrades" it:
| 
|  (3,8,2,9,3,8) >>-<< 1;  # (2,7,1,8,2,7)

So I assume my syntax was correct, though it might not have been
necessary. I don’t understand one-sided hyper-operators well yet.

Regards,
-- 
Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 12:25]:
> I understand this as the hash entry with key 'array' get
> assigned a array consisting of $count number multiplied by
> $scale. If that is right, we must be modifying $arg_for
> (%buckets) since we are adding an entry to the hash.

$arg_for is a reference to a hash. The hash is modified, but
not the reference to it.

Regards,
-- 
Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread Daniel Hulme
Wrt your second problem, if this
> $arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ]; 
is not rw so is not actually adding the entry to the hash (btw,
shouldn't the >>*<< be >>* as the right-hand operand is a scalar?), then
it is possible that
> > > And then I get an error telling me 'No such method in class
> > > Scalar: "&kv"' in the line 
> > > 
> > > for %buckets.kv -> $i, $w {
means that %buckets is being autovivisected (or whatever you
call it) as a Scalar element of %buckets, rather than being a hash?

Just a thought. I was under the impression that writing to an argument
that is not rw should generate an error, unless it is copy, in which
case it should do what it seems to be doing. It's possible that Pugs has
not (yet) implemented this exactly, though.

-- 
You can't run away  forever,  but there's  nothing wrong with  getting a
good head start.  You want to shut out the night,  you want to shut down
the  sun,  you  want  to  shut  away  the  pieces  of  a  broken  heart.
`Rock and Roll Dreams Come True' (Steinman)http://surreal.istic.org/


signature.asc
Description: Digital signature


Re: Simple Print/Say Question

2006-05-24 Thread Martin Kjeldsen
Hi Aristotle,

A. Pagaltzis (12:12 2006-05-24):
> Hi Martin,
> 
> * Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 11:50]:
> > Just curious does this actually run? I'm trying on pugs 6.2.11
> > and it complains quite a bit. First of all shouldn't
> > 
> > for %buckets.values -> $arg_for
> > 
> > be 
> > 
> > for %buckets.values -> $arg_for is rw
> > 
> > since $arg_for is modified?
> 
> No, $arg_for is not modified.
> 

Sorry it could be just me, but isn't $arg_for modified in this

$arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ]; 

I understand this as the hash entry with key 'array' get assigned a array 
consisting of $count number multiplied by $scale. If that is right, we must be 
modifying $arg_for (%buckets) since we are adding an entry to the hash.

> > And then I get an error telling me 'No such method in class
> > Scalar: "&kv"' in the line 
> > 
> > for %buckets.kv -> $i, $w {
> 
> Strange. I did this just by looking at synopses, though, so my
> syntax is probably slightly off.

I don't understand why it dosn't work at all, maybe .kv isn't implemented yet 
in 
pugs.

> 
> Regards,
> -- 
> Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
Hi Martin,

* Martin Kjeldsen <[EMAIL PROTECTED]> [2006-05-24 11:50]:
> Just curious does this actually run? I'm trying on pugs 6.2.11
> and it complains quite a bit. First of all shouldn't
> 
> for %buckets.values -> $arg_for
> 
> be 
> 
> for %buckets.values -> $arg_for is rw
> 
> since $arg_for is modified?

No, $arg_for is not modified.

> And then I get an error telling me 'No such method in class
> Scalar: "&kv"' in the line 
> 
> for %buckets.kv -> $i, $w {

Strange. I did this just by looking at synopses, though, so my
syntax is probably slightly off.

Regards,
-- 
Aristotle Pagaltzis // 


Re: Simple Print/Say Question

2006-05-24 Thread Martin Kjeldsen
Just curious does this actually run? I'm trying on pugs 6.2.11 and it complains 
quite a bit. First of all shouldn't

for %buckets.values -> $arg_for

be 

for %buckets.values -> $arg_for is rw

since $arg_for is modified?

And then I get an error telling me 'No such method in class Scalar: "&kv"' in 
the line 

for %buckets.kv -> $i, $w {

Is it just me?

Regards

Martin

A. Pagaltzis (10:52 2006-05-24):
> my %buckets = (
>  w => {
> count => 4,
> scale => 10.5,
>  },
>  x => {
> count => 6,
> scale => 7,
>  },
>  y => {
> count => 12,
> scale => 3,
>  },
>  z => {
> count => 18,
> scale => 2,
>  },
> );
> 
> for %buckets.values -> $arg_for {
> $arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ];
> }
> 
> my int @results;
> my int $target = 35;
> 
> for %buckets.kv -> $i, $w {
> say "To 4: $i";
> last if $w > $target;
> for %buckets.kv -> $j, $x {
> say "  To 6: $j";
> last if ($w, $x).sum > $target;
> for %buckets.kv -> $k, $y {
> last if ($w, $x, $y).sum > $target;
> for %buckets.kv -> $l, $z {
> if( $target == ($w, $x, $y, $z).sum ) {
> @results.push( [$i, $j, $k, $l] );
> }
> }
> }
> }
> }
> 
> for @results.kv -> $idx, $result {
> say "$idx: $result.join(' | ')";
> }
> 
> I assume all those temporaries that I cleaned out were there for
> speed, in which case this will run slower, but they were too
> unsightly to keep around.
> 
> Regards,
> -- 
> #Aristotle
> *AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
> &Just->another->Perl->hacker;


Re: Simple Print/Say Question

2006-05-24 Thread Chris Yocum

Hi Everyone,
I never thought that my little script would get such loving
attention least of all from such distinguished members of the
community.  It took me a little while to understand exactly what was
going on but now that I do, it looks very good.
Thank you again!  It has been very instructive.

Chris

On 5/24/06, A. Pagaltzis <[EMAIL PROTECTED]> wrote:

my %buckets = (
 w => {
count => 4,
scale => 10.5,
 },
 x => {
count => 6,
scale => 7,
 },
 y => {
count => 12,
scale => 3,
 },
 z => {
count => 18,
scale => 2,
 },
);

for %buckets.values -> $arg_for {
$arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ];
}

my int @results;
my int $target = 35;

for %buckets.kv -> $i, $w {
say "To 4: $i";
last if $w > $target;
for %buckets.kv -> $j, $x {
say "  To 6: $j";
last if ($w, $x).sum > $target;
for %buckets.kv -> $k, $y {
last if ($w, $x, $y).sum > $target;
for %buckets.kv -> $l, $z {
if( $target == ($w, $x, $y, $z).sum ) {
@results.push( [$i, $j, $k, $l] );
}
}
}
}
}

for @results.kv -> $idx, $result {
say "$idx: $result.join(' | ')";
}

I assume all those temporaries that I cleaned out were there for
speed, in which case this will run slower, but they were too
unsightly to keep around.

Regards,
--
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;



Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
my %buckets = (
 w => {
count => 4,
scale => 10.5,
 },
 x => {
count => 6,
scale => 7,
 },
 y => {
count => 12,
scale => 3,
 },
 z => {
count => 18,
scale => 2,
 },
);

for %buckets.values -> $arg_for {
$arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ];
}

my int @results;
my int $target = 35;

for %buckets.kv -> $i, $w {
say "To 4: $i";
last if $w > $target;
for %buckets.kv -> $j, $x {
say "  To 6: $j";
last if ($w, $x).sum > $target;
for %buckets.kv -> $k, $y {
last if ($w, $x, $y).sum > $target;
for %buckets.kv -> $l, $z {
if( $target == ($w, $x, $y, $z).sum ) {
@results.push( [$i, $j, $k, $l] );
}
}
}
}
}

for @results.kv -> $idx, $result {
say "$idx: $result.join(' | ')";
}

I assume all those temporaries that I cleaned out were there for
speed, in which case this will run slower, but they were too
unsightly to keep around.

Regards,
-- 
#Aristotle
*AUTOLOAD=*_;sub _{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;


Re: Simple Print/Say Question

2006-05-24 Thread Larry Wall
You should not need "my" on the right side of a ->.  Also, you should
be able to write $arg_for for constant subscripts.

Larry

On Tue, May 23, 2006 at 05:32:22PM -0700, Ovid wrote:
: Er, and the first loop is better written as this:
: 
:   for %buckets.values -> my $arg_for {
:   for 0 .. $arg_for{'count'} -> $index {
:   $arg_for{'array'}.push($index * $arg_for{'scale'});
:   }
:   }
:  
: Instead of:
: 
:   for %buckets.kv -> my $bucket, $arg_for {
:   for 0 .. $arg_for{'count'} -> $index {
:   $arg_for{'array'}.push($index * $arg_for{'scale'});
:   } 
:   }
: 
: Cheers,
: Ovid
: 
: 
: -- If this message is a response to a question on a mailing list, please send 
follow up questions to the list.
:  
: Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
: 
: 
: 
: