Re: REs as generators

2002-12-12 Thread Dave Storrs
On Thu, Dec 12, 2002 at 10:35:47AM +1100, Damian Conway wrote:
 Dave Storrs wrote:
  - the ability for the programmer to set limiters (??better name??)
  on the junction, which will specify how the junction should
  collapse--e.g. always collapse to the lowest/highest value that hasn't
  been supplied yet, or to the lowest/highest unsupplied value that
  causes a particular code block to return true, or whatever.
 
 Junctions don't collapse. They distribute.
 
 Remember: Junctions Aren't Quantum.

Ah.  Obviously, I don't know JAQ. (sorry)

However, I don't believe this answers my question...or, more likely, I
am just misunderstanding junctions.  I believe that this code:

my $i = one(7...);
print $i;

Is roughly equivalent to this English:

- declare a lexical variable $i 
- create a junction.  The states of the junction are (7..Inf).  The
type of the junction is one 
- assign the junction to $i
- distribute the junction [that still doesn't sound right, but ok] by
choosing one of the states (at random??)
- print the number chosen in the previous step.

First of all, am I correct about this?

Second, what I was originally asking is this: could there be some way
for the programmer to attach a (method/code block/sub/whatever) to the
junction, such that when the state is chosen, the default method of
choosing a state is overriden by the code supplied by the programmer.


--Dks



Re: REs as generators

2002-12-12 Thread Luke Palmer
 Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
 Date: Wed, 11 Dec 2002 17:24:54 -0800
 From: Dave Storrs [EMAIL PROTECTED]
 Mail-Followup-To: [EMAIL PROTECTED] [EMAIL PROTECTED]
 Content-Disposition: inline
 X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
 
 On Thu, Dec 12, 2002 at 10:35:47AM +1100, Damian Conway wrote:
  Dave Storrs wrote:
   - the ability for the programmer to set limiters (??better name??)
   on the junction, which will specify how the junction should
   collapse--e.g. always collapse to the lowest/highest value that hasn't
   been supplied yet, or to the lowest/highest unsupplied value that
   causes a particular code block to return true, or whatever.
  
  Junctions don't collapse. They distribute.
  
  Remember: Junctions Aren't Quantum.
 
 Ah.  Obviously, I don't know JAQ. (sorry)
 
 However, I don't believe this answers my question...or, more likely, I
 am just misunderstanding junctions.  I believe that this code:
 
   my $i = one(7...);
   print $i;
 
 Is roughly equivalent to this English:
 
 - declare a lexical variable $i 
 - create a junction.  The states of the junction are (7..Inf).  The
   type of the junction is one 
 - assign the junction to $i
 - distribute the junction [that still doesn't sound right, but ok] by
   choosing one of the states (at random??)
 - print the number chosen in the previous step.

No collapsing.  Not without an explicit .pick.  It would call Cprint
with each of the values of $i  (unless print was designed to accept a
junction, in which case you'd get some stringification/serialization
of the junction).  Cprint would return a one() junction of whatever
print returned after printing each value, but what do you care,
they're all in the garbage anyway? :)

 First of all, am I correct about this? 

No. As I just explained.

 Second, what I was originally asking is this: could there be some way
 for the programmer to attach a (method/code block/sub/whatever) to the
 junction, such that when the state is chosen, the default method of
 choosing a state is overriden by the code supplied by the programmer.

Your question is now irrelevant.

Luke



Re: REs as generators

2002-12-12 Thread Nicholas Clark
On Wed, Dec 11, 2002 at 06:53:20PM -0800, Randal L. Schwartz wrote:
  Rich == Rich Morin [EMAIL PROTECTED] writes:
 
 Rich On occasion, I have found it useful to cobble up a little language
 Rich that allows me to generate a list of items, using a wild-card or some
 Rich other syntax, as:
 
 Richfoo[0-9][0-9]  yields foo00, foo01, ...
 
 Rich I'm wondering whether Perl should have a similar capability, using REs.
 
 Well, here's a cheap way:
 
 my @list = glob ('foo{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}');
 
 :-)

Cheap in terms of programmer effort. But it uses a lot of RAM in perl5.
Enough the the golfers get upset that some of the shortest solutions don't
work because they run out of swap. IIRC Hugo is lucky because his auction of
an improvement for perl 5.10 could easily have ended up with a bidder who
wanted multiway globs to work in much less RAM.

Nicholas Clark



Re: REs as generators

2002-12-11 Thread Damian Conway
Luke Palmer wrote:


 LP my $foos = 'foo' ~ any(0..9) ~ any(0..9);



Actually $foos will be a junction.  You could use Cstates to get
each state out of the junction in an array.

my @foos = states $foos;


Luke's right on target (as usual :-). Just one slight niggle. I suspect
Cstates may be a method only, so that would be either:

  my @foos = states $foos:;

or:

  my @foos = $foos.states;

Though, I suppose we might argue that Cstates is as fundamental to Perl 6
as Cgrep or Csort, and so ought to have a built-in as well. Hmmm.

Damian




Re: REs as generators

2002-12-11 Thread Luke Palmer
 Date: Wed, 11 Dec 2002 19:15:53 +1100
 From: Damian Conway [EMAIL PROTECTED]
 
 I suspect Cstates may be a method only, so that would be either:
 
my @foos = states $foos:;
 
 or:
 
my @foos = $foos.states;
 
 Though, I suppose we might argue that Cstates is as fundamental to Perl 6
 as Cgrep or Csort, and so ought to have a built-in as well. Hmmm.

Can junctions have methods?  How do you tell the difference between
calling a junction's method and calling a method on each of its
states?

Luke



Re: REs as generators

2002-12-11 Thread Dave Storrs
On Tue, Dec 10, 2002 at 03:38:58PM -0800, Rich Morin wrote:
 On occasion, I have found it useful to cobble up a little language
 that allows me to generate a list of items, using a wild-card or some
 other syntax, as:
 
   foo[0-9][0-9]  yields foo00, foo01, ...
 
 I'm wondering whether Perl should have a similar capability, using REs.


Will Perl6 still have the increment a string ability?  I can't count
the number of times that's been my saving grace when I needed to
portably and easily generate a unique filename.

--Dks



Re: REs as generators

2002-12-11 Thread Damian Conway
Luke Palmer asked:


Can junctions have methods?


If we decide they can, yes. ;-)



