Re: How do you call the variable types?

2017-06-16 Thread Elizabeth Mattijsen

> On 16 Jun 2017, at 06:23, Gabor Szabo  wrote:
> 
> On Sat, Jun 10, 2017 at 9:38 AM, Brent Laabs  wrote:
>> I thought:
>> $ is Scalar
>> @ is Array
>> % is Hash
>> & is a function
>> 
> 
> Reading this https://docs.perl6.org/language/containers I just found
> out that a @-variable can also contain a List,
> not just an array:
> 
>> my @z = ()
> []
>> @z.^name
> Array
>> my @z := ()
> ()
>> @z.^name
> List

You can bind *anything* that does Positional to an @-variable:

$ perl6 
To exit type 'exit' or '^D'
> my @a := 42 but Positional
42
> @a[0]
42
> @a[1]
Index out of range. Is: 1, should be in 0..0
  in block  at  line 1



Liz


Re: How do you call the variable types?

2017-06-15 Thread Brandon Allbery
On Sat, Jun 10, 2017 at 2:38 AM, Brent Laabs  wrote:

> I thought:
> $ is Scalar
> @ is Array
> % is Hash
> & is a function
>

Pedantically:

$ forces item context, but otherwise allows any type (defaulting to
Scalar); the item context gets you "scalar" behavior in most cases even
with non-scalars
@ forces a Positional constraint (which defaults to Array)
% forces an Associative constraint (which defaults to Hash)
& forces a Callable constraint (no default, I think)

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: How do you call the variable types?

2017-06-10 Thread Brent Laabs
I thought:
$ is Scalar
@ is Array
% is Hash
& is a function

> my $x; say $x.VAR.WHAT;
(Scalar)

A dollar variable is a scalar.  The Scalar type is the the container for
the dollar-variables, just like Array is the container for @array and Hash
is the container for %hash.  Of course we also have this...
> my  
(Scalar)

It turns out functions are stored in Scalar containers as well.  In my view
it's a form of syntactic sugar to be able to to use function names without
a sigil in Perl 6.  A declared function is just an object; `sub foo {}` is
saved in the current lexical scope as   These function calls are all
equivalent:
> my  = sub { say "called" };
sub () { #`(Sub|140204743370112) ... }
> x()
called
> ()
called
> my $y =  $y();
called

(Though multi subs would be much more complex to declare this way.)


On Fri, Jun 9, 2017 at 9:51 PM, Gabor Szabo  wrote:

> Brad, thanks for your reply.
> I accept your point on not calling $-variables "generic variables",
> but then how do you call them?
>
> The same with the other 3. You described what they do in the same way
> as the documentation does, but
> when you casually speak about them, you know, with friends in bar :-),
>  what do you call them then? e.g.:
>
> @a = 23, 14, 49;
>
> Do you say:
> "I assign the list on the right hand side to a variable that does the
> Positional role."?
> or
> "I assign the list on the right hand side to an array." ?
> or
> "I assign the list on the right hand side to an at-variable." ?
> or
> Something completely different.
>
> Gabor
>
>
>
> On Sat, Jun 10, 2017 at 7:21 AM, Brad Gilbert  wrote:
> > @ does the Positional role
> > % does Associative
> > & does Callable
> > $ causes its value to be an item (its values do not flatten into an
> > outer list when you use `flat`)
> >
> > my %hash is SetHash;
> >
> > Array does Positional, and all of its values are itemized
> >
> > We are unlikely to call $ variables "generic" because the word
> > "generic" is too generic.
> > For example Java has generics, and they are not variables.
> > Why muddy the waters by using a word that has many different meanings
> > in different programming languages?
> >
> > On Fri, Jun 9, 2017 at 1:21 AM, Richard Hainsworth
> >  wrote:
> >> It also seems to me that 'scalar' gives the wrong impression compared to
> >> arrays. A scalar in a vector is a component of a vector.
> >>
> >> I was thinking of "generic".
> >>
> >> Hence "$variable" is a generic variable because it can hold any type of
> >> content.
> >>
> >>
> >>
> >> On Friday, June 09, 2017 02:10 PM, Gabor Szabo wrote:
> >>>
> >>> Looking at https://docs.perl6.org/language/variables there are 4
> >>> variable types with sigil:  $, @, %, &.
> >>> In Perl 5 I used to call them scalar, array, hash, and function
> >>> respectively, even if the scalar variable had a reference to an array
> >>> in it.
> >>>
> >>> How do you call them in Perl 6?
> >>>
> >>> As I understand @ always holds an array (@.^name is always Array or
> >>> some Array[type]). Similarly % always holds a hash and & is always a
> >>> function or a method.
> >>> So calling them array, hash, and function sounds good.
> >>>
> >>> However I am not sure what to call the variables with a $ sigil?
> >>> Should they be called "scalars"? Wouldn't that case confusion as there
> >>> is also a container-type called Scalar.
> >>>
> >>> The word "scalar" appears twice in the document describing the
> >>> variables: https://docs.perl6.org/language/variables and a total of
> >>> 135 in the whole doc including the 5to6 documents and the document
> >>> describing the Scalar type.
> >>> The document describing the Scalar type:
> >>> https://docs.perl6.org/type/Scalar the term "$-sigiled variable" is
> >>> used which seems to be a bit long for general use.
> >>>
> >>> So I wonder how do *you* call them?
> >>>
> >>> Gabor
>


Re: How do you call the variable types?

2017-06-09 Thread Gabor Szabo
Brad, thanks for your reply.
I accept your point on not calling $-variables "generic variables",
but then how do you call them?

The same with the other 3. You described what they do in the same way
as the documentation does, but
when you casually speak about them, you know, with friends in bar :-),
 what do you call them then? e.g.:

@a = 23, 14, 49;

