[Pythonmac-SIG] [ann] appscript 0.4.0 released

Bob Ippolito bob at redivi.com
Sat Feb 14 11:59:25 EST 2004


On Feb 13, 2004, at 7:09 PM, Chris Ryland wrote:

> On Friday, February 13, 2004, at 03:46 PM, has wrote:
>
>> Heh, I'm not a big fan of operators; know what you mean though.  
>> Reason I'm trying it here is that a conventional method call-based  
>> approach soon becomes unreadable when constructing an expression of  
>> any complexity; for example:
>>
>>    items.test(its.size.greaterthan(12).AND(its.color.equals([0,0,0])))
>>
>> versus:
>>
>>    items.test(its.size > 12 and its.color == [0,0,0])
>
> items.test(lambda: its.size > 12 and its.color = [0, 0, 0]))
>
> would be great! And "all" you have to do is to walk the AST for the  
> lambda (bytecodes are really too low-level and too late for different  
> semantics) and ignore any Pythonic meanings, instead generating the  
> AppleEvent equivalent code (typed Lisp, really). That gives you a lot  
> of freedom!

I don't think it's possible to get an AST, and "its" should be taken as  
an argument to the lambda.

 >>> import inspect
 >>> inspect.getsource(lambda its:its.size > 12)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/inspect.py", line 549, in getsource
     lines, lnum = getsourcelines(object)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/inspect.py", line 538, in getsourcelines
     lines, lnum = findsource(object)
   File  
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/inspect.py", line 408, in findsource
     raise IOError('could not get source code')
IOError: could not get source code

 >>> import dis
 >>> dis.dis(lambda its:its.size > 12 and its.color == [0,0,0])
   1           0 LOAD_FAST                0 (its)
               3 LOAD_ATTR                1 (size)
               6 LOAD_CONST               1 (12)
               9 COMPARE_OP               4 (>)
              12 JUMP_IF_FALSE           22 (to 37)
              15 POP_TOP
              16 LOAD_FAST                0 (its)
              19 LOAD_ATTR                2 (color)
              22 LOAD_CONST               2 (0)
              25 LOAD_CONST               2 (0)
              28 LOAD_CONST               2 (0)
              31 BUILD_LIST               3
              34 COMPARE_OP               2 (==)
         >>   37 RETURN_VALUE

-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20040214/02dcc48e/smime.bin


More information about the Pythonmac-SIG mailing list