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_forarray = [ ( 0 .. $arg_forcount ) »*« $arg_forscale ];
}

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

for %bucketswarray.kv - $i, $w {
say To 4: $i;
last if $w  $target;
for %bucketsxarray.kv - $j, $x {
say   To 6: $j;
last if ($w, $x).sum  $target;
for %bucketsyarray.kv - $k, $y {
last if ($w, $x, $y).sum  $target;
for %bucketszarray.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 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 %bucketswarray.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_forarray = [ ( 0 .. $arg_forcount ) »*« $arg_forscale ];
 }
 
 my int @results;
 my int $target = 35;
 
 for %bucketswarray.kv - $i, $w {
 say To 4: $i;
 last if $w  $target;
 for %bucketsxarray.kv - $j, $x {
 say   To 6: $j;
 last if ($w, $x).sum  $target;
 for %bucketsyarray.kv - $k, $y {
 last if ($w, $x, $y).sum  $target;
 for %bucketszarray.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
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 %bucketswarray.kv - $i, $w {

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

Regards,
-- 
Aristotle Pagaltzis // http://plasmasturm.org/


Re: Simple Print/Say Question

2006-05-24 Thread A. Pagaltzis
* Daniel Hulme [EMAIL PROTECTED] [2006-05-24 12:45]:
  $arg_forarray = [ ( 0 .. $arg_forcount ) »*« $arg_forscale ]; 

 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 // http://plasmasturm.org/


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 %bucketswarray.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: Simple Print/Say Question

2006-05-23 Thread Gabor Szabo

On 5/23/06, Chris Yocum [EMAIL PROTECTED] wrote:


1|2|3

I would say something like:

print $array[0] . | . $array[1] . | . $array[2] . \n;

not the best way but it works.

In Perl6 if say something like this:

print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] . \n;

I get

1 2 3 | | |

My question is: why is it doing that or, more to the point, what am I
doing wrong?



I am not sure, maybe the . before \n cause the problem but why not try this
one:

my @array = (1, 2, 3);
say join |, @array;

Gabor


Re: Simple Print/Say Question

2006-05-23 Thread Fagyal Csongor
Chris,

Strange. I have just tried this using an old version (6.2.3) of Pugs:

my (@array) = 1,2,3;
print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

It prints
1|2|3
on my terminal.

Gabor's join-ed version also works.

- Fagzal

 Oops.  That last . is a typo on my part.  Sorry about that!  It should
 read, which it does in my code:

 print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

 However, your say join technique does not work.  I will keep on it but
 for now I am off to dinner!

 Thanks!,
 Chris

 On 5/23/06, Gabor Szabo [EMAIL PROTECTED] wrote:
 On 5/23/06, Chris Yocum [EMAIL PROTECTED] wrote:
 
  1|2|3
 
  I would say something like:
 
  print $array[0] . | . $array[1] . | . $array[2] . \n;
 
  not the best way but it works.
 
  In Perl6 if say something like this:
 
  print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] . \n;
 
  I get
 
  1 2 3 | | |
 
  My question is: why is it doing that or, more to the point, what am
 I doing wrong?
 

 I am not sure, maybe the . before \n cause the problem but why not
 try this one:

 my @array = (1, 2, 3);
 say join |, @array;

 Gabor





Re: Simple Print/Say Question

2006-05-23 Thread Chris Yocum

Dear Fagyal,
Huh.  Strange.  I tried the code on its own without the rest of
the script and it did just fine as well.  There must be something
wrong in my script somewhere.

Chris

On 5/23/06, Fagyal Csongor [EMAIL PROTECTED] wrote:

Chris,

Strange. I have just tried this using an old version (6.2.3) of Pugs:

my (@array) = 1,2,3;
print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

It prints
1|2|3
on my terminal.

Gabor's join-ed version also works.

- Fagzal

 Oops.  That last . is a typo on my part.  Sorry about that!  It should
 read, which it does in my code:

 print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

 However, your say join technique does not work.  I will keep on it but
 for now I am off to dinner!

 Thanks!,
 Chris

 On 5/23/06, Gabor Szabo [EMAIL PROTECTED] wrote:
 On 5/23/06, Chris Yocum [EMAIL PROTECTED] wrote:
 
  1|2|3
 
  I would say something like:
 
  print $array[0] . | . $array[1] . | . $array[2] . \n;
 
  not the best way but it works.
 
  In Perl6 if say something like this:
 
  print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] . \n;
 
  I get
 
  1 2 3 | | |
 
  My question is: why is it doing that or, more to the point, what am
 I doing wrong?
 

 I am not sure, maybe the . before \n cause the problem but why not
 try this one:

 my @array = (1, 2, 3);
 say join |, @array;

 Gabor






Re: Simple Print/Say Question

2006-05-23 Thread Ovid
This seems to work for me:

  pugs -e 'say (1,2,3).join(|)'
  1|2|3

Or even:

  pugs -e '(1,2,3).join(|).say'
  1|2|3

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/

- Original Message 
From: Fagyal Csongor [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: perl6-users@perl.org
Sent: Tuesday, May 23, 2006 12:11:07 PM
Subject: Re: Simple Print/Say Question

Chris,

Strange. I have just tried this using an old version (6.2.3) of Pugs:

my (@array) = 1,2,3;
print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

It prints
1|2|3
on my terminal.

Gabor's join-ed version also works.

- Fagzal

 Oops.  That last . is a typo on my part.  Sorry about that!  It should
 read, which it does in my code:

 print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] ~ \n;

 However, your say join technique does not work.  I will keep on it but
 for now I am off to dinner!

 Thanks!,
 Chris

 On 5/23/06, Gabor Szabo [EMAIL PROTECTED] wrote:
 On 5/23/06, Chris Yocum [EMAIL PROTECTED] wrote:
 
  1|2|3
 
  I would say something like:
 
  print $array[0] . | . $array[1] . | . $array[2] . \n;
 
  not the best way but it works.
 
  In Perl6 if say something like this:
 
  print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] . \n;
 
  I get
 
  1 2 3 | | |
 
  My question is: why is it doing that or, more to the point, what am
 I doing wrong?
 

 I am not sure, maybe the . before \n cause the problem but why not
 try this one:

 my @array = (1, 2, 3);
 say join |, @array;

 Gabor









Re: Simple Print/Say Question

2006-05-23 Thread Dr.Ruud
Chris Yocum schreef:

 print @array[0] ~ | ~ @array[1] ~ | ~ @array[2] . \n;

First the Perl6-equivalent of

  $ = '|' ;

and then

  say @array ;

-- 
Affijn, Ruud

Gewoon is een tijger.