That's what I wanted to avoid.
>
> : # or without type annotation
> : sub canon( Expr $subjet as $s , Expr $complement as $c) { }
>
> If we put syntactic relief into the signature, it'd probably work the
> other way around, where the descriptive parameter name is the optional thing:
>
> sub canon( Expr $s is named<subjet>, Expr $c is named<complement>) { }
>
> That way the sigil is on the variable, and not on the parameter name that
> you'd use in a named call:
>
> canon( subjet => $mysub, complement => $mycomp );
> canon( :subjet($mysub) :complement($mycomp) );
I suppose you meant
canon( :subjet($mysub), :complement($mycomp) );
>
> We could conceivably allow a declarational notation like:
>
> sub canon( subjet => Expr $s, complement => Expr $c) { }
I keep forgeting about pairs as named arguments and focused only on
subs signature syntax and omitted the call syntax. Subs are defined
once, but usually called many times, so this call syntax matters even
much. It is great that, in calling code, one can use the pair syntax
to remind the reader what argument is what for a given sub but then
use the positional notation:
...
canon :subjet($mysub) :complement($mycomp);
canon $mysub2, $mycomp2;
canon $mysub3, $mycomp3;
...
btw, are the parentheses mandatory in the alternative pair syntax? If
the value is simple to write, I would like to drop the parentheses:
canon :subjet $mysub, :complement $mycomp;
This would happen if a key with colon bind very tightly.
I love Perl6 syntax. Larry, you should post more sample code so that
people get familiar with that syntax. It is easier to learn by example
than by reading manuals. I loved Perl4 syntax but it got ugly with
the introduction of references in Perl5. It is about time that Perl
stops getting a bad rap about being write-only.
--
stef
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 comma is optional between those kinds of pairs.
> btw, are the parentheses mandatory in the alternative pair syntax? If
> the value is simple to write, I would like to drop the parentheses:
>
> canon :subjet $mysub, :complement $mycomp;
>
> This would happen if a key with colon bind very tightly.
Yeah, because a plain old :subjet means the same thing as :subjet(1).
Because of that, if we allow omission of the parentheses, we get
term/operator duality. And we don't have quantum computers yet. %-)
If you don't want to write parentheses, why don't you just use the other
pair notation:
canon subjet => $mysub, complement => $mycomp;
> I love Perl6 syntax. Larry, you should post more sample code so that
> people get familiar with that syntax. It is easier to learn by example
> than by reading manuals. I loved Perl4 syntax but it got ugly with
> the introduction of references in Perl5. It is about time that Perl
> stops getting a bad rap about being write-only.
Well, it'll still get that bad rap because it's as syntactically
flexible as ever (moreso even), so people have all the freedom they want
to write code ugly as sin.
Anyway, if you want to see more Perl 6 syntax, why don't you post some
"how do I"s to the list, and I'll reply with code.
Luke
>Well, it'll still get that bad rap because it's as syntactically
>flexible as ever (moreso even), so people have all the freedom they want
>to write code ugly as sin.
>
>Anyway, if you want to see more Perl 6 syntax, why don't you post some
>"how do I"s to the list, and I'll reply with code.
>
>
How do I concisely code a loop that reads in lines of a file, then calls
mysub() on each letter in each line?
Or each xml tag on the line?
(This came up as I was praising the name of Palmer for the "outer"
operation...)
=Austin
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.9 - Release Date: 1/6/2005
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
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
Out of curiosity, why are we all spelling 'subject' without a 'c'?
Or is 'subjet' a word I'm not familiar with? (Honest question.)
As to the meat of the proposal...I would rather that the aliasing was
done as part of the signature, not afterwards. Keep all the
information that pertains to this parameter in one location.
--Dks
--
dst...@dstorrs.com
I assume it's a spelling error on the part of the original poster.
French for "subject" is "sujet" (IIRC), and "subjet" looks like a cross
between the two.
Luke
I know how to spell "subject" in English. That was a typo. But
certainly, it did not trigger an alarm in my mind. When needed, I can
think and write in (broken) Englisn. But somehow my French sometimes
partly takes over.
French for "subject" is "sujet" and it has the same meanings as in English.
Once, the Sun-King Louis XIV, asked for a "bon mot". He was answered
"Mais sire, vous n'ętes pas sujet". That gives in English: "But
Majesty, you are not a subject". It is pretty rare that a pun can
survive translation.
--
stef