Re: Bug to report: cardinal called an integer

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 23:20, WFB wrote:

Hi Todd,

For years, I have been playing around with programming stuff. I never 
stumbled across the term "cardinal". Its obvious that I am not an native 
English speaker and it does not hurt to learn new stuff. But, you makes 
it harder to understand your problems if you not use the common jargon.


Regards,
Wolfgang


Hi Wolfgang,

I am aware that the term might be obscure to some.
That is why I always say (uint) or unsigned integer to
make sure everyone knows what I am talking about.
I will continue to do so.

The term is quite common in Pascal and Modula2.
I have even seen it in C++.

Here are some examples for you:

C++
https://www.boost.org/doc/libs/1_71_0/libs/numeric/conversion/doc/html/boost_numericconversion/definitions.html

A numeric type Cardinal representing integer numbers with
a numeric set: {0,1,2,3,4,5,6,7,8,9} and range: [0,9] (
no modulo-arithmetic here)

Modula2:
https://www.modula2.org/tutor/chapter3.php

The simple types are INTEGER, CARDINAL,
REAL, BOOLEAN, and CHAR.

Ada (does not use the term, but their tutorials do)
https://en.wikibooks.org/wiki/Ada_Programming/All_Chapters

Unsigned Integers (unsigned, CARDINAL)

If you were to stumble across ALL the various
programming languages, you'd probably go insane,
so it is understandable that you would not have
heard the term.  In our Publik Skools, they use the
term "counting numbers", probably because they
want to avoid snickering about red birds and to
maintains the USA standing as the second worst
education system in the industrial world.

:-)

-T


Re: Bug to report: cardinal called an integer

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 20:03, Darren Duncan wrote:

On 2020-01-09 10:10 a.m., ToddAndMargo via perl6-users wrote:

A bug to report:

$ p6 'my uint32 $c; $c = "ABC";'
This type cannot unbox to a native integer: P6opaque, Str
   in block  at -e line 1

"uint32" is not an "integer".  It is a cardinal.  If
they really want to use the word "integer" for cardinal,
they should change the wording to "unsigned integer".

Picky, picky, picky


ToddAndMargo, you are wrong on this.

A uint32 is NOT specifically a cardinal.


Hi Darren,

Since a uint32 ca not be negative or a fraction,
it is a cardinal.  Other operating system do call
them cardinals, such as Modula2. Pascal, C++ (I
think C too), Java, and so on and so forth.

At best you can say it can be characterized by a cardinal or be 
isomorphic to one.


https://www.dictionary.com/browse/isomorphism
isomorphism
noun
Mathematics. a one-to-one relation onto the map
between two sets, which preserves the relations
existing between elements in its domain.

I am not following what you are getting at.

A uint32 is just as much an ordinal as a cardinal, so insisting on 
calling it a cardinal means the type can't be used as an ordinal, or a 
variety of other things.


https://www.dictionary.com/browse/ordinal-number
   ordinal number
   noun
   Also called ordinal numeral. any of the numbers that
   express degree, quality, or position in a series, as
   first, second, and third *(distinguished from cardinal
   number)*.

   Mathematics. a symbol denoting both the cardinal number
   and the ordering of a given set, being identical for
   two ordered sets having elements that can be placed
   into one-to-one correspondence, the correspondence
   preserving the order of the elements.

https://www.dictionary.com/browse/cardinal-number
   cardinal number
   noun
   Also called cardinal numeral. any of the numbers
   that express amount, as one, two, three, etc.
   *(distinguished from ordinal number)*.

No idea how you are mixing these two.  I can see
how yo would use a cardinal in programming to
denote an ordinal, if that is what you are getting at.


Calling this an unsigned integer (u int) is much more accurate as it 
doesn't presume a particular semantics such as that we are storing a 
count rather than a position for example, it says what we actually know, 
and no more.


I am sorry, I have no idea what you are trying to say.  I do not care if 
you call a cardinal an unsigned integer.  Just

don't call it an integer.  The high bit in a cardinal is
part of the number and denotes a negative number in an integer.



You are also wrong on saying that the values one can store in a uint32 
are not integers; they definitely ARE integers.  Every cardinal is an 
integer.


Where do you get that.  A cardinal can not be negative.  An
Integer can.  And the structure is even different:  the high
bit in an integer denote the sign of the integer; the high bit
in a cardinal is just a higher positive number.  So they
are not the same by any shake.


If you want to be precise, calling a uint32 an "unsigned integer" or 
"cardinal" is inaccurate in the same way that calling it an "integer" 
is.  


