Re: Perl 6 regexes... (fwd)

2002-08-12 Thread Sean O'Rourke

What Dan says.  If you're interested, there are at least three options:

- a fairly well-developed compiler for perl 5 regexes (languages/regex).

- a less well-developed compiler built into the prototype Perl 6 compiler
  (languages/perl6)

- a set of regex ops in rx.ops, suitable for starting your own
  implementation from scratch.

Since I'm working on #2, I'd of course most appreciate help on that ;).
It unfortunately relies on a couple of other miscellaneous enhancements
that haven't made it into CVS.  If you're interested in taking a look
before it gets into CVS, email me and I'll send you the duct tape I'm
using to hold it together now.

/s

-- Forwarded message --
Date: Mon, 12 Aug 2002 03:00:27 -0400
From: Dan Sugalski <[EMAIL PROTECTED]>
To: Sean O'Rourke <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Subject: Re: Perl 6 regexes...

At 10:01 PM -0700 8/11/02, Sean O'Rourke wrote:
>Working on it.  I've got greedy quantifiers (including <$n,$m>),
>interpolated arrays and scalars, enumerated character classes, code
>assertions, embedded blocks.  It's all static, so runtime-compiled regexes
>aren't going in.  Hypotheticals will be hard, but should be doable.  Same
>with the various cut operators ("::").

Yow. Cool. Pop a note to perl6-language if you want, to see about
grabbing some folks to help out.

>On Mon, 12 Aug 2002, Dan Sugalski wrote:
>
>>  Well, we've got a pretty good description of perl 6's regexes
>>  courtesy of A5. Anyone care to take a shot at either modifying the
>  > regex compiler to deal with them, or writing a perl 6 regex compiler?

-- 
 Dan

--"it's like this"---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
   teddy bears get drunk




Re: 'while <> {' in Perl 6

2002-08-12 Thread [EMAIL PROTECTED]

From: Larry Wall [EMAIL PROTECTED]
> (Had an interesting typo there.  I put => insteaqd of ->.  
> I wonder how much trouble that sort of thing is gonna cause.
> Maybe pairs can be disallowed or warned about where a pointy
> sub might be expected.)

I foresee a lot of problems.  To my Perl5 eyes, -> means "a property or
method will be next" while => means "maps to".  Indeed, 25% of my brain
thinks that -> ought to be switched to => because "maps to" is already
pretty close to the new intended meaning.  => as a pair creator doesn't
make a lot of sense in that context anyway, so there's no ambiguity.  (45%
of my brain says that => now creates a pair object so yes in fact it *is*
ambiguous, 25% says to Just Trust Larry, and 5% is busy craving a latte).

Question: if the compiler *doesn't* raise an error, what happens? How would
the following code be interpreted, even insanely?  An endless loop perhaps?

  while something() => $_ { ... }

-Miko



mail2web - Check your email from the web at
http://mail2web.com/ .





Re: A Perl 6 class question

2002-08-12 Thread Allison Randal

On Fri, Aug 09, 2002 at 03:09:29PM -0400, Chris Dutton wrote:
> 
> This one actually came to me just the other night.  Would it be possible 
> in Perl 6 to create "anonymous classes"?  Something like:
> 
> my $foo_class = class {
>   method new {
>   # yada yada yada
>   }
> }
> 
> my $foo_obj = $foo_class.new;

Yup. Reread the section of Exegesis 4 on "Lexical Exceptions". You even
got the exact syntax (always a nice confirmation of how natural it is :).

Allison



Re: A Perl 6 class question

2002-08-12 Thread Trey Harris

Another one...

class Foo is Bar;

method a {
  setup();
}

1;
# EOF

(Is the 1 still required?  I think I heard Damian say it was going away.)

The question is, is this valid, if Bar defines a sub/static method
'setup'?

Is my instict right that 'sub' in a class is a 'class/static method' in
the terminology of other languages?

I'm wondering if the oddly redundant syntax we have now of:

package Foo;
use Bar;
our @ISA = qw(Bar);
sub a {
   my $self = shift;
   Bar::setup();
}
1;

Can go away.

Trey




Re: 'while <> {' in Perl 6

2002-08-12 Thread Leopold Toetsch

[EMAIL PROTECTED] wrote:


> Question: if the compiler *doesn't* raise an error, what happens? How would
> the following code be interpreted, even insanely?  An endless loop perhaps?
> 
>   while something() => $_ { ... }


Changing the closure to use »=>« instead of »->« yields with current P6C:

Can't locate object method "ctx_right" via package "P6C::pair" at \

P6C/Addcontext.pm line 678.   


So the pair syntax comes in, which is not much surprising, pair is very 
high in precedence.


> -Miko

leo





Re: A Perl 6 class question

2002-08-12 Thread Allison Randal

