Darren Duncan writes:

> 1. I'm not sure if it is possible yet, but like Haskell et al ..., it
> should be possible to write a Perl 6 routine or program in a pure
> functional notation or paradigm, such that the entire routine body is
> a single expression, but that has named reusable sub-expressions.

I realize it isn't pure functional, but in Perl a C<do> block permits
arbitrary code to be treated as a single expression.  Or to put it
another way round, you can use temporary variables inside the expression
that don't 'leak out' of it.

> For example, in pseudo-code:
> 
>   routine foo ($bar) {
>     return
>       with
>         $bar * 17 -> $baz,
>         $baz - 3 -> $quux,
>         $baz / $quux;
>   }
> 
> This is instead of either of:
> 
>   routine foo ($bar) {
>     return ($bar * 17) / ($bar * 17 - 3);
>   }

That's obviously bad cos of the repetition.

>   routine foo ($bar) {
>     my $baz = $bar * 17;
>     my $quux = $baz - 3;
>     return $baz / $quux;
>   }

But what does a functional form have over that?  Or over the C<do>
version:

  my $whatever
      = do { my $baz = $bar * 17; my $quux = $baz - 3; $baz / $quux };

Sure there are variables.  But in terms of how your brain thinks about
it is it any different from the functional version -- labels being
associated with intermediate parts of the calculation?
    
Smylers

Reply via email to