A proposal for separable verbs. (Was: Re: A proposal on if and else)

2003-01-20 Thread Austin Hastings

--- Joseph F. Ryan [EMAIL PROTECTED] wrote:
 If the final design stays the way it is now, there really won't be
 a lexer.  Instead, a perl6 grammar parses the data, and builds up
 a huge match-object as it, well, matches.  This match object is then
 munged into the optree.
 

With this in mind, I'll say it again:

Let's support separable verbs. 

Here's how:

# Note my arbitrary selection of _ as separation indicator. Feel free
to replace this with something more appropriate:

sub if($test, block) 
  _ elsif ($test, block) is optional is floating is multi
  _ elsunless ($test, block) is optional is floating is multi
  _ else (block) is optional is fixed
{
  while (!$args[0].test) shift;
  args[0].block();
}

Where:

1: I'm hacking real hard on the implementation. Better Ideas Welcome.
2: space-underscore-space means separable bit. Negotiable. BIW.
3: is optional/[dflt: required] means doesn't have to appear.
4: is floating/[dflt: fixed] means can appear in any order.
5: is multi/[dflt: single] means can appear more than once.

The last three (3, 4, 5) are really just match-hints to the rexer for
here's how to look for me:

/if arg-bits 
  ((elsif arg-bits | elsunless arg-bits)*)
  (else arg-bits)?/

Instead of, say, requiring all the elsif in front of all the elsunless,
or whatever.

I think this is one of those p6-ish generalizations:

try/catch/finally
do/while
if/elsif/elsunless/else
repeat/until
(arguably: switch/case/default)

are all just separable verbs:

sub try (block)
  _ catch ($e, block) is optional is multi is fixed
  _ finally (block) is optional is fixed;

sub do (block)
  _ while ($cond); # is single is fixed is required

sub repeat (block)
  _ until ($cond); # is single is fixed is required

sub switch ($cond)
  _ case ($val, block) is multi is required
  _ default (block) is optional;

(Note: This leaves switch statements looking like crap, so I'd really
rather sugar them up. But the point is, you *could* to it that way.)

switch ($x)
case (10) { print 10; }
case (11) { print 11; }
default   { print Something else; }

=Austin







RE: A proposal for separable verbs. (Was: Re: A proposal on if and else)

2003-01-20 Thread Brent Dax
Austin Hastings:
# Let's support separable verbs. 
# 
# Here's how:
# 
# # Note my arbitrary selection of _ as separation indicator. 
# Feel free to replace this with something more appropriate:
# 
# sub if($test, block) 
#   _ elsif ($test, block) is optional is floating is multi
#   _ elsunless ($test, block) is optional is floating is multi
#   _ else (block) is optional is fixed

How do you name one of these suckers?

%::{'if'}   #Incomplete, and is there an %::{'elsif'}?
%::{'if_elsif_elsunless_else'}  #Could conflict with other symbols
%::{'if _ elsif _ elsunless _ else'}#Depends on ordering

Remember, this also has bearing on importing them from a module.

# {
#   while (!$args[0].test) shift;

1. Where did this $args come from?
2. The while syntax is way wrong.
3. How does else's test default to 1?

#   args[0].block();

From this, it's obvious you forgot about sigil invariance.

# }
# 
# Where:
# 
# 1: I'm hacking real hard on the implementation. Better Ideas Welcome.
# 2: space-underscore-space means separable bit. Negotiable. BIW.
# 3: is optional/[dflt: required] means doesn't have to appear.
# 4: is floating/[dflt: fixed] means can appear in any order.
# 5: is multi/[dflt: single] means can appear more than once.

5 conflicts with multimethods.

# I think this is one of those p6-ish generalizations:
# 
# try/catch/finally
# do/while
# if/elsif/elsunless/else
# repeat/until
# (arguably: switch/case/default)

Except that none of the other ones exist in Perl 6.  :^)

try {
...
CATCH {
...
}
}

loop {
...
last unless cond;
}

loop {
...
last if cond;
}

