dg
dg copied to clipboard
changes to __getitem__ and/or None alias
So we were discussing whether to change the current __getitem__
syntax or to just alias _
to None
.
One idea is to allow the argument to !!
to be a tuple. Like this:
a = (0..21)
a!!(1,14,2) #=> range(1, 14, 2)
a !! slice 1 14 2 #=> range(1, 14, 2)
The !!
would just check if its argument is a tuple and unpack the arguments into a slice
object. Also, if _
is aliased to None
, reversing a list would just be: xs!!(_,_,-1)
. But at this point the syntax isn't radically different or improved. So maybe just aliasing _
to None
is the best change right now.
This problem with this is that a tuple can be a valid argument to __getitem__
in some cases; the most prominent example of that are numpy arrays. (xs !! (1, 2, 3)
is equivalent to Python's xs[1, 2, 3]
, which is the same thing as xs[(1, 2, 3)]
.)
Either way, right now I'm busy rewriting the parser; you've probably noticed that the current one is awful. (So awful, in fact, I don't even know exactly what kind of parser that is.) Everything else will probably have to wait until I either finish the new one or give up.
Argh right. Or just simply a dictionary could accept tuples. So probably the best thing should just alias _
to None
.
As for the parser, I don't have a complete vision of the dg internals yet! :D Right now I'm reading the compiler source code.
On second thought, aliasing _
to None
doesn't really work either. First, it would require reimplementing sys.displayhook
, which for some reason is also responsible for updating _
with the result of an expression entered into the REPL; second, it'd be necessary to come up with some different variable for that purpose. And, well, I can't think of a good name.
Damn, language design is hard.