develooper Front page | perl.perl6.users | Postings from January 2020

Re: stolen uint's

Thread Previous | Thread Next
From:
Trey Harris
Date:
January 29, 2020 20:18
Subject:
Re: stolen uint's
Message ID:
CALKJ+EtaXWHb+xtHZ5NHOGoa4dbxEmSEfNsbhyo=GSMR=nLO+Q@mail.gmail.com
On Wed, Jan 29, 2020 at 14:39 ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 2020-01-29 11:32, Trey Harris wrote:
> > On Wed, Jan 29, 2020 at 13:50 ToddAndMargo via perl6-users
> > <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >
> >     Why don't use use
> >
> >     typeMappings[type_index( typeid(char) )] = "char";
> >
> > Finally, a definition I can work with...
> >
> > We can treat this as a request for typeid(); the mapping creation and
> > lookup is an implementation detail.
> >
> > So: the C++ typeid operator works in two modes, static (which happens at
> > compile-time and is inlined) and dynamic (which happens at runtime and
> > is subject to polymorphism). Do you want the static or the dynamic
> behavior?
>
>
> I thought that was C not C++, but ...


The `typeid` operator is C++. Some stdlib extensions have a `typeid` in C,
but it’s non-standard.

Also, your example given below is C++, not C.

As variables in Raku get boxed and coerced
> all the time, I guess I am asking for dynamic.


In that case, you have it already as was mentioned much earlier. See
https://gist.github.com/treyharris/0ce541c07a1f94b41af61207563e7807

with
```perl6
proto check_type($ --> Str) { * }
multi check_type(uint $var) { return "uint" }
multi check_type(Int $var) { return "Int" }

my uint $ui = 42;
say "Value is $ui"; # Value is 42
say check_type($ui); # uint
say ".^name is {$ui.^name}"; # .^name is Int
say check_type($ui); # uint

# .abs autoboxes
say check_type($ui.abs); # Int

# abs() does not
say check_type(abs $ui); # uint
```

Is that what you’re going for?



>
> I am after what the variable is at the moment I
> ask.
>
> Is Raku written in C or C++?


You can go to https://github.com/rakudo/rakudo and determine this for
yourself—click the colored bar to see the language breakdown. (92.6% at the
moment is written in Raku itself; it’s mostly a self-hosted language.)

One of the guys on the C group wrote me this:


That was C++, for the record.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About