duck-lang
duck-lang copied to clipboard
Add string & array functions
Strings and arrays seem to have lots of missing functions and properties. For example length properties and substr/array are missing. For convenience I would make strings and arrays the same thing (String = char[]) like D does it, for writing functions easier. Some functions/properties that are really important:
lengthsubarray/substringor maybe implement an index range operator[start .. length]and alsocopyor maybe implement an array copy operatora = b[]indexOflastIndexOfpush(add)sortmaybe?
I want to make sure I don't overlook this.
Implementing a real, consistent standard library has been one of my goals from the start but it is still something I am trying to delay for as long as possible. For a few reasons:
Until there is a reliable, consistent standard library, with features for strings and arrays, there won't be very much serious development in Duck. This is useful because it allows more development of the language side of things before adoption.
While still figuring out what the model is for the Duck language, especially in choosing platform support, there is a bit of a difference between different Duck environments. The JavaScript interpreter, for example, on the home page is a slightly different revision of the language than the code version, and it has slightly different behavior because it uses JavaScript types for certain things, like numbers.
So I want to make sure the language is at a stage for these developments first. Another thing I haven't determined yet is whether to support compound types. For example, given a string s, is it possible to attach methods and fields to s? If so, does it still behave as a string.
In any case, these are all features that should be added and I'll consider your syntax recommendations in the design.
I also think the ideas for indexing arrays and ranges of arrays are great. I would have to think about the syntax for a copy constructor. Also, I agree that strings should behave like arrays, but I wouldn't necessarily say they should be implemented in the same way.
Agreed On Aug 18, 2015 6:03 PM, "Greg Tourville" [email protected] wrote:
I also think the ideas for indexing arrays and ranges of arrays is great. I would have to think about the syntax for a copy constructor. Also, I agree that strings should behave like arrays, but I wouldn't necessarily say they should be implemented in the same way.
— Reply to this email directly or view it on GitHub https://github.com/gregtour/duck-lang/issues/23#issuecomment-132407493.
Making a string a char[] instead of a separate type makes many things much easier. Then just adding extension functions make it perfect. Like strings inherit splicing from arrays. Or functions that work with arrays should work with strings too, like for example split or sort. I also think casting a string to a byte[] should be possible.