Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Quick question: parens vs subroutine parameter

2 views
Skip to first unread message

Larry Wall

unread,
Apr 20, 2005, 4:30:38 PM4/20/05
to perl6-l...@perl.org
On Wed, Apr 20, 2005 at 10:23:14PM +0200, Juerd wrote:
: Autrijus Tang skribis 2005-04-21 4:19 (+0800):
: > So, following up on the Parens handling, are these two equivalent?
: > # Assuming &is has the parameter signature (Str, Str, Str)
: > is((1,2), (3,4), "hey");
: > is([1,2], [3,4], "hey");
:
: I think so.
:
: > What happens if &is is of type (Any, Any, Str)?
:
: Same thing, as the inner comma is still in scalar context.
:
: However, with list context, I expect things to flatten, so with a
: signature of *@_, it puts 5 elements in @_.

That's all correct.

Larry

Juerd

unread,
Apr 20, 2005, 4:23:14 PM4/20/05
to Autrijus Tang, perl6-l...@perl.org
Autrijus Tang skribis 2005-04-21 4:19 (+0800):
> So, following up on the Parens handling, are these two equivalent?
> # Assuming &is has the parameter signature (Str, Str, Str)
> is((1,2), (3,4), "hey");
> is([1,2], [3,4], "hey");

I think so.

> What happens if &is is of type (Any, Any, Str)?

Same thing, as the inner comma is still in scalar context.

However, with list context, I expect things to flatten, so with a
signature of *@_, it puts 5 elements in @_.


Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html

Autrijus Tang

unread,
Apr 20, 2005, 4:19:51 PM4/20/05
to perl6-l...@perl.org
So, following up on the Parens handling, are these two equivalent?

# Assuming &is has the parameter signature (Str, Str, Str)
is((1,2), (3,4), "hey");
is([1,2], [3,4], "hey");

What happens if &is is of type (Any, Any, Str)?

Thanks,
/Autrijus/

Juerd

unread,
Apr 20, 2005, 5:28:23 PM4/20/05
to Autrijus Tang, perl6-l...@perl.org
Autrijus asked me to summarize here what I said on IRC #perl6, and ask
Larry for another "that's all correct".

I've rephrased everything as facts/assumptions.

Array context, as provided by a signature of "Array $foo", is still
a form of scalar context, even though Array.isa(List).

Array is a class here.

Classes when used for context expect objects.

Objects are references.

Array implies ref.

The main contexts, void, scalar and list, have nothing to do with
types.

Scalar context can expect a certain type of value, for example, an
Array or a Dog.

List context can also expect a certain type of values for its
elements.

Somewhere during our conversation, I suggested renaming scalar and list
context to singular and plural context, to avoid all the confusion.

Void context still exists and is not a form of singular or plural
context. Perhaps this should be called nullar context, although void
context works equally well for me and is not confusing because we have
no Void type.

When we really want a scalar (the thing itself), we call that Any
context or Scalar context, both forms of singular context (formerly
called scalar context).

What exactly is the difference between Scalar and Any?

Larry Wall

unread,
Apr 20, 2005, 9:26:08 PM4/20/05
to perl6-l...@perl.org
On Wed, Apr 20, 2005 at 11:28:23PM +0200, Juerd wrote:
: Autrijus asked me to summarize here what I said on IRC #perl6, and ask

: Larry for another "that's all correct".
:
: I've rephrased everything as facts/assumptions.
:
: Array context, as provided by a signature of "Array $foo", is still
: a form of scalar context, even though Array.isa(List).

I don't think Array.isa(List). I think List.isa(Array of Generator),
and Array.maybehasa(List) stored under it's .specs property for generating
more values of the Array if you run off the end of the existing elements.

: Array is a class here.

Yes.

: Classes when used for context expect objects.

If by "context" you mean variable declaration, then yes.

: Objects are references.

Objects are blessed referents, just as in Perl 5. It's just that most
such referents are an opaque type now. I think what you're trying
to say here is that Real Objects™ are never value types, which is true.
Objects are always accessed through references, as in Perl 5.

: Array implies ref.

Yes, though people don't have to realize that when they say @foo[$bar].

: The main contexts, void, scalar and list, have nothing to do with
: types.

That's a slight overstatement, but mostly true.

: Scalar context can expect a certain type of value, for example, an
: Array or a Dog.

Yes.

: List context can also expect a certain type of values for its
: elements.

Right.

: Somewhere during our conversation, I suggested renaming scalar and list


: context to singular and plural context, to avoid all the confusion.

I often talk about them in those terms, but I'd hate to have to type
"singular" instead of "scalar" or "plural" instead of "list" all the time.

