Dave Whipp wrote:

Something else springs to mind. Consider the C<for> syntax:

  for 1,2,3 ~> foo -> $a { ... }

Is there any way we could unify these two operators without creating
ambiguities? If we
could, then using straight arrows would be nicer to type than the squiggly
ones.
I think I see what you're saying...

$a ~> foo;

calls foo on $a, while

$a -> $x { ... }

um, does nothing... OK, I didn't see what I thought I said.

Actually, I do see something like:

$a ~> -> $x { ... }

as having meaning, namely "call the anon sub with $a as an argument.

Does syntax already exist for doing that? Can one do:

-> $x { ... } ($a);

already?

If not, then the "~> ->" construct has a use, perhaps a semi-common use, and perhaps it should be simplified. Not to suggest another operator here, but "$a ~-> $x { ... }" anyone?

But you were looking for a way to play off their similar meanings to avoid having to use a tilde....

The BNF for anonymous subs is something like (I haven't read the existing grammars, so if I'm not using the standard terms...sorry):

anon_sub :== "sub" block
| "sub" "(" paramlist ")" block
| "->" block
| "->" paramlist block

The BNF for left-to-right pipelines would be something like:

lr_pipe :== lr_pipe "~>" variable
| lr_pipe "~>" function_call

If we were to combine -> and ~>, would it lead to any ambiguity? I'm not sure. Certainly we'd be talking about more than a one-token lookahead.

Actually, I'm not sure the lr_pipe is unambiguous in its own right. I don't have it complete, obviously, but I see problems with the two calls as is...

What is the result of:

$input ~> %functionTable{$state} ~> $state;

Is it equivalent to:

%functionTable($state) = $input;
$state = %functionTable($state);

or

$state = %functionTable($state).($input);

How does the grammar differentiate between the two?

Or would I have to type

$input ~> %functionTable{$state}.() ~> $state;

instead?






Dave.







Reply via email to