daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

minor idea: discourage methods with copy semantics in favour of [:] #72

Open dumblob opened 9 years ago

dumblob commented 9 years ago

Just an idea in the name of simplifying the language and interfaces. I'm always feeling like copy() methods (e.g. in os.path) are redundant, because the same semantics has the special case of the [] operator, namely [:].

Shouldn't we discourage the creation and use of methods with copy semantics in favour of the [:] operator?

There is though currently an issue to use the [:] operator this way:

m = {0->5, 1->6}
n=m[:]
n[1]=9
io.writeln("m", m, "n", n)
[[Error::Key]] --- Invalid key:

In code snippet:
      6 :  DATA        :     0 ,     0 ,     6 ;     5;   :
>>    7 :  GETI        :     5 ,     6 ,     7 ;     5;   m[:]
      8 :  MOVE_PP     :     7 ,     1 ,     8 ;     5;   n=m[:] n
Raised by:  __main__(), at instruction 7 in line 2 in file "/home/test/test.dao";
Night-walker commented 9 years ago

[:] is slicing, which only slightly overlaps with copying and is hardly intuitive in most cases comparing to clone(). No need to turn the language into APL, it won't make it simpler.