Junctions - feedback and desires

2005-03-10 Thread Terrence Brannon
I gave a talk on Perl 6 Junctions at the Thousand Oaks Perl Mongers
meeting last night

   http://www.hcoop.net/~terry/perl/talks/p6-junctions/index.html 
 
and two questions/desires came out of it: 
 
1: will it be possible to know which element of a junction is 
currently being used? E.g.: 
 
my @first_set = qw(1 1); 
my @new_set = qw(1 1.4 1 1 8 1 1 1 0.8); 
 
my $any_new_set = any(@new_set); 
my $any_first_set = any(@first_set); 
 
if ( (abs($any_first_set - $any_new_set)) > 0.5) { 
  "a variation in the readings is too large".say; 
  printf "we we examining %d and %d when it happened", 
  $any_new_set.current, $any_first_set.current ; # desired feature
  
} 
 
2: Unless the array of values can be specified lazily, it will not be 
practical to use Perl 6 Junctions on large datasets. For example  I
might like to be able to specify a sub ref/closure whose execution yields a
new array value or undef when no more values. I.e.:

sub mynext {
my($age) = $sth->fetchrow_array;
$age
}

my $junction = any(\&mynext) ;

3: Do junctions short circuit? I.e., whenever the condition is met,
does it continue immediately. Using the example from point #1, can we assume
that the body of the "then" branch will fire when 8 of @new_set is
encountered?


is "flattening" the word to use when describing lazy lists?

2005-04-04 Thread Terrence Brannon

A Perl 5 user thinks of flattening a data structure as taking
something which is nested and "linearizing" it.