Do you say:
"I assign the list on the right hand side to a variable that does the
Positional role."?
or
"I assign the list on the right hand side to an array." ?
or
"I assign the list on the right hand side to an at-variable." ?
or
Something completely different.

Gabor



On Sat, Jun 10, 2017 at 7:21 AM, Brad Gilbert  wrote:
> @ does the Positional role
> % does Associative
> & does Callable
> $ causes its value to be an item (its values do not flatten into an
> outer list when you use `flat`)
>
> my %hash is SetHash;
>
> Array does Positional, and all of its values are itemized
>
> We are unlikely to call $ variables "generic" because the word
> "generic" is too generic.
> For example Java has generics, and they are not variables.
> Why muddy the waters by using a word that has many different meanings
> in different programming languages?
>
> On Fri, Jun 9, 2017 at 1:21 AM, Richard Hainsworth
>  wrote:
>> It also seems to me that 'scalar' gives the wrong impression compared to
>> arrays. A scalar in a vector is a component of a vector.
>>
>> I was thinking of "generic".
>>
>> Hence "$variable" is a generic variable because it can hold any type of
>> content.
>>
>>
>>
>> On Friday, June 09, 2017 02:10 PM, Gabor Szabo wrote:
>>>
>>> Looking at https://docs.perl6.org/language/variables there are 4
>>> variable types with sigil:  $, @, %, &.
>>> In Perl 5 I used to call them scalar, array, hash, and function
>>> respectively, even if the scalar variable had a reference to an array
>>> in it.
>>>
>>> How do you call them in Perl 6?
>>>
>>> As I understand @ always holds an array (@.^name is always Array or
>>> some Array[type]). Similarly % always holds a hash and & is always a
>>> function or a method.
>>> So calling them array, hash, and function sounds good.
>>>
>>> However I am not sure what to call the variables with a $ sigil?
>>> Should they be called "scalars"? Wouldn't that case confusion as there
>>> is also a container-type called Scalar.
>>>
>>> The word "scalar" appears twice in the document describing the
>>> variables: https://docs.perl6.org/language/variables and a total of
>>> 135 in the whole doc including the 5to6 documents and the document
>>> describing the Scalar type.
>>> The document describing the Scalar type:
>>> https://docs.perl6.org/type/Scalar the term "$-sigiled variable" is
>>> used which seems to be a bit long for general use.
>>>
>>> So I wonder how do *you* call them?
>>>
>>> Gabor


Re: How do you call the variable types?

2017-06-09 Thread Brad Gilbert
@ does the Positional role
% does Associative
& does Callable
$ causes its value to be an item (its values do not flatten into an
outer list when you use `flat`)

my %hash is SetHash;

Array does Positional, and all of its values are itemized

We are unlikely to call $ variables "generic" because the word
"generic" is too generic.
For example Java has generics, and they are not variables.
Why muddy the waters by using a word that has many different meanings
in different programming languages?

On Fri, Jun 9, 2017 at 1:21 AM, Richard Hainsworth
 wrote:
> It also seems to me that 'scalar' gives the wrong impression compared to
> arrays. A scalar in a vector is a component of a vector.
>
> I was thinking of "generic".
>
> Hence "$variable" is a generic variable because it can hold any type of
> content.
>
>
>
> On Friday, June 09, 2017 02:10 PM, Gabor Szabo wrote:
>>
>> Looking at https://docs.perl6.org/language/variables there are 4
>> variable types with sigil:  $, @, %, &.
>> In Perl 5 I used to call them scalar, array, hash, and function
>> respectively, even if the scalar variable had a reference to an array
>> in it.
>>
>> How do you call them in Perl 6?
>>
>> As I understand @ always holds an array (@.^name is always Array or
>> some Array[type]). Similarly % always holds a hash and & is always a
>> function or a method.
>> So calling them array, hash, and function sounds good.
>>
>> However I am not sure what to call the variables with a $ sigil?
>> Should they be called "scalars"? Wouldn't that case confusion as there
>> is also a container-type called Scalar.
>>
>> The word "scalar" appears twice in the document describing the
>> variables: https://docs.perl6.org/language/variables and a total of
>> 135 in the whole doc including the 5to6 documents and the document
>> describing the Scalar type.
>> The document describing the Scalar type:
>> https://docs.perl6.org/type/Scalar the term "$-sigiled variable" is
>> used which seems to be a bit long for general use.
>>
>> So I wonder how do *you* call them?
>>
>> Gabor


Re: How do you call the variable types?

2017-06-09 Thread Richard Hainsworth
It also seems to me that 'scalar' gives the wrong impression compared to 
arrays. A scalar in a vector is a component of a vector.


I was thinking of "generic".

Hence "$variable" is a generic variable because it can hold any type of 
content.



On Friday, June 09, 2017 02:10 PM, Gabor Szabo wrote:

Looking at https://docs.perl6.org/language/variables there are 4
variable types with sigil:  $, @, %, &.
In Perl 5 I used to call them scalar, array, hash, and function
respectively, even if the scalar variable had a reference to an array
in it.

How do you call them in Perl 6?

As I understand @ always holds an array (@.^name is always Array or
some Array[type]). Similarly % always holds a hash and & is always a
function or a method.
So calling them array, hash, and function sounds good.

However I am not sure what to call the variables with a $ sigil?
Should they be called "scalars"? Wouldn't that case confusion as there
is also a container-type called Scalar.

The word "scalar" appears twice in the document describing the
variables: https://docs.perl6.org/language/variables and a total of
135 in the whole doc including the 5to6 documents and the document
describing the Scalar type.
The document describing the Scalar type:
https://docs.perl6.org/type/Scalar the term "$-sigiled variable" is
used which seems to be a bit long for general use.

So I wonder how do *you* call them?

Gabor