waterbearlang / waterbear

Visual block syntax for programming languages
http://waterbearlang.com/
357 stars 88 forks source link

Block to build a complex shape from an array of points #1279

Open dethe opened 8 years ago

dethe commented 8 years ago

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

CelticMinstrel commented 8 years ago

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

dethe commented 8 years ago

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

CelticMinstrel commented 8 years ago

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

dethe commented 8 years ago

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.

CelticMinstrel commented 8 years ago

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 8 years ago

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.

CelticMinstrel commented 8 years ago

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.