Code block literals

Donald 'Paddy' McCarthy paddy3118 at netscape.netNOTthisBIT
Wed Oct 15 04:16:05 EDT 2003



John Roth wrote:
> "Greg Ewing (using news.cis.dfn.de)" <g2h5dqi002 at sneakemail.com> wrote in
> message news:bmd3cv$lk51t$1 at ID-169208.news.uni-berlin.de...
> 
>>Dave Benjamin wrote:
>>
>>>In that case, why do we eschew code blocks, yet have no problem with the
>>>implicit invocation of an iterator,
>>
>>I don't think code blocks per se are regarded as a bad thing.
>>The problem is that so far nobody has come up with an entirely
>>satisfactory way of fitting them into the Python syntax as
>>expressions.
> 
> 
> I know. I played around with the idea a bit after it came up a couple
> of weeks ago, and identified a number of issues.
> 
<<SNIP>>
> 
> So let's say I want to use a code block instead of
> a lambda or a named function in a map:
> 
> foobar = map(def (x, y, z):
>         astatement
>         anotherstatement
>     list1, list2, list3)
> 
<<SNIP>>
> A third item is that I don't really care if we use 'def'
> or not. Borrowing the vertical bar from Ruby, the map
> example becomes:
> 
> foobar = map(| x, y, z |
>         astatement
>         anotherstatement
>     list1, list2, list3)
> 
> I kind of like this better, except for one really unfortunate
> issue: it's going to raise havoc with code coloring algorithms
> for a while.
> 
> John Roth
> 

Hmm,
How about just using the presence of (...):: as starting a code block?
A call to a function that might take two function args and something else:
   foo = bar(func1, func2, nonfunc)
would become:
   foo = bar( (a,b)::
       astatement
       somemorestatements
     ,(c,d,e)::
       anotherstatement
       yetmorestatements
     ,nonfunc)

I used the double colon after the closing bracket as the statements of 
the enclosed statement block must be double indented w.r.t foo

I guess the indentation of the arguments of bar (not including the 
statement blocks could have less restrictive indentation.
Just as you could write
   foo = bar(
    func1,
        func2,
    nonfunc)
the indentation rules would have to be that the statement block is 
double indented on the line after ):: and the statement block ends on 
the next line with LESS indentation (more indentation would be tart of 
the statement block).

Pad.






More information about the Python-list mailing list