Idea: Python Shorthand (was Re: Why a class when there will only be one instance?

Josh Gilbert jgilbert+comp.lang.python at uvm.edu
Thu May 27 15:47:44 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ville Vainio wrote:

>>>>>> "Josh" == Josh Gilbert <jgilbert+comp.lang.python at uvm.edu> writes:
> 
> 
>     Josh> Now that's a great idea! Nlanguageigils stuff, I switched
>     Josh> from Perl to Python for a reason, I was putting sigils in my
>     Josh> English, C, and so on.
> 
> I agree - the $ @ stuff was a (bad) joke, as I said elsewhere.
> 
>     Josh> There are two paths, have the IDE convert each line to
>     Josh> Python when you hit '\n' or as a batch. The first method
>     Josh> would allow it in Python shells.
> 
> Live conversion would probably bring less surprises.
> 
>     Josh> This is a very good idea. I wonder how hard it will be.
> 
> At least it doesn't *seem* difficult. It might even be easy enough to
> do with regexps!
> 
> Some syntax brainstorming again:
> 
> d f x,y,z=12:  ->   def f(x,y,z=12):    (, is one keystroke just like
> space)
> 
>   d f x,y:     ->   def f(self,x,y):    (d with indent, add self)
> 
> p x; r x;      ->   print x; return x
> 
> 
> a.b 1,2 ; a..b ; .a;  ->   a.b(1,2); a.b ; self.a;
> 
> Sounds like a potentially fun emacs project, and the style of
> programming that could be appreci8ed by TXT MSG gener8n :-).
> 

Oh my. It's utterly trivial with IPython. As in the framework is all there,
just plug in your rules. My implementation currently uses only regex's
which could lead to errors in string literals or comments. However, it
works. 

A more interesting implementation would be to write a full-blown parser for
the shorthand language with a simple lookup table to translate it to real
Python. I might get around to it, but probably not. I can't think of a way
to save much more typing without being overly obscure. 

Well that was fun. I guess the only thing left for me to say is the vague
handwaving of suggesting that the script could decode to another language,
any language as long as you can define a one to one correspondence of
terminals. So I could write Java that looked an awful lot like Python.
Probably a bad idea.

        Josh

- -- 
http://www.uvm.edu/~jgilbert/public_key.gpg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAtkX13TWYZBkZ2IsRAiylAJ9oaFGHFoN0aRE8aGWxmyZIDt2c6ACbBBfB
FG/DVh1ApDQyBvKRQeTW61g=
=7Nwd
-----END PGP SIGNATURE-----



More information about the Python-list mailing list