Pythonification of the asterisk-based collection packing/unpacking syntax
buck
workitharder at gmail.com
Sat Dec 17 23:52:32 EST 2011
I like the spirit of this. Let's look at your examples.
> Examples of use:
> head, tail::tuple = ::sequence
> def foo(args::list, kwargs::dict): pass
> foo(::args, ::kwargs)
My initial reaction was "nonono!", but this is simply because of the ugliness. The double-colon is very visually busy.
I find that your second example is inconsistent with the others. If we say that the variable-name is always on the right-hand-side, we get:
> def foo(list::args, dict::kwargs): pass
This nicely mirrors other languages (such as in your C# example: "float foo") as well as the old python behavior (prefixing variables with */** to modify the assignment).
As for the separator, let's examine the available ascii punctuation. Excluding valid variable characters, whitespace, and operators, we have:
! -- ok.
" -- can't use this. Would look like a string.
# -- no. Would looks like a comment.
$ -- ok.
' -- no. Would look like a string.
( -- no. Would look like a function.
) -- no. Would look like ... bad syntax.
, -- no. Would indicate a separate item in the variable list.
. -- no. Would look like an attribute.
: -- ok, maybe. Seems confusing in a colon-terminated statement.
; -- no, just no.
? -- ok.
@ -- ok.
[ -- no. Would look like indexing.
] -- no.
` -- no. Would look like a string?
{ -- too strange
} -- too strange
~ -- ok.
That leaves these. Which one looks least strange?
float ! x = 1
float $ x = 1
float ? x = 1
float @ x = 1
The last one looks decorator-ish, but maybe that's proper. The implementation of this would be quite decorator-like: take the "normal" value of x, pass it through the indicated function, assign that value back to x.
Try these on for size.
head, @tuple tail = sequence
def foo(@list args, @dict kwargs): pass
foo(@args, @kwargs)
For backward compatibility, we could say that the unary * is identical to @list and unary ** is identical to @dict.
-buck
More information about the Python-list
mailing list