develooper Front page | perl.perl6.language | Postings from May 2003

Re: S6: Change in if syntax?

Thread Previous | Thread Next
From:
Piers Cawley
Date:
May 5, 2003 06:14
Subject:
Re: S6: Change in if syntax?
Message ID:
m2k7d51qo9.fsf@TiBook.bofh.org.uk
arcadi shehter <fearcadi@figaro.weizmann.ac.il> writes:

> I was reading 
> http://www.linux-mag.com/downloads/2003-04/perl6/03.04.perl6.2.txt
> and in particular , this 
>
> print -sum(@probs >>*<< >>log<<(@probs))/log(2);
>
> And I have several questions 
>
> * are all these are correct ( and equivalent ) ?
>
> @y = >>log<< @x    # (1)
> @y = >>log<<(@x)   # (2)
> @y = >>log<< .(@x) # (3)
> @y = log >>.<< (@x)# (4)
> @y = log >>.(@x)<< # (5) wild and probably wrong guess   
>
> it seems that there is no way to insert space between vectorized sub
> and its argument if only 2 is OK. 
>
> But log is unary operator so probably (1) and (2) apply to it for that 
> reason . 

Personally I'd argue that you should only be able to vectorize
things that are used in 'operator form'. So I'd say that only 1 and
2 are definitely legal. I'm wary of >>.<< being considered legal
syntax though.

> What if I have a sub accepting 2 scalar args 
>
> sub pow($base , $exp=2) {...}
>
> will both these work ?: 
>
> #list of squares 
> @y = >>pow<<(@base,$exp)   
>  #or:
> @y =   pow >>.<< (@base,$exp)
>
>
> #list of powers 
> @y = >>pow<<($base,@exp)   

I would hope not. But:

  @y = >>pow.assuming(exp => $exp)<<(@base);

and

  @y = >>pow.assuming(base => $base)<<(@exp)

should work...

> Also : 
> is these equivalent to @c = @a >>+<< @b  :
>
> @c = >>infix:+<< (@a,@b)  
>
> 			   or it should be 
>
> @c = >>infix:+<< .(@a,@b)  
>
> 			   or it should be 
>
> @c = infix:>>+<< .(@a,@b)  

Ick... I haven't a clue. The infix:>>+<< option looks the most
promising though, since it implies that one could write:

multi infix:+ ($a, $b) {...}
multi infix:>>+<< ($a, @b) {...}
multi infix:>>+<< (@a, $b) {...}
multi infix:>>+<< (@a, @a) {...}

But I'm not sure either way here, after all, in most cases you could
probably abstract out the vectorizing behaviour:

multi outfix:>><< (&op, $arg) { &op($arg) }
multi outfix:>><< (&op, @arg) { map {&op($_)} @arg }
multi outfix:>><< (&op, $a1, @a2) { map { &op($a1, $_) } @a2 }
...

Hmm... I'm pretty sure those signatures are wrong though...


-- 
Piers

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About