开发者

Delete a variable in boo

I 开发者_运维问答know that the similarities between boo and Python are only superficial, but still, how can I do an equivalent of the following Python code in boo?

a = 'a'
del a
a = 1

I've tried

a = 'a'
a = null
System.GC.Collect()                                                                                                                                                    
System.GC.WaitForPendingFinalizers()
a = 1

But booish tells me it cannot convert 'int' to 'string'.

The point is not to use the duck type. Is that possible?

Edit: As per comment suggestions, changed del from function to statement.


This is not possible in Boo. Boo uses implicit static-typing. Thus, all variables are strongly typed based on their first assignment within their scope. Once assigned, the type of the variable cannot change.

Garbage collecting will ensure that objects on the heap which are no longer referenced will be removed from the heap, but it has no effect on each language's individual variable scoping. In Boo, a variable does not go out of scope until the end of the block in which it was defined.

Duck typing in Boo is handled by the compiler, which assigns it the static type of "object" and then uses runtime code to effect the duckiness of what the underlying .NET runtime considers a generic object.


you can declare a as object

a as object a = "letter_a"

print a "letter a"

a = 1 print a 1

I like more boo than python!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