Perfectly accurate.  Unsigned integer and a cardinal are
exactly the same thing.   The only difference is the
amount of letter you need to use to describe them.
Sort of like "associative array" and "hash"

In either case, the variable can only hold a proper subset of 
either type, not all of them.  If you're calling integer wrong then one 
will have to call the type something like "integers in the range 
0..^2**32".


-- Darren Duncan


The difference between a cardinal and an integer is
the high bit.  Both are whole numbers.  An integer
can be negative.  A cardinal can not.

If you are going to error out something, say the proper
variable type you are error out on.  Cardinal or unsigned
integer, I don't care which you call a cardinal.  Whatever
floats your boat.  Both descriptions are correct.  Just
be correct.

-T

p.s. in assembly, they call a cardinal an unsigned integer.


Re: Bug to report: cardinal called an integer

2020-01-12 Thread WFB
Hi Todd,

For years, I have been playing around with programming stuff. I never
stumbled across the term "cardinal". Its obvious that I am not an native
English speaker and it does not hurt to learn new stuff. But, you makes it
harder to understand your problems if you not use the common jargon.

Regards,
Wolfgang

On Mon, 13 Jan 2020 at 05:03, Darren Duncan  wrote:

> On 2020-01-09 10:10 a.m., ToddAndMargo via perl6-users wrote:
> > A bug to report:
> >
> > $ p6 'my uint32 $c; $c = "ABC";'
> > This type cannot unbox to a native integer: P6opaque, Str
> >in block  at -e line 1
> >
> > "uint32" is not an "integer".  It is a cardinal.  If
> > they really want to use the word "integer" for cardinal,
> > they should change the wording to "unsigned integer".
> >
> > Picky, picky, picky
>
> ToddAndMargo, you are wrong on this.
>
> A uint32 is NOT specifically a cardinal.
>
> At best you can say it can be characterized by a cardinal or be isomorphic
> to one.
>
> A uint32 is just as much an ordinal as a cardinal, so insisting on calling
> it a
> cardinal means the type can't be used as an ordinal, or a variety of other
> things.
>
> Calling this an unsigned integer (u int) is much more accurate as it
> doesn't
> presume a particular semantics such as that we are storing a count rather
> than a
> position for example, it says what we actually know, and no more.
>
> You are also wrong on saying that the values one can store in a uint32 are
> not
> integers; they definitely ARE integers.  Every cardinal is an integer.
>
> If you want to be precise, calling a uint32 an "unsigned integer" or
> "cardinal"
> is inaccurate in the same way that calling it an "integer" is.  In either
> case,
> the variable can only hold a proper subset of either type, not all of
> them.  If
> you're calling integer wrong then one will have to call the type something
> like
> "integers in the range 0..^2**32".
>
> -- Darren Duncan
>


Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 18:23, ToddAndMargo via perl6-users wrote:

On 2020-01-12 16:05, Joseph Brenner wrote:

This can be done with an explicit, named subset if you like:

   subset StrOrInt where Str | Int;

   sub do_stuff ( StrOrInt $item ) {
   say "$item is a " ~ $item.^name;
   }


Hi Joseph,

I like it.

Now to figure where to put it so it is apparent
when maintaining the code.  I will play
around with placement.

Thank you!

-T



$ p6 'subset StrOrUint where Str | uint32; my StrOrUint $x = -2.14'
Type check failed in assignment to $x; expected StrOrUint but got Rat 
(-2.14)

  in block  at -e line 1


Re: Bug to report: cardinal called an integer

2020-01-12 Thread Darren Duncan

On 2020-01-09 10:10 a.m., ToddAndMargo via perl6-users wrote:

A bug to report:

$ p6 'my uint32 $c; $c = "ABC";'
This type cannot unbox to a native integer: P6opaque, Str
   in block  at -e line 1

"uint32" is not an "integer".  It is a cardinal.  If
they really want to use the word "integer" for cardinal,
they should change the wording to "unsigned integer".

Picky, picky, picky


ToddAndMargo, you are wrong on this.

A uint32 is NOT specifically a cardinal.

At best you can say it can be characterized by a cardinal or be isomorphic to 
one.

A uint32 is just as much an ordinal as a cardinal, so insisting on calling it a 
cardinal means the type can't be used as an ordinal, or a variety of other things.


Calling this an unsigned integer (u int) is much more accurate as it doesn't 
presume a particular semantics such as that we are storing a count rather than a 
position for example, it says what we actually know, and no more.


