Dimension of slices; scalars versus 1-element arrays?

2005-01-08 Thread Craig DeForest
I just re-read Synopsis 9, which covers PDL-related actions and array slicing, 
and came to the conclusion that either (A) there's a hole in the syntax as it 
is lain out,  (B) I lack sufficient understanding of what has been thought 
out so far, or (C) that part of the language definition isn't finished yet.

Is the perl6 expression
@a[4; 0..5];
a 1x6 array (probably correct)?  Or a 6 array (probably not correct)? If the
former, how do you specify that you want the latter?  There's a significant 
difference between the two -- for example, if '4' is some list expression 
that happens to have just one element, you don't want the whole shape of the 
output array to change.

The problem is the near-universal wart that scalars are not merely lists with 
but a single element, so you need to be able to tell the difference between a 
dimension that exists but has size 1, and a dimension that doesn't exist.
(In perl5, all arrays are one-dimensional, so the issue is sidestepped by the 
presence of scalar/list context.)

Perl5/PDL solves the problem with 'extra-parenthesis' syntax in slicing, and 
with zero-size dimensions in operators like range() [no relation to perl6 
range operators] that take a dimension size list.  Examples:
$a(  4,  0:5 );  # This perl5/PDL slice is a 1x6-array
$a( (4), 0:5 );  # This perl5/PDL slice is a 6-array
$a->range($xy,[1,3]);# This perl5/PDL range is a 1x3-array
$a->range($xy,[0,3]);# This perl5/PDL range is a 3-array
The extra parens only remove the dimension if they would otherwise be no-ops.

It is not (yet) clear to me whether the extra parens syntax is a good solution 
for perl 6 slices.



Re: Possible syntax for code as comment

2005-01-08 Thread Stéphane Payrard
On Fri, Jan 07, 2005 at 09:55:39PM +0100, Juerd wrote:
> Stéphane Payrard skribis 2005-01-07 21:23 (+0100):
> > >  my $s := $subjet;
> > >  my $c := $complement;
> > That's what I wanted to avoid.
> 
> Why? Do you expect to use lots of one letter aliases?
> 
> I think it's one of the most effective ways to kill readability.
> 
> 
> Juerd
> 


The clearly expressed motivation was the Huffman principle. So I certainly
did not imply to use _lots_ of _one_letter_ aliases. The aliases get to
be shorter when they are few and heavily used.

In other words, when some vars heavily used in some portion of code,
it is a win to locally alias them with shorter names. Because they are
few it easy to remember what they denote.  The particular optimal
lengths of these aliases vary on case by case and is also admittedly a
question of taste.

Independantly of aliasing, they are global conventions for the use of
short names, $i or $j is likely to denote an index. Perl helps further
by the use sigil hopefully made consistant in Perl6.

Too long names very often result in folded lines, less code visible in
a screenful. As a result important structural properties of a program often
become invisible.

Anyway the particular length of variables names was not the subject of
my mail,  but a good syntax for aliasing name in signatures.


-- stef



Re: Possible syntax for code as comment

2005-01-08 Thread Ashley Winters
On Sat, 8 Jan 2005 21:05:20 +0100, Stéphane Payrard <[EMAIL PROTECTED]> wrote:
> Anyway the particular length of variables names was not the subject of
> my mail,  but a good syntax for aliasing name in signatures.

Hmm... how about abducting the -> operator and using default variable
initialization? Perhaps we can borrow a page out of the K&R C book.

Lets say I take the -> operator and make it proper in these cases:

sub canon( $subjet, $complement)
-> $s = $subjet{$*Global}, $c = $complement
{
my @foo = ...;
for @foo -> $bar; $remaining = @foo.elems {
# $bar contains an element, $remaining contains the number of
elements in @foo
# or any expression I want, but it's block-scoped here
}
}

How's that?

Ashley