[IronPython] Missing __long__ method on int

2007-03-11 Thread Michael Foord
Hello all,

It looks like integer objects in IronPython are missing the '__long__' 
method. My apologies if this is a duplicate.

All the best,

Michael
http://www.voidspace.org.uk/ironpython/
___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] C#, Types and IronPython

2007-03-11 Thread Simon Dahlbacka



Several of the MSDN examples use 'typeof(int)', why not just specify
'Int32' ? I guess it makes the code less platform dependent ?? Oh well.



they are not the same thing

In CLS (or whatever the .net type system is called), System.Int32 is the
"normal" integer type, that you can type just int in C# is just syntactic
sugar.

In normal cases you work with variables, but in some cases you want to work
with the types (just as you can use e.g. type(42) in python), in that case
you can use either typeof(int) or int foo=42;foo.GetType() (or Type.GetType
("System.Int32") ) and of these the former is more efficient if the type you
want is known at compile time..

hope this helps,

Simon
___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] C#, Types and IronPython

2007-03-11 Thread Michael Foord
Nicholas Riley wrote:
> On Sun, Mar 11, 2007 at 02:27:11PM +, Michael Foord wrote:
>   
>> What object does 'typeof(int)' (in C# *not* IronPython) return. I guess 
>> it is not System.Int32 !
>> 
>
> Indeed it is; I'm not sure why you're confused about this when a
> one-line C# program will give you the answer :-)  typeof(int) is
> converted by the C# compiler into the following IL:
>
> ldtoken[mscorlib]System.Int32
> call   class [mscorlib]System.Type 
> [mscorlib]System.Type::GetTypeFromHandle(valuetype 
> [mscorlib]System.RuntimeTypeHandle)
>
> which makes it pretty clear that System.Int32 is specified at compile
> time.
>
>   
>> Is there a common base class for the C# number types ?
>> 
>
> No; however there are several common interfaces these types implement,
> such as IConvertible.
>
>   
Ok - cool. That's very helpful. I'm still not really used to the idea of 
decompiling assemblies to get this sort of information.

Several of the MSDN examples use 'typeof(int)', why not just specify 
'Int32' ? I guess it makes the code less platform dependent ?? Oh well.

Thanks

Michael

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] C#, Types and IronPython

2007-03-11 Thread Nicholas Riley
On Sun, Mar 11, 2007 at 02:27:11PM +, Michael Foord wrote:
> What object does 'typeof(int)' (in C# *not* IronPython) return. I guess 
> it is not System.Int32 !

Indeed it is; I'm not sure why you're confused about this when a
one-line C# program will give you the answer :-)  typeof(int) is
converted by the C# compiler into the following IL:

ldtoken[mscorlib]System.Int32
call   class [mscorlib]System.Type 
[mscorlib]System.Type::GetTypeFromHandle(valuetype 
[mscorlib]System.RuntimeTypeHandle)

which makes it pretty clear that System.Int32 is specified at compile
time.

> Is there a common base class for the C# number types ?

No; however there are several common interfaces these types implement,
such as IConvertible.

-- 
Nicholas Riley <[EMAIL PROTECTED]> | 
___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] C#, Types and IronPython

2007-03-11 Thread Michael Foord
Nicholas Riley wrote:
> On Sat, Mar 10, 2007 at 01:34:32PM +, Michael Foord wrote:
>   
>> I have some C# that is getting at type objects in several different 
>> ways, and I would like to know the difference.
>>
>> Type.GetType("int")
>> typeof(int)
>>
>> and I think :
>>
>> int.GetType()
>> 
>
> In IronPython this is asking for the type of 'int' here, not the type
> of _an_ int.  In C# it does both.
>
>   

Right - but what I want to do is get the type object for 'int' that 
would be returned by that call in C#.

I realise that what Python understands as 'int' is a different thing to 
what C# understands as int.

Thanks for the other info. I see that 'Type.GetType' works when you pass 
in a fully qualified type name - but I swear I saw an example in C# that 
didn't. I'm trying to find it now and failing ! I give up. Perhaps I 
hallucinated it.

All the best,

Fuzzyman
http://www.voidspace.org.uk/ironpython/
___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Type.GetType returns None