On Sat, Aug 10, 2002 at 07:30:19PM -0400, Chris Dutton wrote:
> 
> The only problem I could see, and I wanted to wait for at least one 
> other opinion before mentioning this, is rewriting the above as:
> 
> my $foo_class $foo_obj = $foo_class.new;

I'm not exactly sure what you're trying to do with this. You can create
an object within the same statement as you define the class:

my $foo_obj = class {
method new {
# yada yada yada
}
}.new;

> Still I can see this as occasionally being useful for having instance 
> variables which can effectively be initialized, but afterwards are 
> constant.  Then again, there's probably another, more graceful way to do 
> this using the new method and properties.
> 
> sub foo(int $bar //= 0) {
>   return class {
>   int $.baz is constant = $bar;
>   method out(int $multiply_by //= 1) {
>   print $.baz * $multiply_by, "\n";
>   }
>   }
> }
> 
> foo(5).new.out(2); # 10
> foo(6).new.out(3); # 18

As it stands, you're not gaining anything over:

sub foo(int $bar //= 0, int $multiply_by //= 1) {
print $bar * $multiply_by, "\n";
}

foo(5,2);

I'll tease out the various threads there. Keep in mind that the new OO
syntax is only partially defined at this point. Yes, you will be able to
return an anonymous class. Yes, it will be lexically scoped to the
context in which it was defined, so it will have access to $bar. Yes,
attributes can have properties attached, and I imagine C
will be one of the acceptable properties. I also imagine attributes will
have the option of being initialized using assignment-style (C<=>)
syntax. I also imagine that attributes will be able to be typed. The
current consensus on attribute declaration is to use this syntax:

attr $.baz;

(i.e. C, not C or C)
Or in your case:

attr int $.baz is constant = $bar;



> foo(5).new.out(2); # 10

I suspect this will be allowable syntax. But if you find yourself using
it you might want to re-think the code. Creating a class and an object
for single use isn't tremendously efficient. Then again, you may be
golfing. :)

Allison



RE: Regular and Context-Free languages

2002-08-12 Thread Thom Boyer

Steve Find said on August 09, 2002 6:24 PM:
>Anyone happen to know where pushdown automata fit in this list? Can
>they handle context-sensitive, just context-free, or some other
>subset?

Mark Reed said on August 09, 2002 7:60 PM:
>To recognize a context-sensitive language I think you need a Turing
>machine.  I'm not aware of anything intermediate in power between
>a PDA and a TM.

A regular expression is equivalent to an FSM 
  (Finite State Machine).
A context-free grammar is equivalent to a PDA 
  (Push-down Automata -- i.e., an FSM with a stack)
A context-sensitive grammars is equivalent to an LBA 
  (Linear Bounded Automata -- i.e., a Turing machine restricted 
  to a given finite length of tape)
An unrestricted grammar is equivalent to a TM 
  (Turing Machine).

[info from _Introduction_to_Automata_Theory,_Languages,_and_Computation_,
John E. Hopcroft and Jeffrey D. Ullman]



Re: A Perl 6 class question

2002-08-12 Thread Chris Dutton

On Monday, August 12, 2002, at 01:27 PM, Allison Randal wrote:

> On Sat, Aug 10, 2002 at 07:30:19PM -0400, Chris Dutton wrote:
>>
>> The only problem I could see, and I wanted to wait for at least one
>> other opinion before mentioning this, is rewriting the above as:
>>
>> my $foo_class $foo_obj = $foo_class.new;
>
> I'm not exactly sure what you're trying to do with this.

Sort of like:

class A { ... }
my A $a = A.new;

Where A is $foo_class.  Probably not terribly useful, but I just 
wondered if it'd work anyway.

>  You can create
> an object within the same statement as you define the class:
>
> my $foo_obj = class {
> method new {
> # yada yada yada
> }
> }.new;

I figured that would work, but wasn't entirely sure.  Thanks.

>> sub foo(int $bar //= 0) {
>>  return class {
>>  int $.baz is constant = $bar;
>>  method out(int $multiply_by //= 1) {
>>  print $.baz * $multiply_by, "\n";
>>  }
>>  }
>> }
>>
>> foo(5).new.out(2); # 10
>> foo(6).new.out(3); # 18
>
> As it stands, you're not gaining anything over:
>
> sub foo(int $bar //= 0, int $multiply_by //= 1) {
> print $bar * $multiply_by, "\n";
> }
>
> foo(5,2);

Granted, it was a trivial example.  :-)

>   attr int $.baz is constant = $bar;

I like it.

>> foo(5).new.out(2); # 10
>
> I suspect this will be allowable syntax. But if you find yourself using
> it you might want to re-think the code. Creating a class and an object
> for single use isn't tremendously efficient. Then again, you may be
> golfing. :)

Hmmm  could I have instead written the following and ended up with 
both a lexically scoped anonymous class($fc), and an instance($fo)?

( my $fo = ( my $fc = foo(5) ).new ).out;

One thing is obvious... it's been way too long since I read the various 
Exegesis documents.