How do you tell the difference between calling a junction's method and 
 calling a method on each of its states?

If it's a method of the class Junction (or one of its four subclasses) then it's
a method call on the junction itself.

If it's not defined in the built-in class, then it's a method call distributed
over the states of the junction.

Damian




Re: REs as generators

2002-12-11 Thread Damian Conway
Dave Storrs wrote:

On Tue, Dec 10, 2002 at 10:37:10PM -0700, Luke Palmer wrote:


Why use regexen when you can just use junctions?

   my $foos = 'foo' ~ any(0..9) ~ any(0..9);



At what moment does a junction actually create all of its states?

Hmm...perhaps a clearer way to say that is At what moment does a
junction allocate memory for, and initialize that memory with, all of
its states?


That will have to be done lazily in some cases at least:

	if $input == any(13...);

so maybe it should be done lazily in all cases.




- the ability for the programmer to set limiters (??better name??)
on the junction, which will specify how the junction should
collapse--e.g. always collapse to the lowest/highest value that hasn't
been supplied yet, or to the lowest/highest unsupplied value that
causes a particular code block to return true, or whatever.


Junctions don't collapse. They distribute.

Remember: Junctions Aren't Quantum.

Damian




Re: REs as generators

2002-12-11 Thread Randal L. Schwartz
 Rich == Rich Morin [EMAIL PROTECTED] writes:

Rich On occasion, I have found it useful to cobble up a little language
Rich that allows me to generate a list of items, using a wild-card or some
Rich other syntax, as:

Richfoo[0-9][0-9]  yields foo00, foo01, ...

Rich I'm wondering whether Perl should have a similar capability, using REs.

Well, here's a cheap way:

my @list = glob ('foo{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}');

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Re: REs as generators

2002-12-10 Thread Uri Guttman
 RM == Rich Morin [EMAIL PROTECTED] writes:

  RM On occasion, I have found it useful to cobble up a little language
  RM that allows me to generate a list of items, using a wild-card or some
  RM other syntax, as:

  RMfoo[0-9][0-9]  yields foo00, foo01, ...

  RM I'm wondering whether Perl should have a similar capability, using REs.

the problem is that regexes can be very wide in accepting data but your
needs are narrow. how do you expand . or .*  ?

what you want is more like a macro facility. my favorite macro support
came with macro-11. it had .IRPC (indefinite repeat char) so you could
do this (untested and surely bad syntax :)

.IRPC   $A, 0123456789
.IRPC   $B, 0123456789
.ASCII  'foo$A$B'
.END
.END

there has been debate here about what level of macro support to have. we
can't do lisp's as we don't have easy access to generated code and we
have to be better than cpp which is useless IMO as you don't have nested
calls and loops.

but for stuff like table and data structure building we should have some
way to generate perl source/data with decent control.

uri

-- 
Uri Guttman  --  [EMAIL PROTECTED]   http://www.stemsystems.com
- Stem and Perl Development, Systems Architecture, Design and Coding 
Search or Offer Perl Jobs    http://jobs.perl.org



Re: REs as generators