You are also wrong on saying that the values one can store in a uint32 are not 
integers; they definitely ARE integers.  Every cardinal is an integer.


If you want to be precise, calling a uint32 an "unsigned integer" or "cardinal" 
is inaccurate in the same way that calling it an "integer" is.  In either case, 
the variable can only hold a proper subset of either type, not all of them.  If 
you're calling integer wrong then one will have to call the type something like 
"integers in the range 0..^2**32".


-- Darren Duncan


Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-09 06:56, ToddAndMargo via perl6-users wrote:

    mailto:perl6-users@perl.org>> wrote:

    Hi All,

    In a sub declaration, is there a way to constrain
    a variable to only an "int32" or a "Str" (I want both)?
    Or do I have to put up with the other types of "Any"?

    Many thanks,
    -T



On Thu, 9 Jan 2020 at 08:13, WFB > wrote:


    Hi, Todd,

    If I understand your question right, then you mean something like 
that:


    sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}

    https://docs.raku.org/type/Signature#index-entry-where_clause

    Regards

    On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users



On 2020-01-08 23:14, WFB wrote:

For the sake of readability you might want use a subset:
https://docs.raku.org/language/typesystem#subset



Hi W,

Subset does no seems to be what I am after, but "where"
does.   Thank you!

-T


Hi W,

I might be changing my mind.  It would not be the
first time you have done that to me.

:-)

-T


Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 16:05, Joseph Brenner wrote:

This can be done with an explicit, named subset if you like:

   subset StrOrInt where Str | Int;

   sub do_stuff ( StrOrInt $item ) {
   say "$item is a " ~ $item.^name;
   }


Hi Joseph,

I like it.

Now to figure where to put it so it is apparent
when maintaining the code.  I will play
around with placement.

Thank you!

-T


Re: Changing the error message from subset type violation

2020-01-12 Thread yary
As I was next to you in today's Raku gathering, I came up with this as a
sort-of answer. Not very happy with it but it gets partway there.

#!/usr/bin/env perl6
use v6.d;

## Simple version to check membership, but the type error won't tell which
strings
# subset Critter of Str where any 

## This subset knows its strings and notes the right values. But, can't
catch that message.
subset Critter of Str where {
my @valid-animals = ;

# What I'd like to do here, is return a block which accepts the
# right things, and adds to the type check failure on bad things.
# But all I can get working, is checking & returning a boolean,
# perhaps noting a message. The caller then ACCEPTS against either
# True or False and doesn't know about the note.

$_ ~~ any @valid-animals
 or {
note("at $^c.file():$^c.line() Critter must be one of @valid-animals[]");
False;
 }(callframe(4)); # fiddle with callframe until Raku gets Carp
};

my Critter $pet = 'bee';
my Critter $pat = 'fish';

CATCH {
default {
note "** Caught this **";
.rethrow
}
}

##   Ideal output
# ** Caught this **
# Type check failed in assignment to $pat; expected Critter but got Str
("fish")
# Critter must be one of ant bee cat dog elephant
#   in block  at ./substr_err.raku line 27

##   Actual output
# at ./subset_except.raku:27 Critter must be one of ant bee cat dog elephant
# ** Caught this **
# Type check failed in assignment to $pat; expected Critter but got Str
("fish")
#   in block  at ./subset_except.raku line 27


Re: weirdness with subset on has

2020-01-12 Thread Joseph Brenner
Moving the definition of the subset outside of the class
covers for the weird behavior...

  my @allowed = << alpha beta gamma delta >>;
  my @default = << alpha >>;
  subset Allowed of Str where * eq any( @allowed );

  class HasSubset {
  has Allowed @.grk = @default;
  method echo_grk {
  say @!grk.join(" | ");
  }
  }

  my $obj = HasSubset.new();
  $obj.echo_grk();

  my $obj2 = HasSubset.new( grk => << alpha beta gamma >> );
  $obj2.echo_grk();

  my $obj3 = HasSubset.new( grk => << alpha beta rutabaga >> );
  $obj3.echo_grk();
  # value 'rutabaga' fails as expected:
  # Type check failed in assignment to @!grk; expected
HasSubset::Allowed but got Str ("rutabaga")


