On Sat, Oct 06, 2007 at 04:00:18PM -0500, brian d foy wrote:
: This is basically the same question I had about file test operators
: earlier
: (http://www.nntp.perl.org/group/perl.perl6.language/2007/04/msg27415.htm
: l). I never got an answer on my syntax question and the discussion went
: off to talk about file tests instead of pair notation. 

Sorry, keep meaning to answer things and then get distracted.  It's only
been, what, two months since you sent this message...  :)

: >From S02 "The general radix form of a number involves prefixing with
: the radix in adverbial form".
: 
: This seems to say that there are non-general radix forms, and that
: those might involve a different radix form that's not adverbial.

Nope, anything else is just a function/method call.

: Later in the "Literals" section of S02, there's a chart of the
: corresponding forms for fat arrow, pair, and paren notation. It has
: 
:    a => 'foo'      :a<foo>      :a(<foo>)
: 
: That looks like it might mean that these are corresponding forms:
: 
:    8 => 377    :8<377>    :8(377)

The first is just a pair of 8 and 377, and has no special numeric
significance.  The adverbial syntax is special in that, for ordinary
pairs, what follows the colon must be an identifier, so :8<377>
would ordinarily be illegal.  And because it would be illegal, we
can just reuse that syntax for an easy way to write radix literals.

It happens to fall out from this that the parenthetical form (which
allows an arbitrary expression returning a string instead of a literal
string) gives us a way to get rid of the badly named "hex" and "oct"
functions, which are bass-ackwards from the usual conversion functions
in that they name the input rather than the output.

The :8(377) above is a bit wrong, by the way, and works only because
decimal 377 happens to stringify to something that looks like an
octal number.  You couldn't, for instance, say :16(deadbeef) unless
deadbeef() was a 0-ary (or listop with no args) function returning
a hex string.

: Now, if I can do that, what happens to the pair form in a hash composer
: when I want the key of '8' and the value of :10<377>?

The situation doesn't arise, since you can't create a pair starting
with :8 anyway.

: Also, going a bit further, the table lists
: 
:    a => <foo bar>      :a<foo bar>      :a(<foo bar>)
: 
: So can I do things like
: 
:    255 => <10 1 0 6>;  # hey, that looks like an IP address

That's just a pair equivalent to 255 => (10,1,0,6), which promotes
to 255 => [10,1,0,6] because => is scalar context on both sides.
The construct has no numeric significance in terms of radix.

:    :255<10 1 0 6>; # is that the same as :255[ 10,1,0,6 ] ?

Unspecced, but yes, that would probably be allowable if we force
:255{10,1,0,6} to mean the same as :255[10,1,0,6].

Except, if you were really trying to generate an IPv4 address, I'd
suggest using :256 instead.  :)

: And, if that works, what might this do? 
: 
:    q:w:255<10 1 0 6>

That would almost certainly be illegal syntactically on the face of it,
since the quote syntax doesn't know :255, and the quote syntax must
understand its options at compile time because that may influence how
the quoted string will be parsed.

If passed to an ordinary function where a term is expected, it's just
a literal number term.  If passed adverbially where an operator is
expected, it's likely to fail at compile time as "two terms in a row",
and if somehow it got past that, it'd attempt to bind to an optional
parameter named 255, which you can't declare, so it fails.  Anyway,
it's gonna blow up one way or another.  I guarantee it.  :)

Larry

Reply via email to