More design points
Posted: Sat Jul 21, 2012 6:35 pm
Here's some things I've been thinking about while working on the MultiList class.
First, lists and arrays
It seems to me that line 3 should be a List. This would match the array literal syntax of line 1.
I find line 2 tricky for two reasons. First, the "get" keyword has a different meaning when dealing with properties. Second, there is nothing about the "for-get" syntax that indicates that a list is returned (as opposed to stream perhaps).
Finally, the compiler replaces generics angle brackets with square ones, and so generic types start to look like arrays.
First I propose that line 3 be a list and that int@[] be for arrays, to match the literal syntax. The compiler should also output angle brackets for generics
I think list comprehension should be written as follows
This would be equivalent to making a stream comprehension and evaluating it to a list.
Requiring square brackets around a list literal also means that braces { } could be used to specify a set or dictionary comprehension, @[ ] could be used for arrays, and maybe '[ ]' could be a StringBuilder comprehension.
for loops
It's unclear whether 'foo' is an int or stream.
Requiring '0:' for ints is more explicit. Perhaps the following could be used as shorthand.
Streams
Do Cobra streams have a 'next' and 'current' method? I want to merge two streams into a stream of pairs. As a platform dependent workaround, I casted each of the streams to C#'s IEnumerable.
Vari
Given a method with parameter 'as vari T', is there a way to call it with an 'IList<T>' variable?
cue init
Is there a way to make a private constructor? I tried 'cue _init' but that didn't work.
require
init allows multiline requires but methods and properties do not. When I tried to write a multiline require block in a method, I got the following confusing error
To get around the restriction, I wrote
Also, I find underscore to be a weird line continuation character because it's also a character for variables names and such. What about a backslash?
indexing
From within a class
Also
Error reporting
Cobra has the best compiler errors. To be even clearer:
"Test.cobra(5,21): error: Expecting GET, but got "yield" instead."
could say
"Test.cobra( line 5, column 21): error: ......"
First, lists and arrays
- Code: Select all
print [0,1,2,3].getType #System.Collections.Generic.List`1[System.Int32]
print (for i in 4 get i).getType #System.Collections.Generic.List`1[System.Int32]
print int[].getType #System.Int32[]
print @[0,1,2,3].getType #System.Int32[]
It seems to me that line 3 should be a List. This would match the array literal syntax of line 1.
I find line 2 tricky for two reasons. First, the "get" keyword has a different meaning when dealing with properties. Second, there is nothing about the "for-get" syntax that indicates that a list is returned (as opposed to stream perhaps).
Finally, the compiler replaces generics angle brackets with square ones, and so generic types start to look like arrays.
First I propose that line 3 be a list and that int@[] be for arrays, to match the literal syntax. The compiler should also output angle brackets for generics
I think list comprehension should be written as follows
lst = [ for i in 4 yield i ]
This would be equivalent to making a stream comprehension and evaluating it to a list.
lst = (for i in 4 yield i).toList
Requiring square brackets around a list literal also means that braces { } could be used to specify a set or dictionary comprehension, @[ ] could be used for arrays, and maybe '[ ]' could be a StringBuilder comprehension.
for loops
for i in foo
pass
It's unclear whether 'foo' is an int or stream.
for i in 0:foo
pass
Requiring '0:' for ints is more explicit. Perhaps the following could be used as shorthand.
for i in :foo
pass
Streams
Do Cobra streams have a 'next' and 'current' method? I want to merge two streams into a stream of pairs. As a platform dependent workaround, I casted each of the streams to C#'s IEnumerable.
Vari
Given a method with parameter 'as vari T', is there a way to call it with an 'IList<T>' variable?
cue init
Is there a way to make a private constructor? I tried 'cue _init' but that didn't work.
require
init allows multiline requires but methods and properties do not. When I tried to write a multiline require block in a method, I got the following confusing error
#Expecting DEDENT, but got "for" instead.
To get around the restriction, I wrote
require _
data.count >0 _
and data.count + start <= _shape.count _
and not _isReadonly _
and not _isPermuted
Also, I find underscore to be a weird line continuation character because it's also a character for variables names and such. What about a backslash?
indexing
From within a class
this[element] #doesn't compile
thisObj = this
thisObj[element] #works but gives
#warning: An explicit "this" literal is unnecessary for accessing members of the current object. You can remove "this".
Also
- Code: Select all
x = [1,2,3,4,5]
print x[:-1] #[1,2,3,4]
print x[-1]
#Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
#Parameter name: index
# at System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) [0x00000] in <filename unknown>:0
# at Test.Main () [0x00000] in <filename unknown>:0
#[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Argument is out of range.
#Parameter name: index
# at System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) [0x00000] in <filename unknown>:0
# at Test.Main () [0x00000] in <filename unknown>:0
Error reporting
Cobra has the best compiler errors. To be even clearer:
"Test.cobra(5,21): error: Expecting GET, but got "yield" instead."
could say
"Test.cobra( line 5, column 21): error: ......"