waterbearlang/waterbear

Block to build a complex shape from an array of points

dethe opened this issue · 7 comments

dethe commented

We might even want a few variations of this for things like visualizing music samples, etc. Related to #1278.

This is just a "polygon" block, isn't it?

dethe commented

Yes, except you can't currently drop an array into a polygon, or initialize a polygon in a loop (to add many points concisely).

Ah, I see what you mean. It's a variation on the polygon block, then.

dethe commented

Yes. There have been requests for typed arrays, so one option would be to do that and have polygon take an array of points as its argument.

I don't really think typed (homogeneous) arrays are worthwhile. Although there's definitely blocks that should expect a homogeneous array as input, they can be made to accept any array and handle elements that are the wrong type in some sensible manner (try to convert them, skip them, treat them as null, etc).

dethe commented

Mainly the requests for homogeneous arrays come from folks building wrappers for languages which expect that (C, Java, Arduino, etc.), but I can see them having use in WB for making type expectations obvious.

I can't imagine why anyone would want to make a wrapper for C... Anyway, homogeneous arrays are not actually a type, per se. They're a type modifier. Thus, you can't just make them a type using the existing mechanisms in Waterbear. You would need a lot of new logic for it. (You could think of the homogeneous array as a function that takes a type as input and returns a type.)

Someone wanting to write a wrapper for Java would simply implement them as an array of Object. I don't really know how Arduino works, but I imagine you could probably do something similar there, too. If you were crazy enough to write a wrapper for C, you can use an array of union types. In short, implementing a heterogeneous array in languages that only have homogeneous ones built-in is very much possible.