FOR EXAMPLE:

 use Data::Hash::Flatten;

  # NESTED DATA
  my $a = { bill => { '5/27/96' => { 'a.dat' => 1, 'b.txt' => 2,
  'c.lsp' => 3 } },
jimm => { '6/22/98' => { 'x.prl' => 9, 'y.pyt' => 8,
'z.tcl' => 7 } } } ;


  my @a = Data::Hash::Flatten->this($a, [qw(name date file)]);
  
  use Data::Dumper;
  print Dumper([EMAIL PROTECTED]);

  # FLATTENED DATA
  $VAR1 = [
  {
'date' => '6/22/98',
'name' => 'jimm',
'file' => 'z.tcl'
  },
  {
'date' => '6/22/98',
'name' => 'jimm',
'file' => 'y.pyt'
  },
  {
'date' => '6/22/98',
'name' => 'jimm',
'file' => 'x.prl'
  },
  {
'date' => '5/27/96',
'name' => 'bill',
'file' => 'c.lsp'


HERE'S ANOTHER EXAMPLE:

@ary = (@a,@b,@c);

All three arrays are not nested into @ary, but flattened into @ary.

TO SUMMARIZE:

flatten means something particular to Perl 5 users and the usage of
the term "flatten" in http://dev.perl.org/perl6/synopsis/S06.html
has no relation to its previously understood meaning.

A more accurate term might be generated or reified, because the
abstract, existent-only-in-conception list members are
concretized/generated/reified via slurping.


SUGGESTIONS:

Change this


Slurpy parameters are treated lazily -- the list is only flattened
into an array when individual elements are actually accessed:

@fromtwo = tail(1..Inf);# @fromtwo contains a lazy [2..Inf]



To this:


Slurpy parameters are treated lazily -- the list is only
concretized/generated/realized/reified/actualized
into an array when individual elements are actually accessed:

@fromtwo = tail(1..Inf);# @fromtwo contains a lazy [2..Inf]




Change this:


Flattening argument lists


to this:


Actualizing argument lists



Second use of flattening

2005-04-04 Thread Terrence Brannon
The first discussion of flattening had to do with a list of data being
flattened into an array.

Further down we see another different use of the word "flattening" : 

http://dev.perl.org/perl6/synopsis/S06.html
   section="Flattening lists">

  The unary prefix operator * flattens its operand (which allows the
  elements of an array or iterator to be used as an argument list). 



Here I understand this to mean that the array is spreading or
distributing its elements to individual scalars.

So, to avoid confusion with the common understanding of flattening in
Perl, perhaps it should be called spreading or distributing.


Re: trim() and words() functions?

2005-04-16 Thread Terrence Brannon
[EMAIL PROTECTED] (Larry Wall) writes:


>  Of course, generations of Perl programmers have
> made do with various forms of s///,

I have found String::Strip on CPAN to work well for my needs in this
area.


adverbial blocks: description and examples requested

2005-05-05 Thread Terrence Brannon
I was looking at a line in the hangman program:

  @letters == @solution.grep:{ $_ ne '' }; 

and was told that I was looking at an adverbial block.

But I don't understand what that is and could not find a description
and examples in a reverse search on dev and nntp.perl.org.

I would appreciate any information on this topic.

Thanks




Re: adverbial blocks: description and examples requested

2005-05-05 Thread Terrence Brannon
Luke Palmer <[EMAIL PROTECTED]> writes:

> Ugh, hit "a" in gmail when replying!
>
> On 5/5/05, Terrence Brannon <[EMAIL PROTECTED]> wrote:
>> I was looking at a line in the hangman program:
>>
>>   @letters == @solution.grep:{ $_ ne '' };
>>
>> and was told that I was looking at an adverbial block.
>
> The adverbial block is what you're giving to `if` when you say:
>
> if $foo { ... }

It is? An adverb describes a verb. What is the verb here?

> On the statement level, it looks like a block in operator position.

On statement level... hmmm. Statement I think I understand: a complete
sentence made up of expressions. "operator position" - how am I to
know where operator position is?

I'm really just asking these two questions about "statement level" and
"operator position" so that you will be aware that not everyone will
understand what you mean by these terms and you might want to explain
them fully before using them when you write a Perl 6 tutorial/book/
etc.

Don't bother explaining them to me. I can figure out what I need
without knowing what you meant here.

> > However, on the expression level, it is preceded by a colon, and goes
> into the *& argument of the sub.
>
> sub grep (*&block, [EMAIL PROTECTED]) {...}

why must &block be slurpy? can't it be specified as a required
parameter like so:

sub grep (&block, [EMAIL PROTECTED]) {...}

>
> (I don't know about the ordering of those arguments)
>
> It was invented to avert the annoying ({ }) construct, especially when
> used in a series:
>
> @result = @input.grep:{...}.map:{...}

So the annoying way to write this would be this?

@result = map {   } (grep { } @input) ;

where the parentheses are required?

So what are the colon-free ways to write this, which is not in series:

sub has_won returns Bool { 
@letters == @solution.grep:{ $_ ne '' }; 
} 


>
> Did that answer your question?

yes, to a large extent and way way faster than anticipated!

> >
> Luke

-- 
Carter's Compass: I know I'm on the right track when,
   by deleting something, I'm adding functionality.



Re: adverbial blocks: description and examples requested

2005-05-10 Thread Terrence Brannon
Luke Palmer <[EMAIL PROTECTED]> writes:

> On 5/5/05, Terrence Brannon <[EMAIL PROTECTED]> wrote:
>> I was looking at a line in the hangman program:
>>
>>   @letters == @solution.grep:{ $_ ne '' };
>>
>> and was told that I was looking at an adverbial block.
>
> The adverbial block is what you're giving to `if` when you say:
>
> if $foo { ... }

But no colon is used in this case. Is that consistent?

-- 
Carter's Compass: I know I'm on the right track when,
   by deleting something, I'm adding functionality.



Re: adverbial blocks: description and examples requested

2005-05-10 Thread Terrence Brannon
Ashley, this is a great post. I have included it almost verbatim in my
p6 talk I'm giving tomorrow at our Perl Monger's meeting:

   http://www.metaperl.com/talks/p6/hangman-elucidated/slide6.html

I hope you don't mind.

> On 5/5/05, Terrence Brannon <[EMAIL PROTECTED]> wrote:
>> I was looking at a line in the hangman program:
>> 
>>   @letters == @solution.grep:{ $_ ne '' };
>> 
>> and was told that I was looking at an adverbial block.
>> 
>> But I don't understand what that is and could not find a description
>> and examples in a reverse search on dev and nntp.perl.org.
>
> Methods with arguments require parens. However, the block to grep
> isn't I an argument. It's describing the manner in which the
> array will be grepped... that's an adverb to grep.
>
> So, why are the parens required on methods? Take the following if statements:
>
> if @foo.shift { ... }
>
> if @foo.grep { ... }   # grep doesn't get the block
>
> To make things clear, methods without parens are assumed to take no
> arguments. In order to pass a block to the above grep, you either need
> to use @foo.grep({ $^a <=> $^b}) or the adverbial colon:
>
> if @foo.grep:{$^a <=> $^b} { ... }
>
> Ashley Winters

-- 
Carter's Compass: I know I'm on the right track when,
   by deleting something, I'm adding functionality.



Re: Syntax of using Perl5 modules?

2005-05-25 Thread Terrence Brannon
Autrijus Tang <[EMAIL PROTECTED]> writes:

> So, this now works in Pugs with (with a "env PUGS_EMBED=perl5" build):
>
> use Digest--perl5;
>
> my $cxt = Digest.SHA1;
> $cxt.add('Pugs!');
>
> # This prints: 66db83c4c3953949a30563141f08a848c4202f7f
> say $cxt.hexdigest;
>
> This includes the "Digest.pm" from Perl 5.  DBI.pm, CGI.pm etc will
> also work.
>
> Now my question is, is my choice of using the "perl5" namespace indicator a 
> sane way to handle this? 

I was getting used to ":" as an adverbial and adjective modifier. So I
would think the above would be:

use Digest:perl5

but that would be confusing given that two colons separate parts of a
package namespace.

-- 
Carter's Compass: I know I'm on the right track when,
   by deleting something, I'm adding functionality.