: Void context still exists and is not a form of singular or plural


: context. Perhaps this should be called nullar context, although void
: context works equally well for me and is not confusing because we have
: no Void type.

So let's get just rid of Scalar and List types.

: When we really want a scalar (the thing itself), we call that Any


: context or Scalar context, both forms of singular context (formerly
: called scalar context).
:
: What exactly is the difference between Scalar and Any?

Isn't any, that I can tell. So maybe we settle on Any for the type
and scalar() for the function/concept. It'd be nice if we could
unify those somehow, but any() is taken. Maybe Item/item().

Likewise, there's really no such thing as a List. The basic list types
are actually Eager and Lazy, and an Array conveniently contains one of each.

Larry

"TSa (Thomas Sandlaß)"

unread,
May 13, 2005, 1:13:53 PM5/13/05
to perl6-l...@perl.org
Larry Wall wrote:
> : Void context still exists and is not a form of singular or plural
> : context. Perhaps this should be called nullar context, although void
> : context works equally well for me and is not confusing because we have
> : no Void type.

Nice, without Void we don't need the double headed
pseudo type lattice needed if we were to distinguish
subs that return no usefull---that is Any---value
from the ones that return no value at all.


> So let's get just rid of Scalar and List types.

How does that go with the distinction between the container
and content type/class? Are all variables then implemented
with Parrot level refs/pointers/PMCs and there is no need for
a single element container class? Actually I would appreciate
this.

With the idea of the Perl6 type system having a type lattice
and | meaning LUB (lowest upper bound) the apex of which would
be Any.

::Any ::= Str | Num | Ref of Any | Array of Any | Hash of Any | ...

The ... is dynamically updated whenever a new toplevel type
is added: Any ::= Any | TheNewType.

How do we name the bottom Type? None? All? The latter would
nicely relate it to the & as the GLB (greatest lower bound).
But OTOH, None feels more natural and is e.g. used by the
Cecil folks as well.


> : When we really want a scalar (the thing itself), we call that Any
> : context or Scalar context, both forms of singular context (formerly
> : called scalar context).

BTW, context is not meaningfull at runtime but only defines what
code the compiler generates? E.g. list context would be compiled
to some code that gathers the values from the involved expressions,
subs and constants---into what? An Array?


> : What exactly is the difference between Scalar and Any?
> Isn't any, that I can tell. So maybe we settle on Any for the type
> and scalar() for the function/concept.

> It'd be nice if we could
> unify those somehow, but any() is taken. Maybe Item/item().

Just ideas from me for:
no value: void, zero
one value: mono, unary
>1 value: poly, many
--
TSa (Thomas Sandlaß)

Rod Adams

unread,
May 13, 2005, 8:31:23 PM5/13/05
to perl6-l...@perl.org
Autrijus Tang wrote:

>On Fri, May 13, 2005 at 07:13:53PM +0200, "TSa (Thomas Sandlaß)" wrote:
>
>
>>Larry Wall wrote:
>>
>>
>>>: Void context still exists and is not a form of singular or plural
>>>: context. Perhaps this should be called nullar context, although void
>>>: context works equally well for me and is not confusing because we have
>>>: no Void type.
>>>
>>>
>>Nice, without Void we don't need the double headed
>>pseudo type lattice needed if we were to distinguish
>>subs that return no usefull---that is Any---value
>>from the ones that return no value at all.
>>
>>
>

>Hrm. So if I have a sub that does nothing:
>
> sub Foo { }
>
>Is it illegal to say this?
>
> sub Foo returns Void { }
>
>

Can't we just say :

Void =:= none(Any)

and get Void for near free?

-- Rod Adams

Autrijus Tang

unread,
May 13, 2005, 8:20:06 PM5/13/05
to "TSa (Thomas Sandlaß)", perl6-l...@perl.org
On Fri, May 13, 2005 at 07:13:53PM +0200, "TSa (Thomas Sandlaß)" wrote:
> Larry Wall wrote:
> >: Void context still exists and is not a form of singular or plural
> >: context. Perhaps this should be called nullar context, although void
> >: context works equally well for me and is not confusing because we have
> >: no Void type.
>
> Nice, without Void we don't need the double headed
> pseudo type lattice needed if we were to distinguish
> subs that return no usefull---that is Any---value
> from the ones that return no value at all.

Hrm. So if I have a sub that does nothing:

sub Foo { }

Is it illegal to say this?

sub Foo returns Void { }

What about:

sub Foo returns :() { }

Or do I really need to convert it to this?

sub Foo returns Any { }

Thanks,
/Autrijus/

0 new messages