Re: [Pyobjc-dev] Objective-P?
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-11-12 15:06:00
|
On 12 Nov, 2009, at 15:56, Leonardo Santagada wrote: > > On Nov 12, 2009, at 8:52 AM, Anders Hovmöller wrote: > >> >> On Thu, Nov 12, 2009 at 10:59 AM, Ronald Oussoren <ron...@ma...> wrote: >> >> On 12 Nov, 2009, at 0:01, Anders Hovmöller wrote: >> >>> [ .... ] >>> >>> Find attached the source for the custom importer. >> >> While this is a nice trick I'd be much more interested in a syntax-change that at least has a chance of getting accepted into the Python core. Your syntax for calling a method is ambiguous, at least for the parser using in CPython and possibly in general: >> >> 10 <foo + bar> baz >> >> Python's parser needs to know if the '<' token is the start of a method call or a comparison operator (and so do humans, it's far from clear what's going on here when I look at the code). >> >> Yea, I know. I just chose <> instead of [] to finish my quick and dirty prototype in the two hours I had alloted :P As for trying to get something that can be accepted into Python proper, I think that's a dead end. Python already has a syntax for named parameters. I think this calls for a domain specific extension, not something you'd necessarily want to push up to CPython. >> >> >> I've been thinking about syntax enhancements during the summer, the best I could think of was the introduction of a new operator: >> >> class MyObject (NSObject): >> def $[setValue: value]: >> pass >> >> $[myObject setValue:42] >> >> In this code '$[' would be a new operator, which should be unambigous w.r.t. existing code. Better yet, one could use a simular trick for anonymous functions: >> >> Hmm, yea that's probably a nicer way of doing it. Changing from < and > to $[ and ] should be a rather trivial change in the hack I wrote. >> > > I always thought of doing this as a different encoding, so you can put your translation on Lib/encodings/ and just do a # _*_ encoding: objective-c on the source files. I know, it is kinda crazy. Yikes, that is ugly. Anders' custom importer is the right way to do this, that's one reason why custom importer hooks are possible in the first place. Ronald > > Look at pybraces for how to do it: > http://timhatch.com/projects/pybraces/ > > -- > Leonardo Santagada > santagada at gmail.com > > > |