On 1/12/20, Joseph Brenner  wrote:
> Here's a code snippet that tries to use a subset to constrain the
> values of an object field (i.e. declared with has).  As written, this
> code works, but only when there's what looks like an irrelevant
> experimental line in it (labeled "WEIRD ONE"), when that line is
> commented out it throws an error...
>
>   class HasSubset {
>   my @allowed = << alpha beta gamma delta >>;
>   my @default = << alpha >>;
>
>   subset Allowed of Str where * eq any( @allowed );
>
>   my Allowed $experiment = 'delta'; # WEIRD ONE this line is
> *needed* to get the following to work...
>
>   has Allowed @.greek = @default;
>
>   method echo_greek {
>   say @!greek.join(" | ");
>   }
>   }
>
>   my $obj = HasSubset.new();
>   $obj.echo_greek();
>
>   # As written, prints the default: 'alpha'
>   # Without the WEIRD ONE line, you see errors like:
>   ## Type check failed in assignment to @!greek; expected
> HasSubset::Allowed but got Str ("alpha")
>


weirdness with subset on has

2020-01-12 Thread Joseph Brenner
Here's a code snippet that tries to use a subset to constrain the
values of an object field (i.e. declared with has).  As written, this
code works, but only when there's what looks like an irrelevant
experimental line in it (labeled "WEIRD ONE"), when that line is
commented out it throws an error...

  class HasSubset {
  my @allowed = << alpha beta gamma delta >>;
  my @default = << alpha >>;

  subset Allowed of Str where * eq any( @allowed );

  my Allowed $experiment = 'delta'; # WEIRD ONE this line is
*needed* to get the following to work...

  has Allowed @.greek = @default;

  method echo_greek {
  say @!greek.join(" | ");
  }
  }

  my $obj = HasSubset.new();
  $obj.echo_greek();

  # As written, prints the default: 'alpha'
  # Without the WEIRD ONE line, you see errors like:
  ## Type check failed in assignment to @!greek; expected
HasSubset::Allowed but got Str ("alpha")


Re: int and Str in sub declaration question

2020-01-12 Thread Joseph Brenner
This can be done with an explicit, named subset if you like:

  subset StrOrInt where Str | Int;

  sub do_stuff ( StrOrInt $item ) {
  say "$item is a " ~ $item.^name;
  }



On 1/9/20, ToddAndMargo via perl6-users  wrote:
 mailto:perl6-users@perl.org>> wrote:

 Hi All,

 In a sub declaration, is there a way to constrain
 a variable to only an "int32" or a "Str" (I want both)?
 Or do I have to put up with the other types of "Any"?

 Many thanks,
 -T

>
>>> On Thu, 9 Jan 2020 at 08:13, WFB >> > wrote:
>>>
>>> Hi, Todd,
>>>
>>> If I understand your question right, then you mean something like
>>> that:
>>>
>>> sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}
>>>
>>> https://docs.raku.org/type/Signature#index-entry-where_clause
>>>
>>> Regards
>>>
>>> On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users
>
>
> On 2020-01-08 23:14, WFB wrote:
>> For the sake of readability you might want use a subset:
>> https://docs.raku.org/language/typesystem#subset
>>
>
> Hi W,
>
> Subset does no seems to be what I am after, but "where"
> does.   Thank you!
>
> -T
>


Changing the error message from subset type violation

2020-01-12 Thread Joseph Brenner
I was just playing around with using a "subset" to restrict a
string to a set of allowed values:

  subset Monster of Str where * eq any( << godzilla mothera blob
tingler grendel minotaur >> );

  my Monster $thingie;
  $thingie = 'grendel';  # accepts this as expected

  $thingie = 'nada'; # fails as expected, with message:
  # Type check failed in assignment to $thingie; expected Monster but
got Str ("nada")

I was wondering if there's some way to replace that error message
with a better one.  If there's only a half dozen allowed values
I'd want to tell the user something like

  "The string nada is note one of the allowed values
   godzilla mothera blob tingler grendel minotaur"

I keep thinking there should be a form of where with a CATCH that
should work, but I don't see how to do it.


Re: rakudo.org outdated?

2020-01-12 Thread yary
I downloaded the Rakudo Star 2019.11-rc1 source installer from
https://dist.tyil.nl/raku/rakudo-star/ and built it on OS X 10.15.2
"Catalina", rakudo-test complains about Native Call, and also that a couple
TODO's pass

