Python vs. Io

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Ehrenberg

    Python vs. Io

    Io (www.iolanguage.com) is a new programming language that's purely
    object-oriented (but with prototypes), has a powerful concurrency
    mechanism via actors, and uses an extremely flexible syntax because
    all code is a modifiable message tree. Like Python, it is dynamically
    typed, has a very clean syntax, produces short code, and is
    excruciatingly slow (on the same level as eachother). Io has a unique
    syntax combining Lisp's idea of functions for flow control with
    traditional function syntax and smalltalk-like syntax to get slots of
    objects. Io has no keywords and everything, even multiple lines of
    code, can be used as an expression. Even as a beginner to Io, I was
    able to write something in just 43 lines to let you do something like
    this (and more) in Io:

    each((key, value) in map(x=1, y=2, z=3),
    write(key, ": ", value, "\n")
    )

    Neither the each function nor the map function were built in (Io has
    other mechanisms for that kind of thing, but they are less efficient).
    Can anyone show me how to so much as alias "for" to "each" in Python
    or allow block syntax at all without hacking the C source code?

    Io doesn't use __methods_with_ this_annoying_s yntax__ because nothing
    is supposed to be for internal use only and there are only about three
    functions that would cause a problem if overridden.

    For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
    uses IoCamelCase, which looks much better. Interfaces to C are much
    more object oriented.

    Many users of Io (myself included) have switched over from Python for
    these reasons.

    I guess there are still the obvious advantages of Python over Io,
    including
    *large community
    *more bindings to stuff
    *strict coding conventions
    *inflexible so everything is the same
    *no need to close blocks
    But unless there are other problems, the first two go away soon
    (considering that Io was first created just two years ago). The last
    three are somewhat trivial and may even be to Io's advantage.

    Daniel Ehrenberg
  • John Roth

    #2
    Re: Python vs. Io


    "Daniel Ehrenberg" <LittleDanEhren @yahoo.com> wrote in message
    news:711c7390.0 401291301.3f957 94@posting.goog le.com...
    [color=blue]
    > Can anyone show me how to so much as alias "for" to "each" in Python[/color]

    Without getting into the language wars, I think what you're looking
    for is called the Visitor Pattern (Design Patterns: GOF). It's actually
    trivial to implement as long as you're not looking for built-in support.

    Something like this works quite well in any object where you want
    to implement a visitor over a collection:

    class aCollection:
    def visit(self, instance):
    for x in self._collectio n:
    instance.visito r(x)
    return instance.result ()

    The final call is a little more than the bare visitor pattern, but it
    allows the visitor instance to pass back a result so you can use
    it in expressions.

    A visitor then looks like this:

    class fubar:
    def __init__(self):
    self.whatever = 0
    def visitor(self, value):
    self.whatever += value
    def result(self):
    return self.whatever

    and you use it like this:

    ohWow = aCollection.vis it(fubar())

    Unlike a block in, for example, Ruby, a visitor instance
    can be pre-initialized, it can have multiple methods and
    it can persist after being passed against the collection.

    Of course, you can use more complex data structures as well,
    see the compiler stuff for examples of the visitor pattern used
    over the Python Abstract Syntax Tree.

    The visitor pattern is also very useful for file system
    navigation; I use it consistently.

    John Roth
    [color=blue]
    >
    > Daniel Ehrenberg[/color]


    Comment

    • Brian Kelley

      #3
      Re: Python vs. Io

      John Roth wrote:[color=blue]
      > "Daniel Ehrenberg" <LittleDanEhren @yahoo.com> wrote in message
      > news:711c7390.0 401291301.3f957 94@posting.goog le.com...
      >
      >[color=green]
      >>Can anyone show me how to so much as alias "for" to "each" in Python[/color]
      >
      >
      > Without getting into the language wars, I think what you're looking
      > for is called the Visitor Pattern (Design Patterns: GOF). It's actually
      > trivial to implement as long as you're not looking for built-in support.[/color]

      I think Daniel's example is a little bit more complicated than that. It
      resembles more closly the lisp-ish macros that were discussed to death a
      while ago.

      Note that in his code:
      each((key, value) in map(x=1, y=2, z=3),
      write(key, ": ", value, "\n")
      )

      key and value are variable names that get used inside the function call.

      Here is my pythonic(?) version, however it requries a lambda to bind the
      variable names.

      def map(**kw):
      return kw.items()

      def each(seq, func):
      for v in seq:
      apply(func, v)

      from sys import stdout
      write = stdout.write

      each(map(x=1,y= 2,z=3),
      lambda key, value: write("%s: %s\n"%(key, value)))

      Brian

      Comment

      • David M. Cooke

        #4
        Re: Python vs. Io

        At some point, LittleDanEhren@ yahoo.com (Daniel Ehrenberg) wrote:
        [color=blue]
        > Io (www.iolanguage.com) is a new programming language that's purely
        > object-oriented (but with prototypes), has a powerful concurrency
        > mechanism via actors, and uses an extremely flexible syntax because
        > all code is a modifiable message tree. Like Python, it is dynamically
        > typed, has a very clean syntax, produces short code, and is
        > excruciatingly slow (on the same level as eachother). Io has a unique
        > syntax combining Lisp's idea of functions for flow control with
        > traditional function syntax and smalltalk-like syntax to get slots of
        > objects. Io has no keywords and everything, even multiple lines of
        > code, can be used as an expression. Even as a beginner to Io, I was
        > able to write something in just 43 lines to let you do something like
        > this (and more) in Io:
        >
        > each((key, value) in map(x=1, y=2, z=3),
        > write(key, ": ", value, "\n")
        > )
        >
        > Neither the each function nor the map function were built in (Io has
        > other mechanisms for that kind of thing, but they are less efficient).
        > Can anyone show me how to so much as alias "for" to "each" in Python
        > or allow block syntax at all without hacking the C source code?[/color]

        Hey, if I wanted to to, I could add functions and all that that would
        make Python look like Lisp, or IO, or whatever.

        But, why? If I wanted to write Lisp or Io, I'd use those.

        Your example I'd write in Python as

        for key, value in dict(x=1, y=2, z=3):
        print '%s: %s\n" % (key, value)

        I didn't have to write 43 lines of support code, and it's also two
        lines. I don't think "this isn't builtin" is a selling point -- you
        need a critical mass of builtins to make a language useful.
        [color=blue]
        > Io doesn't use __methods_with_ this_annoying_s yntax__ because nothing
        > is supposed to be for internal use only and there are only about three
        > functions that would cause a problem if overridden.[/color]
        [color=blue]
        > For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
        > uses IoCamelCase, which looks much better. Interfaces to C are much
        > more object oriented.[/color]

        Ok, these two points are window-dressing: minor spelling and
        punctuation issues (which seems to be what most language wars are about).

        Heck, use boost::python for C++ interfaces; those function names are
        even shorter. Or use pyrex to generate wrappers, writing them in a
        Pythonesque language.
        [color=blue]
        > Many users of Io (myself included) have switched over from Python for
        > these reasons.
        >
        > I guess there are still the obvious advantages of Python over Io,
        > including
        > *large community
        > *more bindings to stuff[/color]

        Yep. That's a *big* difference, I'd say.
        [color=blue]
        > *strict coding conventions
        > *inflexible so everything is the same[/color]

        Can you elaborate a bit on why Python is inflexible? I find Python to
        be extremely flexible.
        [color=blue]
        > *no need to close blocks
        > But unless there are other problems, the first two go away soon
        > (considering that Io was first created just two years ago). The last
        > three are somewhat trivial and may even be to Io's advantage.[/color]

        Python is 14 years old, and it's still working on global domination;
        Io's got some catching up to do :-)

        --
        |>|\/|<
        /--------------------------------------------------------------------------\
        |David M. Cooke
        |cookedm(at)phy sics(dot)mcmast er(dot)ca

        Comment

        • Christopher Koppler

          #5
          Re: Python vs. Io

          On Thu, 29 Jan 2004 17:21:19 -0500, cookedm+news@ph ysics.mcmaster. ca
          (David M. Cooke) wrote:
          [color=blue]
          >At some point, LittleDanEhren@ yahoo.com (Daniel Ehrenberg) wrote:
          >[/color]
          [snip-a-lot][color=blue]
          >[color=green]
          >> For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
          >> uses IoCamelCase, which looks much better. Interfaces to C are much
          >> more object oriented.[/color]
          >
          >Ok, these two points are window-dressing: minor spelling and
          >punctuation issues (which seems to be what most language wars are about).
          >
          >Heck, use boost::python for C++ interfaces; those function names are
          >even shorter. Or use pyrex to generate wrappers, writing them in a
          >Pythonesque language.
          >[color=green]
          >> Many users of Io (myself included) have switched over from Python for
          >> these reasons.
          >>
          >> I guess there are still the obvious advantages of Python over Io,
          >> including
          >> *large community
          >> *more bindings to stuff[/color]
          >
          >Yep. That's a *big* difference, I'd say.[/color]

          Using any language (other than a Lisp) which is sufficiently powerful
          mostly comes down to personal preference regarding syntax. Library and
          community support will of course grow for new languages if enough
          people find it 'fits their minds' better than anything previously
          available.
          [color=blue]
          >[color=green]
          >> *strict coding conventions
          >> *inflexible so everything is the same[/color]
          >
          >Can you elaborate a bit on why Python is inflexible? I find Python to
          >be extremely flexible.[/color]

          If inflexibility means not being able to arbitrarily change the
          syntax, then I'm all for it, because it does help consistency and
          readability, which I like very much in my programs, especially when
          not working on them alone... Python seems to have found a good middle
          ground between strictness and dynamism.
          If I wanted a 'flexible' language, I'd use Lisp, or Forth.


          --
          Christopher

          Comment

          • Erik Max Francis

            #6
            Re: Python vs. Io

            Daniel Ehrenberg wrote:
            [color=blue]
            > Neither the each function nor the map function were built in (Io has
            > other mechanisms for that kind of thing, but they are less efficient).
            > Can anyone show me how to so much as alias "for" to "each" in Python
            > or allow block syntax at all without hacking the C source code?[/color]

            No, you cannot introduce new special forms (i.e., statement syntax) in
            Python without modifying the Python interpreter itself.

            There are two major camps in language design. One says that you should
            be able to modify the language itself to your will, and the other says
            that this gets rapidly confusing and you shouldn't. They're simply
            different camps, and the two camps won't agree. Furthermore, the
            ability to convert a language from the second camp to the first is not
            without difficulty; such things usually have to be designed into the
            language from the scratch, or you end up with a very complicated process
            of creating hygienic macros.

            This is a situation where Io is in the first camp and Python is in the
            second. They simply don't have equivalent goals; Python emphasizes
            transparency and readability more than customizability and flexibility,
            whereas Io does the opposite.
            [color=blue]
            > Io doesn't use __methods_with_ this_annoying_s yntax__ because nothing
            > is supposed to be for internal use only and there are only about three
            > functions that would cause a problem if overridden.
            >
            > For embedding, Io doesn't have to use Py_ALL_CAPS, instead it just
            > uses IoCamelCase, which looks much better. Interfaces to C are much
            > more object oriented.[/color]

            These are really stylistic objections, as are the other objections you
            list below. That's completely fine, of course; you should choose a
            language that jives with your personal sense of language style. But
            language designers need to make decisions, and those decisions are
            necessarily going to eliminate some styles of programming, while
            emphasizing others.

            You're in a situation where it sounds like Io jives with your sense of
            style more than Python. That's perfectly fine, and I know from my own
            research that Io is a neat little language (though I haven't really used
            it for anything substantial yet). But you can't expect other languages
            to bend to your personal will and personal sense of style, particularly
            when it means necessarily violating someone else's corresponding senses.

            Io and Python have quite different fundamental approaches to language
            design, and so it's not surprising that there are going to be
            irreconcilable differences.

            --
            __ Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
            / \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
            \__/ The only completely consistent people are the dead.
            -- Aldous Huxley

            Comment

            • Paul Prescod

              #7
              Re: Python vs. Io

              Daniel Ehrenberg wrote:
              [color=blue]
              > Io (www.iolanguage.com) is a new programming language that's purely
              > object-oriented (but with prototypes), has a powerful concurrency
              > mechanism via actors, and uses an extremely flexible syntax because
              > all code is a modifiable message tree.[/color]

              I long to live in a world where Python is considered a crufty incumbent
              legacy language that is forced on unwilling programmers by Pointy Haired
              Bosses. First, it would mean that Python has vanquished languages that
              programmers like less. Second, it would mean that the up-and-coming
              languages are so unbelievably cool and elegant that they make Python
              look like a lumbering dinosaur.

              Thanks for reminding me that that that day was once unfathomably far in
              the future and now seems almost around the corner!

              But when I look closer at IO it seems to me that the day is not as near
              as I hope. If you wish to hasten I urge you to:

              * finish the IO tutorial
              * distribute windows binaries of IO
              * make IO compilers to C and Java available
              * make bindings to popular windowing toolkits
              * make bindings to Java, .NET, COM, SOAP, XML-RPC etc.
              * use IO in a production context so that the rest of us can have faith
              in its stability
              * implement MySQL and Oracle bindings
              * publish some books on IO
              * point me to some documentation on how to launch and kill processes in IO

              If this were all done tomorrow I might be tempted to jump over to IO but
              I would be amazed if it were all done even two years from now.

              Also, an observation: IO's syntactic simplicity looks to me to be both a
              blessing and a curse.

              Paul Prescod



              Comment

              • Jonathan Daugherty

                #8
                Re: Python vs. Io

                As other posts have indicated, this is not the io-user-list. While
                you probably have good, purely academic intentions with your post,
                this is not the correct forum. Create an io-vs-python list somewhere
                and I'm sure you'll get a few subscribers. :)

                --

                Jonathan Daugherty
                cprogrammer.org is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, cprogrammer.org has it all. We hope you find what you are searching for!


                "It's a book about a Spanish guy called Manual, you should read it."
                -- Dilbert

                Comment

                • Josiah Carlson

                  #9
                  Re: Python vs. Io

                  Daniel Ehrenberg wrote:
                  [color=blue][color=green]
                  >>Perhaps it isn't more flexible. On the other hand, it does allow anyone
                  >>to read your code and know that there isn't any magical syntax that is
                  >>usable on one Python x.y installation, that isn't on another.
                  >>[/color][/color]

                  As mentioned by Sean Ross, I was talking about Python x.y compatibility
                  with other copies of version x.y. With the way you describe IO, it
                  encourages people to customize flow control and syntax. Such
                  customization does not necessarily increase readability, usability, or
                  write-once-run-anywhere with IO version u.v. It may also fragment the
                  language in the long run into different camps; those that like the slim
                  version, and those that like a version with every modification they can
                  find.

                  - Josiah

                  Comment

                  • Andrew Henshaw

                    #10
                    Re: Python vs. Io

                    Paul Prescod wrote:

                    ....snip...[color=blue]
                    > First, if I had invented Python I would not have bothered to buck the
                    > trend of using curly braces. Hardly anyone chooses Python because of
                    > that feature and some are turned off by it.[/color]
                    ....snip...


                    Not that this invalidates your point, as I still fall into the category of
                    'hardly anyone'; but, the indentation-identified block is precisely the
                    reason I first tried Python. Having used Occam for many years, I was very
                    pleased to find a language that recognized the superiority of that style.


                    --Andy

                    Comment

                    • A. Lloyd Flanagan

                      #11
                      Re: Python vs. Io

                      LittleDanEhren@ yahoo.com (Daniel Ehrenberg) wrote in message news:<711c7390. 0401291301.3f95 794@posting.goo gle.com>...[color=blue]
                      > Can anyone show me how to so much as alias "for" to "each" in Python
                      > or allow block syntax at all without hacking the C source code?
                      >[/color]

                      I think the point is, why on earth would you want to do something like
                      that? If you want a language you can use to make programs that make
                      no sense to anyone but the author, Perl should be more than sufficient
                      for your needs.

                      Comment

                      • Dang Griffith

                        #12
                        Re: Python vs. Io

                        On 29 Jan 2004 13:01:06 -0800, LittleDanEhren@ yahoo.com (Daniel
                        Ehrenberg) wrote:

                        ....[color=blue]
                        >Can anyone show me how to so much as alias "for" to "each" in Python
                        >or allow block syntax at all without hacking the C source code?[/color]
                        ....[color=blue]
                        >Many users of Io (myself included) have switched over from Python for
                        >these reasons.[/color]
                        If you've switch from Python to Io, what will you do with the answers
                        to these questions? Use them for good or evil? Will you switch back
                        from Io to Python?
                        --dang

                        Comment

                        • Terry Carroll

                          #13
                          Re: Python vs. Io

                          On Sun, 01 Feb 2004 13:47:20 -0800, Paul Prescod <paul@prescod.n et> wrote:
                          [color=blue]
                          >First, if I had invented Python I would not have bothered to buck the
                          >trend of using curly braces. Hardly anyone chooses Python because of
                          >that feature and some are turned off by it.[/color]

                          I have to admit that the indentation feature turned me off at first, but
                          having used Python for a while now, I find that method superior to the
                          curly braces approach. Much more DWIM.

                          Comment

                          • John Roth

                            #14
                            Re: Python vs. Io

                            "Paul Prescod" <paul@prescod.n et> wrote in message
                            news:mailman.11 10.1075672228.1 2720.python-list@python.org ...[color=blue]
                            > First, if I had invented Python I would not have bothered to buck the
                            > trend of using curly braces.[/color]

                            I suppose I am hardly anyone else, since that it exactly what
                            attracted me to Python. In fact, I will take partial responsibility
                            for the indentaion syntax in IBM's ISPF mini-language - it's a
                            preferance of long standing with me.

                            Now that I actually have a significant language using them, I
                            can see that there are a couple of things they make more
                            difficult, statement syntax embedded within expressions being
                            one. The other is a rather esoteric issue with clauses like
                            elif, else and except.

                            John Roth
                            [color=blue]
                            >
                            > Paul Prescod
                            >
                            >
                            >[/color]


                            Comment

                            • Hannu Kankaanp??

                              #15
                              Re: Python vs. Io

                              alloydflanagan@ comcast.net (A. Lloyd Flanagan) wrote in message news:<e838aa6e. 0402020730.3d45 c9b1@posting.go ogle.com>...[color=blue]
                              > LittleDanEhren@ yahoo.com (Daniel Ehrenberg) wrote in message news:<711c7390. 0401291301.3f95 794@posting.goo gle.com>...[color=green]
                              > > Can anyone show me how to so much as alias "for" to "each" in Python
                              > > or allow block syntax at all without hacking the C source code?
                              > >[/color]
                              > I think the point is, why on earth would you want to do something like
                              > that? If you want a language you can use to make programs that make
                              > no sense to anyone but the author, Perl should be more than sufficient
                              > for your needs.[/color]

                              The point is that implementing your own "for" is something you can't
                              do in Python very nicely, so it's a proof that Io can achieve
                              genuinely higher abstraction levels on this part. Implementing
                              "for" again with a new name probably wouldn't make anyone
                              happy, but such power opens a set of tricks and idioms to
                              be used in real code to solve real problems, that wouldn't
                              be possible in Python without kludgy syntax.

                              Here's a normal loop:

                              bar = 0
                              for x in range(10):
                              bar += x

                              Here's the same using a custom loop:

                              bar = [0]
                              def temp(x):
                              bar[0] += x
                              for_each(range( 10), temp)

                              That is just so damn ugly. I want to be able to define (e.g.)

                              bar = 0
                              for_each(x, range(10)):
                              bar += x

                              Now tell me which of these two lowermost forms looks
                              better and makes more sense? For examples that don't
                              just make aliases of existing syntax, see the
                              Lisp vs Python thread that was here a few months ago
                              (sorry, can't remember it's topic name).

                              BTW, Python can be used to make programs that make
                              no sense as well. (due to Ulf Bartelt:)

                              print (lambda Ru,Ro,Iu,Io,IM, Sx,Sy:reduce(la mbda x,y:x+y,map(lam bda y,
                              Iu=Iu,Io=Io,Ru= Ru,Ro=Ro,Sy=Sy, L=lambda yc,Iu=Iu,Io=Io, Ru=Ru,Ro=Ro,i=I M,
                              Sx=Sx,Sy=Sy:red uce(lambda x,y:x+y,map(lam bda x,xc=Ru,yc=yc,R u=Ru,Ro=Ro,
                              i=i,Sx=Sx,F=lam bda xc,yc,x,y,k,f=l ambda xc,yc,x,y,k,f:( k<=0)or (x*x+y*y[color=blue]
                              >=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+ yc,k-1,f):f(xc,yc,x, y,k,f):chr([/color]
                              64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),r ange(Sx))):L(Iu +y*(Io-Iu)/Sy),range(Sy
                              ))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)

                              The real question is if the language *allows* a sensible
                              programmer to write clear, understandable code even in hard
                              problem domains.

                              But this is nothing but my humble opinion without actually
                              knowing anything about Io.. Maybe it isn't that good. I wasn't
                              really arguing for Io but for better abstractions.

                              Comment

                              Working...