Python Macros

Arich Chanachai macrocosm at fastmail.fm
Mon Oct 4 14:04:46 EDT 2004


Michael Sparks wrote:

>Arich Chanachai wrote:
>
>  
>
>>How hard/easy is it to extend the Python syntax? 
>>    
>>
>
>It's not that hard to do, but involves changing the compiler and if done
>properly a whole slew of other things. If you want non-functional syntax
>changes it's fairly trivial - just change the Grammar file and rebuild. 
>If you want a checklist of things you might want to look at when changing
>the syntax you could look at this patch : http://www.python.org/sf/1013835
>
>  
>
Are there tutorials on this?

>It's worth noting that this would probably result in a local overhead for
>yourself in maintaining a private branch of python however - since this
>changes your python in a fairly fundamental manner. I don't know what your
>use case is though - if it's experimentation then I suspect that you'd be
>happy with that :)
>
>  
>
:Local overhead???  Private branch???  How come?  I'm extending the 
language not adding another Python interpreter.

>>Perhaps there are macro facilities for this? 
>>    
>>
>
>Not that I'm aware of. (At least not as far as I know in the lisp or C
>meanings of the term)
>
>  
>
I was thinking Scheme.

>>I'd like to add messages and message passing, for example.
>>    
>>
>
>Why do you feel you need to extend the language for this? Why not (for
>example) overload <<, >> and similar operators? __lshift__, __rshift__ etc.
>I'd really recommend not extending the language unless you really don't have
>any option - unless that's what you're specifically interested in :)
>
>
>  
>
Not sure I understand you here.  I want to implement messages like in 
ObjC where if you send a msg to an object and that object does know what 
to do with it, it can send the obj automatically to another object which 
might know what to do with it.

Anyhow, there are other reasons as well.




More information about the Python-list mailing list