mhogenso/Zuse — pull request #24 by pwightman (2013-11-22 06:12:57+00:00)
Title: Method metadata

The issue we need to solve is that Vlad needs to know detailed information about each method call that we provide to him, methods like `move("up right", 100)` or `max(var_1, var_2)`. I'm proposing we encode this in JSON, which can give us a lot of fine-grained control over the methods, and it will make the UI more data-driven instead of having to hard-code everything. See the diff, but I'll explain the pertinent parts here.

Each method has a `method key that defines how it would be presented to the user:

```json
{
"method": "move [speed] [direction]"
}
```

`[speed]` and `[direction]` would be placeholders where the users would tap to insert a value. Using the `[bracket]` syntax would also allow us to make some of the methods more natural, like:

```
"move [direction] every [seconds]"
```

That's just a random one, but you get the idea.

Along side the `method` key would be the `parameters` key that has an entry for each of the placeholders. In the case of the `speed` placeholder, we just specify that any number is valid by specifying `numeric` in the types. Other types would be things like `string` or `boolean`.

```json
{
"speed": {
"types": ["numeric"]
}
}
```

The direction param is a little more complicate though. We want to list some custom strings (like "up right") but then also give them the option to enter a number, and that needs to be in degrees, so between 0 - 360. You could specify all those like so:

```json
{
"direction": {
"types": [
{
"numeric": {
"range": [0, 360]
}
}
],
"custom_types": [
"up right",
"up left",
"up",
"right",
"down right",
"down left",
"down",
"left"
]
}
}
```

Anyway. There's a few holes here, like we can't really enforce ranges on variables because there's no way to know what value variables hold until the program runs, so I'm not sure that will work come to think of it. But I'm too tired to keep thinking about this, ha. Let me know what you think!