2002-12-10 Thread Adam Turoff
On Tue, Dec 10, 2002 at 03:38:58PM -0800, Rich Morin wrote:
 On occasion, I have found it useful to cobble up a little language
 that allows me to generate a list of items, using a wild-card or some
 other syntax, as:
 
   foo[0-9][0-9]  yields foo00, foo01, ...
 
 I'm wondering whether Perl should have a similar capability, using REs.

Dominus has an example of an 'odometer' written using closures.  If
you want to specify a simple sequence like this using a regex, then
you need to parse the regex (but in reverse).

Alternatively, you could write a generic odometer generator generator
that takes a series of scalars and lists:

my $generator = make_generator('foo', [0..9], [0..9]);

while ($_ = $generator-()) {
## progressively generate foo00, foo01, ...
}

Z.




Re: REs as generators

2002-12-10 Thread Luke Palmer
 Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
 Date: Tue, 10 Dec 2002 21:07:34 -0500
 From: Adam Turoff [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Content-Disposition: inline
 X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
 
 On Tue, Dec 10, 2002 at 03:38:58PM -0800, Rich Morin wrote:
  On occasion, I have found it useful to cobble up a little language
  that allows me to generate a list of items, using a wild-card or some
  other syntax, as:
  
foo[0-9][0-9]  yields foo00, foo01, ...
  
  I'm wondering whether Perl should have a similar capability, using REs.
 
 Dominus has an example of an 'odometer' written using closures.  If
 you want to specify a simple sequence like this using a regex, then
 you need to parse the regex (but in reverse).
 
 Alternatively, you could write a generic odometer generator generator
 that takes a series of scalars and lists:
 
   my $generator = make_generator('foo', [0..9], [0..9]);
 
   while ($_ = $generator-()) {
   ## progressively generate foo00, foo01, ...
   }
 
 Z.

It only differentiates between arrays an non-, but it would be trivial
to add other semantics, if you figure out what they actually are.

  sub make_generator(*@pats) {
  return unless @pats;
  
  given shift @pats - $pattern { 
  when Array {
  for @$pattern - $item {
  my $generator = make_generator(@pats);
  yield $item ~ $_ for $generator;
  }
  }
  otherwise {
  my $generator = make_generator(@pats);
  yield $pattern ~ $_ for $generator;
  }
  }
  }

You'd use it just like I did in the sub, as an iterator.

This would have been dastardly complex without corouties. :-)

Luke



Re: REs as generators

2002-12-10 Thread Luke Palmer
 Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
 Date: Tue, 10 Dec 2002 15:38:58 -0800
 From: Rich Morin [EMAIL PROTECTED]
 X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/
 
 On occasion, I have found it useful to cobble up a little language
 that allows me to generate a list of items, using a wild-card or some
 other syntax, as:
 
foo[0-9][0-9]  yields foo00, foo01, ...
 
 I'm wondering whether Perl should have a similar capability, using REs.

Why use regexen when you can just use junctions?

my $foos = 'foo' ~ any(0..9) ~ any(0..9);

That's a bit shorter that the code sample I just wrote... not by much
though :-P.  Unfortunately, this one doesn't come in order, but a
Csort should fix that.

We have a Ipowerful language on our hands, people.

Luke



Re: REs as generators

2002-12-10 Thread Uri Guttman
 LP == Luke Palmer [EMAIL PROTECTED] writes:

  LP Why use regexen when you can just use junctions?

  LP my $foos = 'foo' ~ any(0..9) ~ any(0..9);

should that be @foos or will it make an anon list of the foos and store
the ref?

  LP We have a Ipowerful language on our hands, people.

i know but changing my brane to think like that will take some time and
practice. i brought up a macro idea but this is what i wanted to do with
maps or nested loops.

uri

-- 
Uri Guttman  --  [EMAIL PROTECTED]   http://www.stemsystems.com
- Stem and Perl Development, Systems Architecture, Design and Coding 
Search or Offer Perl Jobs    http://jobs.perl.org



Re: REs as generators

2002-12-10 Thread Uri Guttman
 LP == Luke Palmer [EMAIL PROTECTED] writes:

  LP my $foos = 'foo' ~ any(0..9) ~ any(0..9);
   
   should that be @foos or will it make an anon list of the foos and store
   the ref?

  LP Actually $foos will be a junction.  You could use Cstates to get
  LP each state out of the junction in an array.

  LP my @foos = states $foos;

that is going to take a while to become normalized in my neurons. very
useful but not in my vernacular yet.

uri

-- 
Uri Guttman  --  [EMAIL PROTECTED]   http://www.stemsystems.com
- Stem and Perl Development, Systems Architecture, Design and Coding 
Search or Offer Perl Jobs    http://jobs.perl.org