logo       

[jira] Created: (BOO-246) Implicit duck typing option: msg#00007

lang.boo.devel

Subject: [jira] Created: (BOO-246) Implicit duck typing option

Message:

A new issue has been created in JIRA.

---------------------------------------------------------------------
View the issue:
http://jira.codehaus.org/browse/BOO-246

Here is an overview of the issue:
---------------------------------------------------------------------
Key: BOO-246
Summary: Implicit duck typing option
Type: New Feature

Status: Unassigned
Priority: Major

Original Estimate: Unknown
Time Spent: Unknown
Remaining: Unknown

Project: Boo
Components:
Compiler

Assignee:
Reporter: Doug Holton

Created: Thu, 3 Feb 2005 3:58 PM
Updated: Thu, 3 Feb 2005 3:58 PM

Description:
This idea was mentioned in a few mailing list posts:
http://archive.boo.codehaus.org/user/messages/530
http://archive.boo.codehaus.org/user/messages/558
http://archive.boo.codehaus.org/user/messages/559
(Rodrigo's response is not in the archives)

When a type in boo cannot be inferred, it resolves to "object". For example,
this code will not work because "ToUpper()" is a method of type string, not
type object:

l = [1,"asdf",3]
for item in l: //item's type is just "object"
if item isa string:
print item.ToUpper()
else:
print item

Currently you can cast to a string, which is fastest:
print (item as string).ToUpper()

or you can cast the item to a "duck" type so that the method resolution doesn't
happen until runtime (this is slower):

for item as duck in l:
item.ToUpper() //now works if the item is really a string


We can create a compiler option to implicitly treat unknown types as type
"duck" instead of type "object", so no "as duck" is necessary. This might be
helpful for lighter scripting tasks where speed is not so important.

For example to make the above code sample work, in
src/Boo.Lang.Compiler/TypeSystem/TypeSystemServices.cs, change the end of the
GetEnumeratorItemType method (at line 424) from this:
return ObjectType;
to this:
return DuckType;

To make implicit duck typing optional, however, we would need to add the option
to the Boo compiler (or else implement it as a compiler service like Rodrigo
has discussed for other future options).


---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise