Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing docs for how to find the type of a native int #1568

Closed
zoffixznet opened this issue Sep 19, 2017 · 4 comments
Closed

Missing docs for how to find the type of a native int #1568

zoffixznet opened this issue Sep 19, 2017 · 4 comments
Assignees
Labels
docs Documentation issue (primary issue type)

Comments

@zoffixznet
Copy link
Contributor

I think there's some way to ask a variable for what type of native int it is (maybe something with metamodel?)

Don't see anything mentioned on https://docs.perl6.org/type/nativeInt

@zoffixznet zoffixznet added docs Documentation issue (primary issue type) new part of "docs" - indicates that this documentation is for a new, currently undoc'd section labels Sep 19, 2017
@Skarsnik
Copy link
Contributor

Skarsnik commented Sep 19, 2017 via email

@zoffixznet
Copy link
Contributor Author

I thought there was something, but perhaps it was the .^name.

It's not working for variables:

m: say int32.^name                                                                      rakudo-moar 083403: OUTPUT: «int32␤»
m: (my int32 $ = 42).^name.say                                                          rakudo-moar 083403: OUTPUT: «Int␤»

And I'm a bit surprised even this doesn't work. Gives Int for all the values:

my @vs := 42, (my int $ = 42), (my int32 $ = 42),
    (my int64 $ = 42), (my int16 $ = 42), (my int8 $ = 42);

multi wat (int)   { 'int'   }
multi wat (int8)  { 'int8'  }
multi wat (int16) { 'int16' }
multi wat (int32) { 'int32' }
multi wat (int64) { 'int64' }
multi wat (Int)   { 'Int'   }

.&wat.say for @vs;

@jnthn
Copy link
Contributor

jnthn commented Sep 21, 2017

.^name is a meta-method call; to call a meta-method, we need an object to resolve the meta-object, and thus the native type is boxed into an Int and the call is done on that.

@vs is being bound to a List which holds objects, thus they are all boxed at the point of being made into a list.

Natives don't know their types because they're just values, without any meta-data. And sized natives only matter for storage; all operations are done at full width. So by the time you actually get a native in a position where you could pass it somewhere, it will be full-width anyway, so multi-dispatching over their size won't work out.

We might some day be able to make $some-native-var.VAR.of work out; at first I thought that was probably easy, then looked more closely and realized that no, not quite. You can, however, already as a native int array what kinds of elements it has, using my int32 @x = 42; say @x.of.

@JJ JJ added JJ TPF Grant and removed new part of "docs" - indicates that this documentation is for a new, currently undoc'd section labels Apr 8, 2018
@JJ
Copy link
Contributor

JJ commented Apr 14, 2018

I see two options here. First, just close the issue, since there is no actual way to find the type of a native type. Second, to add the sentence by @jnthn

Natives don't know their types because they're just values, without any meta-data.
in an appropriate context, at least in the page that @zoffixznet has mentioned. I'd rather go for the first, but I'm open to arguments for the second (or any other option, for that matter)

@JJ JJ self-assigned this Apr 14, 2018
@JJ JJ removed the JJ TPF Grant label May 14, 2018
@JJ JJ closed this as completed in 0c95459 Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

4 participants