Re: Factoring Arguments

2007-12-21 Thread Larry Wall
On Fri, Dec 21, 2007 at 08:41:54AM -0800, Jonathan Lang wrote:
: I'm wondering if something similar could be done for optional
: arguments - something along the lines of "within the following block,
: assign value V to argument X of routine R by default."  This would
: allow for a similar "factoring out" of repetitive flags.  So instead
: of:
: 
:   say qq:!c" ... { ... } ...";
:   say qq:!c" ... { ... } ...";
:   say qq:!c" ... { ... } ...";
: 
: and so on, you might do something like:
: 
:   with &qq :(c => false) {
: say "... { ... } ...";
: say "... { ... } ...";
: say "... { ... } ...";
:   }

Hmm, well, qq isn't really a function, it's actually the name of
a sublanguage, as parsed by a macro.

: Or maybe it could be a pragma (which, by definition, lasts only until
: the end of the current scope):
: 
:   {
: use defaults { qq => :!c }
: say "... { ... } ...";
: say "... { ... } ...";
: say "... { ... } ...";
:   }

I like to name pragmas by the construct they're controlling, so if
we took that approach, I'd probably make it something like:

{
use qq ':!c';
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}

: The core concept here is to allow the programmer to easily change the
: default behavior of a routine within a given scope so that he doesn't
: have to repeatedly override the default behavior every time it comes
: up.
: 
: --
: 
: Is this reasonable, or is this too much of a corner case to be worth the 
effort?

Well, sure, but there's really no effort required at all, given you can
already do it (in theory) with:

{
my macro quote:<" "> { 'qq:!c' }
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}

Actually, the "my" is a bit redundant there; syntax changes from
macros are always lexically scoped.  That includes imports of macros,
so if you made a module that contained:

my macro quote:<" "> is export(:DEFAULT) { 'qq:!c' }

then you could use it like this:

{
use Schwernlich;
say "... { ... } ...";
say "... { ... } ...";
say "... { ... } ...";
}

and it would be a lexically scoped language hack.  With a slight
generalization it's the "use qq" pragma above.  Welcome to Perl 6.  :)

Larry


Re: Factoring Arguments

2007-12-21 Thread Juerd Waalboer
Ryan Richter skribis 2007-12-21 11:52 (-0500):
> On Fri, Dec 21, 2007 at 08:41:54AM -0800, Jonathan Lang wrote:
> > and so on, you might do something like:
> >   with &qq :(c => false) {
> I think this can be done with normal currying, something like
> temp &circumfix:<" "> := "e:.assuming(:!c);

Hm, would the following work?

given "e:.assuming(:!c) -> &circumfix:<" "> {
...
}
-- 
Met vriendelijke groet,  Kind regards,  Korajn salutojn,

  Juerd Waalboer:  Perl hacker  <[EMAIL PROTECTED]>  
  Convolution: ICT solutions and consultancy <[EMAIL PROTECTED]>


Re: Factoring Arguments

2007-12-21 Thread Jonathan Lang
Ryan Richter wrote:
> Jonathan Lang wrote:
> > and so on, you might do something like:
> >
> >   with &qq :(c => false) {
>
> I think this can be done with normal currying, something like
>
> temp &circumfix:<" "> := "e:.assuming(:!c);

That handles the specific example that I had in mind, but does so in a
rather brittle way.  First, the programmer is forced to use
double-quotes to make use of the currying; he cannot switch to another
quoting character if one of the strings that he's dealing with has a
number of double-quote characters in it.  This being a
quoting-specific issue, it should be no surprise that it comes with a
quoting-specific solution, e.g., use 'qs' instead of 'qq:!c') - but
that still leaves you with having to prefix every string in the target
scope: c instead of c<" ... ">.  Still, that isn't my main
concern here.

There's no way that I know of to override the currying: every
.assuming that you use removes one parameter from the signature (if I
understand currying correctly).  This means that you don't get to set
assumed values for three different parameters at the start of the
block and then override just one of them for a single use of the
function in the middle of the block.  This concern could probably be
addressed if currying doesn't remove arguments from a signature, but
instead forces them to be optional and assigns default values to them;
but this can lead to its own problems, such as what happens when you
curry the second of three required positional parameters.

What I was thinking of would be somewhat more modest: it would be a
variation on the currying mechanic, but would only apply to optional
parameters.  It wouldn't remove them from the signature at all; it
would merely change the default values assigned to them.

-- 
Jonathan "Dataweaver" Lang


Re: Factoring Arguments

2007-12-21 Thread ajr

>
> A number of languages have a "with ..." construct that's intended to
> cut down on repetitive typing,

I hope I will be excused for dragging in the indecency, but it might be
worth looking at the concepts COBOL used to mitigate its verbosity, (e.g.
types defined in a structure that get inherited by lower levels, unless
specifically over-ridden).

"Those who will not learn from history are bound to repeat it", and a lot
of o-o concepts give me an unpleasant sense of deja vu.


--

Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ippimail.com



Re: Factoring Arguments

2007-12-21 Thread Ryan Richter
On Fri, Dec 21, 2007 at 08:41:54AM -0800, Jonathan Lang wrote:
> and so on, you might do something like:
> 
>   with &qq :(c => false) {

I think this can be done with normal currying, something like

temp &circumfix:<" "> := "e:.assuming(:!c);

-ryan