*Test Summary Report*
t/04-nativecall/20-concurrent.t   (Wstat: 65280
Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 3 tests but ran 0.
t/09-moar/Line_Break__LineBreak.t (Wstat: 0
Tests: 2 Failed: 0)
  TODO passed:   2
t/09-moar/General_Category__extracted-DerivedGeneralCategory.t (Wstat: 0
Tests: 1 Failed: 0)
  TODO passed:   1
Files=103, Tests=1773, 84 wallclock secs ( 0.56 usr  0.22 sys + 247.48 cusr
24.06 csys = 272.32 CPU)
Result: FAIL
make[1]: *** [m-coretest5] Error 1
make: *** [rakudo-test] Error 2

still "make install" got me a Raku that's good enough for me to keep
tinkering with

-y


On Thu, Jan 9, 2020 at 2:30 AM Patrick Spek via perl6-users <
perl6-users@perl.org> wrote:

> On Mon, 6 Jan 2020 11:38:01 -0800
> Darren Duncan  wrote:
>
> > On 2020-01-06 1:18 a.m., Patrick Spek via perl6-users wrote:
> > > On Sun, 5 Jan 2020 18:27:01 -0800 Darren Duncan wrote:
> > >
> > >> The normal Rakudo Star releases so far are compiled, [...]
> > >
> > > For Mac and Windows, perhaps, but the release is similar as it
> > > always was for GNU+Linux. And I'm mostly aiming for that since
> > > that's what I use (and also what I can test). Hence, I need people
> > > to verify they can make binaries for Windows and Mac (and actually
> > > do it as well) before I can continue.
> > >
> > >> If your version requires users to run a Makefile or make or cc or
> > >> whatever or have a working C compiler, then it is a source release
> > >> and not the same thing.
> > >
> > > I never intended to make a "binary" release. I intended to make a
> > > Rakudo Star release, and I personally don't care if that'd be a
> > > binary or source. In the case of GNU+Linux, it's a source release.
> >
> > As long as we know what to expect.  So it sounds like you're just
> > making a single source release of Rakudo Star that users of any
> > operating system would compile themselves, and not separate
> > Linux/Mac/Win versions as had been the case before.  In that case, I
> > can do basic build testing on MacOS for you.  I would just try
> > following the same instructions as Linux users more or less. --
> > Darren Duncan
>
> Any additional testing is very much appreciated! I'd like to have
> someone that can generate a .dmg as well if possible, though, so we can
> continue to deliver some form of binary variant for mac users.
>
> --
> With kind regards,
>
> Patrick Spek
>
>
> www:  https://www.tyil.nl/
> mail: p.s...@tyil.nl
> pgp:  1660 F6A2 DFA7 5347 322A  4DC0 7A6A C285 E2D9 8827
>
> social: https://soc.fglt.nl/tyil
> git:https://gitlab.com/tyil/
>


Re: Bug to report: cardinal called an integer

2020-01-12 Thread ToddAndMargo via perl6-users




Here is one reason why you do these to to be
distinct from each other.  In Win API calls to the
registry, REG_DWORDs are all cardinals, not
integers:


Here is a link to the graphicsthat did not come out:

https://social.msdn.microsoft.com/Forums/getfile/1525734


Re: Bug to report: cardinal called an integer

2020-01-12 Thread ToddAndMargo via perl6-users

  
  
On 2020-01-12 09:18, Marcel Timmerman
  wrote:


  
  On 1/9/20 7:10 PM, ToddAndMargo via
perl6-users wrote:
  
   'my
uint32 $c; $c = "ABC";'
  The error shows that you cannot assign a string to an int (This
type cannot unbox to a native integer: P6opaque, Str)
  
  You can do the following to get it right;
  
  'p6  -e 'my uint32 $c; $c = 0xABC;''
  
  

Hi Marcel,

That you for the tip!  I have been using Hex numbers
a lot lately.

Here is a workaround to assign the value of a cardinal ($c)
to an integer ($x):

p6 'my uint32 $c = 0xFFAA; my int32 $x = $c +| 0x; say $c.base(16);'

FFAA


Back on subject.

The intent of my posting was not to correct a
mistake in my code, but to demonstrate a mistake
in the description of the returned error.

Cardinals or unsigned integers, whatever you want to
call them, are not the same thing.  The error description
called a cardinal and integer.

Here is one reason why you do these to to be
distinct from each other.  In Win API calls to the
registry, REG_DWORDs are all cardinals, not
integers:



And having the error properly describe the variables
involved helps you troubleshoot your booboo's.

-T
  



Re: Bug to report: cardinal called an integer

2020-01-12 Thread Marcel Timmerman

On 1/9/20 7:10 PM, ToddAndMargo via perl6-users wrote:

'my uint32 $c; $c = "ABC";'
The error shows that you cannot assign a string to an int (*This type 
cannot unbox to a native integer: P6opaque, Str*)


You can do the following to get it right;

'p6  -e 'my uint32 $c; $c = 0xABC;''