Code blocks

David Mertz mertz at gnosis.cx
Mon Oct 13 16:31:27 EDT 2003


Back over in that same endless Lisp thread, the idea of codeblocks came
up.  Several variations were discussed, with some different opinions on
just how ugly or bearable the syntax was (I don't think any of them
registered as "wonderful" by anyone).

I think that codeblocks, a la Ruby, Smalltalk, xBase, would be kinda
nice to have.  But the thing I like about them isn't really that they
can be inlined, but rather simply that the operate without defining a
new (nested) scope.  Basically, codeblocks just amount to
boilerplate--except possibly paramaterized... and shorter, of course.

So for that, I would suggest a new scopeless pseudo-function syntax.
E.g.:

    block foo(this, that, other):
        x = this+that
        y = this*other
        z = x // (y-that)

Using this is like a function, but the names wind up in the calling
namespace:

    def bar(someblock):
        a, b, c = (4, 5, 6)
        someblock(a,b,c)
        return x,y,z

    vals = bar(foo)   #-> (9, 24, 0)

That is, I have no desire for blocks to be nameless, just for them to be
passable as first class objects.

Yours, David...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s






More information about the Python-list mailing list