Closed ghost closed 1 year ago
Int
and IntRef
are not interchangeable array types.
Int
andIntRef
are not interchangeable array types.
OK. Then you could use the syntax like Java's Collections.addAll()
.
Update: What do you think about vec->FromArray([1,2,3])
? Same problem with vec->AddAll([1,2,3])
?
Added the following methods to all of the "Ref" classes
ToArray(..)
create a primitive array from a reference arrayFromArray(..)
create a reference array from a primitive arrayFor example
# static int array to intref array to intref vector
r := Collection.Vector->New(IntRef->FromArray([1, 2, 3]))<IntRef>;
r->Size()->PrintLine();
# intref vector to int array
p := IntRef->ToArray(r->ToArray());
p->PrintLine();
Added the following methods to all of the "Ref" classes
ToArray(..)
create a primitive array from a reference arrayFromArray(..)
create a reference array from a primitive arrayFor example
# static int array to intref array to intref vector r := Collection.Vector->New(IntRef->FromArray([1, 2, 3]))<IntRef>; r->Size()->PrintLine(); # intref vector to int array p := IntRef->ToArray(r->ToArray()); p->PrintLine();
@objeck Perhaps you misunderstood me. What I suggested is something much more powerful. It's basically about initializing Collections using Arrays. This offers a way to directly initialize Collections in a reasonable way that will not increase the complexity of the language.
Btw, the current API introduced by you is so obscure:
p := IntRef->ToArray(r->ToArray());
p->PrintLine();
r
is a Vector so r->ToArray()
is an array. Why do you convert IntRef
to an array which take r->ToArray()
which is already an array? I don't understand much about the Ref types of Objeck but this is so counter intuitive.
Added the following methods to all of the "Ref" classes
ToArray(..)
create a primitive array from a reference arrayFromArray(..)
create a reference array from a primitive arrayFor example
# static int array to intref array to intref vector r := Collection.Vector->New(IntRef->FromArray([1, 2, 3]))<IntRef>; r->Size()->PrintLine(); # intref vector to int array p := IntRef->ToArray(r->ToArray()); p->PrintLine();
@objeck Perhaps you misunderstood me. What I suggested is something much more powerful. It's basically about initializing Collections using Arrays. This offers a way to directly initialize Collections in a reasonable way that will not increase the complexity of the language.
Btw, the current API introduced by you is so obscure:
p := IntRef->ToArray(r->ToArray()); p->PrintLine();
r
is a Vector sor->ToArray()
is an array. Why do you convertIntRef
to an array which taker->ToArray()
which is already an array? I don't understand much about the Ref types of Objeck but this is so counter intuitive.
Primitives and references to primitives are two different datatypes, thus requiring conversions between the types. It is possible to write code that converts an array of primitives (i.e., Int [1,2,3]
) into an array of qualified generic references (i.e., IntRef[]
); however, that breaks the properties of generic programming by enforcing tight coupling.
The Java Arrays
class is primarily used to manipulate arrays and create Collections (i.e., List
) from arrays via methods like asList()
it is not for converting say a Java int
array to a Java Integer
array.
The following Java code does the latter:
Integer[] array = new Integer[]{1, 2, 3, 4};
This Objeck code is equivalent:
array := IntRef->FromArray([1,2,3,4])
Note the conversation work is done by the Integer
class in Java and the IntRef
class in Objeck. Conversely, one can write 3 to 5 lines of code to avoid using the above function.
The Integer
array constructor does the conversion.
The
Integer
array constructor does the conversion.
If you have decided this is the optimal syntax, I don't want to argue with you any further. One more quirk of the language is noted.
The
Integer
array constructor does the conversion.If you have decided this is the optimal syntax, I don't want to argue with you any further. One more quirk of the language is noted.
I make no claims that the syntax is "optimal," as that is a matter of opinion. I have implemented most of your feedback while looking past disparaging remarks. Initilizating a generic Vector
can be done in many ways and is not a language limitation.
I am seeking maintainers so that I may work on other aspects of the language. The goal is to empower maintainers to make independent decisions and contribute new ideas.
I make no claims that the syntax is "optimal," as that is a matter of opinion. I have implemented most of your feedback while looking past disparaging remarks. Initilizating a generic
Vector
can be done in many ways and is not a language limitation.
English is not my native language, so the use of words by me is not optimal
, either. I'm very sorry about that if it caused confusion or misunderstanding.
I am seeking maintainers so that I may work on other aspects of the language. The goal is to empower maintainers to make independent decisions and contribute new ideas.
I hope I could help but I can't. I don't have CS background.
@iahung2 Thank you for the feedback
I think we need something more powerful than https://github.com/objeck/objeck-lang/issues/276#issuecomment-1666850999
The syntax could look like this:
The syntax on https://github.com/objeck/objeck-lang/issues/276#issuecomment-1666850999 is counter intuitive and I think should be removed and replaced with the new syntax.