-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spreading a dynamic value #270
Comments
This was ceylon/ceylon-spec#800, FTR. |
This has a somewhat limited functionality. I can do this: value tuple = [1,"2",'3'];
somethingDynamic.spread(*tuple); //turns into tuple.get(0), tuple.get(1), tuple.get(2)
somethingDynamic.spread(*someDynamicArray); //stays as someDynamicArray please check the test code in the related commits @corbinu |
First off I believe the second test should be?
as the elements already in issue270 would be spread across push so issue270 would go from My only other thought is sometimes a dynamic value might be iterable or not. I assume if it is not that the spread will do nothing. So I think there should be a two more tests
|
If the value is not Iterable there should be an exception thrown by a runtime type check. Sent from my iPhone
|
Ok that works too. Given the major use case is for varadic JS functions though does seem a bit of a waste having to check if none, one or many args were passed to the wrapper function each and every time. |
I know it seems like the second test should add 5 elements to the array, but it's simply impossible to spread that array like I spread the tuple, because I don't know the length of the array at compile time (I can't even know it's an array at compile time; it's a dynamic value). As for iterables, I can check if the argument is an Iterable, but then what? How can I spread an Iterable to pass its elements to a native js call? I can't. If I add the runtime type check as @gavinking suggests then the second test will throw an exception, since |
Well maybe I am wrong but my understanding is Ceylon Tuples and Sequences are simplified to a native Array or a generic array-like object correct? couldn't the generated code just look something like this
|
That's quite convoluted for a simple invocation. But the real problem is that we can't really use And no, tuples and sequences are not simplified to narive arrays. Ceylon methods with variadic parameters work similar to Java methods with varargs: the variadic parameter is really a Sequential inside the method, and there's a validation that sets the argument to |
Well it doesn't sound like there is a simple unconvoluted solution. Could apply not be easily added to JsCallable? or the internal native js function extracted from JsCallable much like how a Ceylon String is unwrapped? Well I never assumed it would use the Ceylon way of spreading varidic parameters as the dynamic type is not guaranteed to be a Ceylon object. Which I think is a lot of the issue. I defiantly agree this is more complicated to implement then I had anticipated though. I will will see if perhaps I can take a deeper look at JsCallable etc tomorrow |
Moving to 1.1 |
So I guess we could have a native function that receives a Ceylon Iterable (Tuple, Sequence, Array, whatever) and returns a JS array, or checks if the received object is already a native JS array and just returns it; otherwise, throw an Error. And we can use this function with the |
Sounds good .... Sorry I know my interop work finds the most crazy edge cases ever. |
better sooner than later |
The backend needs to support spreading a
dynamic
value with the*
operator. This was something we agreed on with @corbinu.The text was updated successfully, but these errors were encountered: