Microsoft's Dynamic Languages Runtime (DLR)
Duncan Booth
duncan.booth at invalid.invalid
Thu May 3 13:43:41 EDT 2007
aleax at mac.com (Alex Martelli) wrote:
> Duncan Booth <duncan.booth at invalid.invalid> wrote:
>
>> means in pure Python code the string has python methods, but in
>> Python using the CLR it gains the CLR methods. Presumably in Ruby
>> code it looks like a Ruby string and so on, but (and this is what's
>> new) it is the same object, not a bunch of language specific wrappers
>> around the string type.
>
> So is it changeable (making Python code using it deeply unhappy) or
> unchangeable (making Ruby or Javascript code similarly unhappy)? The
> idea of just having one string type across languages is fascinating,
> but I'm not sure it can work as stated due to different semantics such
> as mutable vs immutable...
>
I think they said in the video that Ruby strings were a whole other talk.
My guess is that, as .Net strings are immutable, Ruby can use them but its
own strings must be some other class.
I did a bit of experimenting with Python and JScript in the DLRconsole
sample (http://silverlight.net/Samples/1.1/DLR-Console/python/index.htm).
Sadly I cannot figure out any way of copying text from the DLR console so
I'll attempt to retype it (hopefully without too many mistakes). BTW, this
is a straight copy: the console really does let you flip languages while
keeping the same variables in scope.
py> s = System.String("abc")
py> s
'abc'
py> type(s)
<type 'str'>
py> s2 = "abc"
py> type(s2) is System.String
True
js> typeof(s)
'string'
js>typeof(s2)
'string'
js> System.String
<type 'str'>
py> n = 42
py> type(n)
<type 'int'>
js> typeof(n)
'number'
py> System.Int32
<type 'int'>
py> type(n) is System.Int32
True
py> p = 2**64
py> type(p)
py> type(p) is System.Int64
False
js> typeof(p)
'Microsoft.Scripting.Math.BigInteger'
py> lst = [1, 2, 3]
js> typeof(lst)
'IronPython.Runtime.List'
js> x = 42
42.0
py> type(x)
<type 'float'>
js> var a = [1, 2, 3]
py> type(a)
<type 'JSArrayObject'>
So it looks like str, int, long, float all map to common types between the
languages but list is an IronPython type. Also as you might expect JScript
will happily use an integer but it only produces float values.
More information about the Python-list
mailing list