given(topic) {
when cond {
...
}

default {

}
}

IMHO, separable keywords are in general a bad design, so perhaps they
should be grammar-munge hard.  We really don't need anything but else
(and possibly its friends) for our purposes, but we want them
everywhere, so I don't see why we shouldn't do it this way.

--Brent Dax [EMAIL PROTECTED]
@roles=map {Parrot $_} qw(embedding regexen Configure)

How do you test this 'God' to prove it is who it says it is?
If you're God, you know exactly what it would take to convince me. Do
that.
--Marc Fleury on alt.atheism




RE: A proposal for separable verbs. (Was: Re: A proposal on if and else)

2003-01-20 Thread Austin Hastings
--- Brent Dax [EMAIL PROTECTED] wrote:
 Austin Hastings:
 # Let's support separable verbs. 
 # 
 # Here's how:
 # 
 # # Note my arbitrary selection of _ as separation indicator. 
 # Feel free to replace this with something more appropriate:
 # 
 # sub if($test, block) 
 #   _ elsif ($test, block) is optional is floating is multi
 #   _ elsunless ($test, block) is optional is floating is multi
 #   _ else (block) is optional is fixed
 
 How do you name one of these suckers?
 
 %::{'if'} #Incomplete, and is there an %::{'elsif'}?
 %::{'if_elsif_elsunless_else'}#Could conflict with other symbols
 %::{'if _ elsif _ elsunless _ else'}  #Depends on ordering
 
 Remember, this also has bearing on importing them from a module.
 

Full name, with full signature. if_elsif_elsunless_else($c,b,$c,b,
$c, b, b);

Maybe a special widget in the arglist to denote separability? This
could be important for varargs multimethods.

 # {
 #   while (!$args[0].test) shift;
 
 1. Where did this $args come from?
 2. The while syntax is way wrong.
 3. How does else's test default to 1?
 
 #   args[0].block();
 
 From this, it's obvious you forgot about sigil invariance.

I can't even spell sigil invariance. And I'm nowhere close to sure that
it would be valid to use while when in the middle of trying to define
if. 

I was backfilling the innards after writing the 'outards'. Just a
competence fault on my part.

 
 # }
 # 
 # Where:
 # 
 # 1: I'm hacking real hard on the implementation. Better Ideas
 Welcome.
 # 2: space-underscore-space means separable bit. Negotiable. BIW.
 # 3: is optional/[dflt: required] means doesn't have to appear.
 # 4: is floating/[dflt: fixed] means can appear in any order.
 # 5: is multi/[dflt: single] means can appear more than once.
 
 5 conflicts with multimethods.

s/multi/repeatable/ or whatever. BIW.

 
 # I think this is one of those p6-ish generalizations:
 # 
 # try/catch/finally
 # do/while
 # if/elsif/elsunless/else
 # repeat/until
 # (arguably: switch/case/default)
 
 Except that none of the other ones exist in Perl 6.  :^)

Because we have not heretofore had a cool syntax for separable verbs.
Now we do. Now it can be possible to say use pascal; and get extra
syntax overhead. Rejoice. :-/

 
   try {
   ...
   CATCH {
   ...
   }
   }
 
   loop {
   ...
   last unless cond;
   }
 
   loop {
   ...
   last if cond;
   }
 
   given(topic) {
   when cond {
   ...
   }
   
   default {
   
   }
   }
 
 IMHO, separable keywords are in general a bad design, so perhaps they
 should be grammar-munge hard.  We really don't need anything but else
 (and possibly its friends) for our purposes, but we want them
 everywhere, so I don't see why we shouldn't do it this way.

Go us. One step closer to total world domination.

=Austin




Re: A proposal for separable verbs. (Was: Re: A proposal on if and else)

2003-01-20 Thread Simon Cozens
[EMAIL PROTECTED] (Austin Hastings) writes:
 Let's support separable verbs. 

That (http://dev.perl.org/perl6/rfc/309.html) is a really good idea.

-- 
Writing software is more fun than working.