2007-03-11 Thread Michael Foord
J. Merrill wrote:
> Those aren't comparable statements.  If you had passed "String" (in quotes) 
> in your C# I think that would have worked, but "string" should not -- 
In the example I gave, 'string' was a variable name, not a literal. :-)

There are overloads that allow you to specify a case-insensitive search 
as well by the way.

The trouble I have is that in IronPython 'Type.GetType("String")' 
returns None. In fact all the following return None :

 >>> Type.GetType("String")
 >>> Type.GetType("int")
 >>> Type.GetType("Int32")

Even when I move the 'Type.GetType' call into C# and then call it from 
IronPython it still returns None - meaning it couldn't find the type I 
was asking for. I don't understand why...

Adding the assembly qualifier (System.String) works - but they are used 
without the qualifier in an MSDN example, which works when compiled as C#...

Using "some string".GetType() (with a string literal) works - but is a 
little inconvenient.

Also - the C# examples use 'typeof(int)' and 'Type.GetType("int")'. To 
make it work I've replaced these with 'Int32', which works but is 
obviously not exactly the same...

Thanks

Fuzzyman
http://www.voidspace.org.uk/ironpython/

> the Type.GetType(string) overload is defined as a case-sensitive search, and 
> in general wants an "assembly qualified name".
>
> http://msdn2.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx
>
> Perhaps all would be fine in pure IP if you had just used 
> Type.GetType(String) or String.GetType(); I'm away and not easily able to try 
> it myself.
>
> I would guess that the cause is that Python's "string" type (lowercase 
> without the quotes) is not the same as .Net's "String" type (mixed case 
> without quotes).
>
> At 09:48 AM 3/10/2007, Michael Foord wrote
>   
>> Michael Foord wrote:
>> 
>>> Hello all,
>>>
>>> Why does "Type.GetType(string)" return None from IronPython ?
>>>
>>> I need to use it with names like "Console", "int" and "string" - 
>>> fetching the .NET type objects. I guess this is because of the reflected 
>>> types ? Do I have an alternative that will work ? (other than stub C#).
>>>   
>>>   
>> Interesting - even with the following C# called from IronPython it 
>> returns None. The code I am translating is from the MSDN docs. Any clues ?
>>
>> namespace SimpleTest
>> {
>>public class SimpleTest
>>{
>>public static Type getType(string typename){
>>return Type.GetType(typename);
>>}
>> }
>>
>> Michael Foord
>> http://www.voidspace.org.uk/ironpython/
>> 
>
>
> J. Merrill / Analytical Software Corp
>
>
> ___
> users mailing list
> users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] C#, Types and IronPython

2007-03-11 Thread Michael Foord
Keith J. Farmer wrote:
> http://msdn2.microsoft.com/en-us/library/system.type.gettype.aspx
>
> The C# typeof(typeid) operator doesn't take a string.  Instead, it takes the 
> type identifier and returns an object representing that type.  It's basically 
> a compile-time operation.
>
> The framework's Type.GetType methods are runtime operations that take some 
> input (eg, a string containing the name of a type, or a variable whose type 
> you want to know) and return the appropriate Type object.
>   
Right - so they both just return a type object. The distinction is that 
one is dynamic (runtime) and the other compile time. That much is fine.

It still doesn't explain to me why they are both used in the MSDN 
example, and more to the point why the example doesn't just use the type 
objects in the first place ! (I don't expect you to answer this. :-)

What object does 'typeof(int)' (in C# *not* IronPython) return. I guess 
it is not System.Int32 ! Is there a common base class for the C# number 
types ?

Thanks

Fuzzyman
http://www.voidspace.org.uk/ironpython/


> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Foord
> Sent: Saturday, March 10, 2007 5:35 AM
> To: Discussion of IronPython
> Subject: [IronPython] C#, Types and IronPython
>
> Hello all,
>
> Despite my previous email, I still need some help. :-)
>
> I have some C# that is getting at type objects in several different 
> ways, and I would like to know the difference.
>
> Type.GetType("int")
> typeof(int)
>
> and I think :
>
> int.GetType()
>
> What are the differences in semantics between 'typeof(...)' and 
> 'Type.GetType(...)' ?
>
> All the best,
>
> Michael
> http://www.voidspace.org.uk/ironpython/
> ___
> users mailing list
> users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
> ___
> users mailing list
> users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com