stencila / mini

A minimal, functional language focused on data analysis and visualization
15 stars 0 forks source link

Unpacking assignment #15

Open nokome opened 7 years ago

nokome commented 7 years ago

A potentially useful addition to the Mini syntax is "unpacking"/"destructuring" assignment.

Javascript has object and array "destructuring" e.g.

var a, b, rest
{a, b} = {a: 10, b: 20}
[a, b] = [10, 20]
[a, b, ...rest] = [10, 20, 30, 40, 50]

Python has "iterable unpacking"

a, b = [10, 20]
a, b, *rest = [10, 20, 30, 40, 50]

Personally, I prefer the Python syntax although we need to consider whether we would use * or ... for unpacking or for "automatic dependencies" in external function calls e.g. r(...) or r(*)

Rationale is primarily cleaner syntax, similar to the Python PEP rationale. In particular, I was thinking about the syntax for importing functions in Mini (e.g. reusing functions in someone else's project). This would be a function (instead of a keyword!) import e.g.

custom_plot = import('some_project/custom_plot')

But if I wanted to import several functions from a project, I'd like to write something like:

custom_func, custom_plot = import('some_project')
obuchtala commented 7 years ago

Probably you mean

custom_func, custom_plot = import('some_project')
nokome commented 7 years ago

Thanks, yes you're right ... I fixed it.