Python syntax in Lisp and Scheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike420@ziplip.com

    Python syntax in Lisp and Scheme

    I think everyone who used Python will agree that its syntax is
    the best thing going for it. It is very readable and easy
    for everyone to learn. But, Python does not a have very good
    macro capabilities, unfortunately. I'd like to know if it may
    be possible to add a powerful macro system to Python, while
    keeping its amazing syntax, and if it could be possible to
    add Pythonistic syntax to Lisp or Scheme, while keeping all
    of the functionality and convenience. If the answer is yes,
    would many Python programmers switch to Lisp or Scheme if
    they were offered identation-based syntax?
  • Paul Rubin

    #2
    Re: Python syntax in Lisp and Scheme

    mike420@ziplip. com writes:[color=blue]
    > If the answer is yes, would many Python programmers switch to Lisp
    > or Scheme if they were offered identation-based syntax?[/color]

    I don't think the syntax is that big a deal. But programming in lisp
    or scheme has a creaky feeling these days, because the traditional
    runtime libraries in those languages have fallen so far behind the
    times.

    Comment

    • Dominic

      #3
      Re: Python syntax in Lisp and Scheme

      mike420@ziplip. com wrote:[color=blue]
      > I think everyone who used Python will agree that its syntax is
      > the best thing going for it. It is very readable and easy
      > for everyone to learn. But, Python does not a have very good
      > macro capabilities, unfortunately. I'd like to know if it may
      > be possible to add a powerful macro system to Python, while
      > keeping its amazing syntax, and if it could be possible to
      > add Pythonistic syntax to Lisp or Scheme, while keeping all
      > of the functionality and convenience. If the answer is yes,
      > would many Python programmers switch to Lisp or Scheme if
      > they were offered identation-based syntax?[/color]

      Well, there's always a programming language which has
      more features than another. However documentation,
      libraries, software-engineering tools and developer
      community have also to be accounted for.

      So whenever a special features is deemed necessary
      but not available in the language I suggest to use
      code generators.

      E.g. you cannot express grammars in C/Java for
      parsing so usually you stick to yacc/bison/flex/cups etc.

      In C++ BOOST provides capabilites to express a parser
      by means of template metaprogramming but compile times
      are huge. In my opinion are old fashioned parser
      generators more transparent.
      So it's probably not worth the trouble.

      I have successfuly implemented a simple code generator
      for real-time control applications in Python
      which outputs C-source.


      Today I'd suggest to use XML-files to describe
      the problem and generate source code from it.
      Source code needed for assembling the final
      result could also be embedded into the XML-files.

      Eclipse uses a kind of JSP to generate code
      from templates. (Examples exist
      for generating source code for enumerations
      which are not yet supported by Java)
      However it's still very primitive.
      At the rapid pace at which Eclipse
      is developed I am curious what way it is going to take.


      Ciao,
      Dominic





      Comment

      • prunesquallor@comcast.net

        #4
        Re: Python syntax in Lisp and Scheme

        mike420@ziplip. com writes:
        [color=blue]
        > I think everyone who used Python will agree that its syntax is
        > the best thing going for it.[/color]

        I've used Python. I don't agree.
        [color=blue]
        > It is very readable and easy
        > for everyone to learn. But, Python does not a have very good
        > macro capabilities, unfortunately. I'd like to know if it may
        > be possible to add a powerful macro system to Python, while
        > keeping its amazing syntax, and if it could be possible to
        > add Pythonistic syntax to Lisp or Scheme, while keeping all
        > of the functionality and convenience. If the answer is yes,
        > would many Python programmers switch to Lisp or Scheme if
        > they were offered identation-based syntax?[/color]

        Yes, you would be able to add macros to Python. No, it isn't anywhere
        as easy as it is with Lisp.

        I imagine you could come up with a readtable hack for reading
        pythonesque syntax in lisp. *shudder*

        Comment

        • Oren Tirosh

          #5
          Re: Python syntax in Lisp and Scheme

          On Thu, Oct 02, 2003 at 10:23:16PM -0700, mike420@ziplip. com wrote:[color=blue]
          > I think everyone who used Python will agree that its syntax is
          > the best thing going for it. It is very readable and easy
          > for everyone to learn. But, Python does not a have very good
          > macro capabilities, unfortunately. I'd like to know if it may
          > be possible to add a powerful macro system to Python, while
          > keeping its amazing syntax, and if it could be possible to
          > add Pythonistic syntax to Lisp or Scheme, while keeping all
          > of the functionality and convenience. If the answer is yes,
          > would many Python programmers switch to Lisp or Scheme if
          > they were offered identation-based syntax?[/color]

          Search the comp.lang.pytho n archives for the word "macros" and you will
          find lots and lots of threads discussing this issue over the years. The
          concensus seems to be that macros are neither compatible with the Python
          Way nor necessary for the vast majority of everyday programming tasks.

          Implementing Python-like syntax in LISP or even a full Python
          implementation in LISP would be a worthwhile goal (LPython?). BTW, this
          kind of implementation is one of the relatively few programming tasks
          that can benefit greatly from macros. The Python semantics can be mostly
          done using macros and a preprocessor would translated Python syntax to
          s-expression code that uses those macros.

          Oren

          Comment

          • Tomasz Zielonka

            #6
            Re: Python syntax in Lisp and Scheme

            mike420@ziplip. com napisa³:[color=blue]
            > I think everyone who used Python will agree that its syntax is
            > the best thing going for it. It is very readable and easy
            > for everyone to learn. But, Python does not a have very good
            > macro capabilities, unfortunately.[/color]

            Well, there is Haskell which also offers indentation-base syntax and one
            of it's compilers (GHC) recently added the Template Haskell extension.

            This is a statically typed, non-strict purely functional language with
            higher order and polymorphic functions, algebraic datatypes, etc. so
            it's a BIT different than Python, but it's worth trying :)

            PS. Haskell also allows to use {, } and ; instead of indentation. I
            wonder why Python doesn't.

            Best regards,
            Tom

            --
            ..signature: Too many levels of symbolic links

            Comment

            • Tomasz Zielonka

              #7
              Re: Python syntax in Lisp and Scheme

              mike420@ziplip. com napisa³:[color=blue]
              > I think everyone who used Python will agree that its syntax is
              > the best thing going for it. It is very readable and easy
              > for everyone to learn. But, Python does not a have very good
              > macro capabilities, unfortunately.[/color]

              Well, there is Haskell which also offers indentation-based syntax and one
              of its compilers (GHC) recently added the Template Haskell extension.

              This is a statically typed, non-strict, purely functional language with
              higher order and polymorphic functions, algebraic datatypes,
              type-classes base overloading, etc. so it's a BIT different than Python,
              but it's worth trying IMO.
              :)

              PS. Haskell also allows to use {, } and ; instead of indentation. I
              wonder why Python doesn't.

              Best regards,
              Tom

              --
              ..signature: Too many levels of symbolic links

              Comment

              • Tomasz Zielonka

                #8
                Re: Python syntax in Lisp and Scheme

                mike420@ziplip. com napisa³:[color=blue]
                > I think everyone who used Python will agree that its syntax is
                > the best thing going for it. It is very readable and easy
                > for everyone to learn. But, Python does not a have very good
                > macro capabilities, unfortunately.[/color]

                Well, there is Haskell which also offers indentation-based syntax and
                one
                of its compilers (GHC) recently added the Template Haskell extension.

                This is a statically typed, non-strict, purely functional language with
                higher order and polymorphic functions, algebraic datatypes,
                type-class based overloading, etc. so it's a BIT different than Python,
                but it's worth trying IMO :)

                PS. Haskell also allows to use {, } and ; instead of indentation. I
                wonder why Python doesn't.

                Best regards,
                Tom

                --
                ..signature: Too many levels of symbolic links

                Comment

                • Jeremy Yallop

                  #9
                  Re: Python syntax in Lisp and Scheme

                  Tomasz Zielonka wrote:[color=blue]
                  > mike420@ziplip. com napisa³:[color=green]
                  >> I think everyone who used Python will agree that its syntax is
                  >> the best thing going for it.[/color][/color]

                  I've used Python rather a lot, and I don't agree with this, FWIW.
                  [color=blue]
                  > PS. Haskell also allows to use {, } and ; instead of indentation. I
                  > wonder why Python doesn't.[/color]



                  Jeremy.

                  Comment

                  • Tomasz Zielonka

                    #10
                    Re: Python syntax in Lisp and Scheme

                    Jeremy Yallop wrote:[color=blue][color=green]
                    >> PS. Haskell also allows to use {, } and ; instead of indentation. I
                    >> wonder why Python doesn't.[/color]
                    >
                    > http://groups.google.com/groups?as_u....eeel.nist.gov[/color]

                    A state of the art sophisticated parser? :)))

                    You almost got me. I don't know very much about Python and I had to
                    check that # is a beginning of a comment.

                    Do you know the meaning of 'instead of' ?

                    You still have to use indentation, right? You can't write:

                    if 1: #{ print 2 #} else: #{ print 3 #}

                    instead of

                    if 1: #{
                    print 2
                    #}
                    else: #{
                    print 3
                    #}

                    because that would be read as

                    if 1:
                    [color=blue]
                    > Jeremy.[/color]

                    Best regards,
                    Tom

                    --
                    ..signature: Too many levels of symbolic links

                    Comment

                    • Mark Brady

                      #11
                      Re: Python syntax in Lisp and Scheme

                      This whole thread is a bad idea. If you like python then use python.
                      Personally I find Scheme and Common Lisp easier to read but that's
                      just me, I prefer S-exps and there seems to be a rebirth in the Scheme
                      and Common Lisp communities at the moment. Ironically this seems to
                      have been helped by python. I learned python then got interested in
                      it's functional side and ended up learning Scheme and Common Lisp. A
                      lot of new Scheme and Common Lisp developers I talk to followed the
                      same route. Python is a great language and I still use it for some
                      things.

                      Paul Rubin's comments are just pure fud.

                      Some great scheme implementations with large modern libraries (not yet
                      a match for python but growing fast):



                      Download SISC for free. SISC is an extensible Java based interpreter of the algorithmic language Scheme. SISC uses modern interpretation techniques, and handily outperforms all existing Java interpreters (often by more than an order of magnitude).

                      Scheme programming and Scheme language tools and documentation: Chez Scheme, Petite Chez Scheme, the Scheme Widget Library, The Scheme Programming Language, and the Chez Scheme User's Guide


                      Common Lisp has a fantastic wiki site (links to implementations and
                      loads of libraries) with everything you need to get started at:


                      Also see:




                      Many of the latest Scheme and Lisp mailing lists can be browsed from:


                      Develop in the language that suits you but despite the fud you do have
                      a choice,
                      Python, Scheme and Common Lisp are all fine languages with good
                      libraries and FFI capabilities.

                      Regards,
                      Mark.



                      Paul Rubin <http://phr.cx@NOSPAM.i nvalid> wrote in message news:<7xvfr6lvh 6.fsf@ruckus.br ouhaha.com>...[color=blue]
                      > mike420@ziplip. com writes:[color=green]
                      > > If the answer is yes, would many Python programmers switch to Lisp
                      > > or Scheme if they were offered identation-based syntax?[/color]
                      >
                      > I don't think the syntax is that big a deal. But programming in lisp
                      > or scheme has a creaky feeling these days, because the traditional
                      > runtime libraries in those languages have fallen so far behind the
                      > times.[/color]

                      Comment

                      • Matthias

                        #12
                        Re: Python syntax in Lisp and Scheme

                        kalath@lycos.co m (Mark Brady) writes:[color=blue]
                        > Paul Rubin's comments are just pure fud.[/color]
                        [...][color=blue]
                        > Develop in the language that suits you but despite the fud you do have
                        > a choice,
                        > Python, Scheme and Common Lisp are all fine languages with good
                        > libraries and FFI capabilities.[/color]

                        I think that's incorrect: The Common Lisp language has no FFI (foreign
                        function call) capabilities. Each CL _implementation _ has one (which
                        is usually compatible to itself). This is exactly the reason why
                        there are way more libraries out there for Python, Perl, maybe Ruby
                        than for any single CL implementation. The same probably holds for
                        Scheme.

                        Comment

                        • Toni Nikkanen

                          #13
                          Re: Python syntax in Lisp and Scheme

                          kalath@lycos.co m (Mark Brady) writes:
                          [color=blue]
                          > just me, I prefer S-exps and there seems to be a rebirth in the Scheme
                          > and Common Lisp communities at the moment. Ironically this seems to
                          > have been helped by python. I learned python then got interested in
                          > it's functional side and ended up learning Scheme and Common Lisp.[/color]

                          It's be interesting to know where people got the idea of learning
                          Scheme/LISP from (apart from compulsory university courses)? I think
                          that for me, it was the LPC language used in LPmuds. It had a
                          frightening feature called lambda closures, and useful functions such
                          as map and filter. Then one day I just decided to bite the bullet and
                          find out where the heck all that stuff came from (my background was
                          strongly in C-like languages at that point. LPC is like C with some
                          object-oriented and some FP features.)

                          Yes, I know, there's nothing frightening in lambda closures. But the
                          way they were implemented in LPC (actually just the syntax) was
                          terrible :)

                          Comment

                          • Alex Martelli

                            #14
                            Re: Python syntax in Lisp and Scheme

                            mike420@ziplip. com wrote:
                            [color=blue]
                            > I think everyone who used Python will agree that its syntax is
                            > the best thing going for it. It is very readable and easy
                            > for everyone to learn. But, Python does not a have very good
                            > macro capabilities, unfortunately. I'd like to know if it may
                            > be possible to add a powerful macro system to Python, while
                            > keeping its amazing syntax, and if it could be possible to[/color]

                            You can surely hack a "pre-processor" on top of the Python
                            interpreter. With the Python 2.3 architecture of import
                            hooks, it might even be quite feasible to experiment with
                            this idea as a pure Python package and distribute it as such:
                            just add a hook that scans incoming source files (modules)
                            for definitions and/or occurrences of the 'macros' you want,
                            and (respectively) squirrels away the definitions, and/or
                            expands the macros. As for designing the syntax for macro
                            definitions and expansions while remaining 'amazing', I'll
                            pass -- but surely it's not beyond human possibilities;-).

                            Anyway, see later in this post for a toy-level example.

                            [color=blue]
                            > add Pythonistic syntax to Lisp or Scheme, while keeping all
                            > of the functionality and convenience. If the answer is yes,
                            > would many Python programmers switch to Lisp or Scheme if
                            > they were offered identation-based syntax?[/color]

                            If you could make all of the existing Python extensions,
                            libraries, frameworks, etc, instantly available from Lisp or
                            Scheme, you'd gain a LOT of kudos in the Lisp or Scheme
                            community, I suspect. That most existing Python coders
                            would be happy to leave the semantic simplicity of their
                            chosen language for the richness of Common Lisp, I very,
                            very strongly doubt, but in any case until the whole array
                            of existing extensions &c is available it's not an issue;-).


                            So, anyway, here's the promised toy-level example of using
                            custom importers with the new Python 2.3 mechanics to get
                            macros. I'm cutting corners to the bone (just to mix a
                            couple metaphors...) by using the C preprocessor (!) as my
                            "macro expander", ignoring packages, _and_ only looking for
                            "C-macro" definitions AND expansions in files with extension
                            ".pyp" (all others, I'll leave alone...). Oh, also, I do
                            not worry about saving bytecode for such files -- I'm gonna
                            preprocess and recompile them on every run of the program
                            (far too much trouble, when macros exist, to determine
                            whether a bytecode file is up to date -- one should check
                            it, not only with respect to the date of ONE source file,
                            but rather of a hard-to-pin-down collection of macro and
                            include files... so, in the spirit of cutting corners and
                            keeping this a VERY toy-level example, I'm punting:-). So,
                            here's the gist...:


                            import sys
                            import os
                            import imp

                            prepro = 'cat %s | gcc -E -'

                            class MacroImporter(o bject):

                            def __init__(self, path):
                            self.path = path

                            def find_module(sel f, modname):
                            look_for_file = os.path.join(se lf.path, modname+'.pyp')
                            self.code = os.popen(prepro % look_for_file). read()
                            if self.code: return self
                            else: return None

                            def load_module(sel f, modname):
                            mod = imp.new_module( modname)
                            sys.modules[modname] = mod
                            mod.__file__ = "<Macro-Expanded %s>" % modname
                            exec self.code in mod.__dict__
                            return mod

                            sys.path_hooks. append(MacroImp orter)

                            example = open('pippo.pyp ', 'w')
                            example.write(' ''
                            #define unless(cond) if not(cond)
                            def pippo(x):
                            print 'x is', x
                            unless(x>=2): print ' x is smaller than two'
                            unless(x<=4): print ' x is bigger than four'
                            ''')
                            example.close()

                            import pippo
                            pippo.pippo(1)
                            pippo.pippo(7)


                            Removing the various oversimplificat ions, and, in particular, designing
                            a better macro scheme than gcc -E supplies, is left as a trivial exercise
                            for the reader (I have in fact devised a perfect scheme, of course, but,
                            unfortunately, the margins of this post are too narrow for me to write it
                            down...).


                            Alex

                            Comment

                            • Paul Foley

                              #15
                              Re: Python syntax in Lisp and Scheme

                              On 03 Oct 2003 14:44:36 +0300, Toni Nikkanen wrote:
                              [color=blue]
                              > kalath@lycos.co m (Mark Brady) writes:[color=green]
                              >> just me, I prefer S-exps and there seems to be a rebirth in the Scheme
                              >> and Common Lisp communities at the moment. Ironically this seems to
                              >> have been helped by python. I learned python then got interested in
                              >> it's functional side and ended up learning Scheme and Common Lisp.[/color][/color]
                              [color=blue]
                              > It's be interesting to know where people got the idea of learning
                              > Scheme/LISP from (apart from compulsory university courses)?[/color]

                              Try http://alu.cliki.net/The%20Road%20To%20Lisp%20Survey

                              --
                              Cogito ergo I'm right and you're wrong. -- Blair Houghton

                              (setq reply-to
                              (concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz> "))

                              Comment

                              Working...