Python syntax in Lisp and Scheme

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Brady

    #31
    Re: Python syntax in Lisp and Scheme

    "Terry Reedy" <tjreedy@udel.e du> wrote in message news:<7wednSJ_q _L85uCiXTWJhQ@c omcast.com>...[color=blue]
    > "Mark Brady" <kalath@lycos.c om> wrote in message
    > news:e840346c.0 310030302.6be0c 378@posting.goo gle.com...[color=green]
    > > This whole thread is a bad idea.[/color]
    >
    > I could agree that the OP's suggestion is a bad idea but do you
    > actually think that discussion and more publicity here for Lisp/Scheme
    > is bad? You make a pretty good pitch below for more Python=>Lisp
    > converts.
    >[/color]

    You are right of course, however I dislike cross posting and I also
    dislike blatantly arguing with people over language choice. I would
    prefer to lead by example. I think one good program is worth a
    thousand words. For example people listen to Paul Graham
    (http://www.paulgraham.com/avg.html) when he advocates Common Lisp
    because he wrote Viaweb using it and made a fortune thanks to Lisp's
    features (details in the link).
    [color=blue][color=green]
    > > If you like python then use python.[/color]
    >
    > As I plan to do.
    >[/color]

    Nothing wrong with that. Most people on these groups would agree that
    Python is a very good choice for a wide range of software projects and
    it is getting better with every release.

    I think that if you can get over S-exps then Scheme and Common Lisp
    feel very like python. I would recommend Pythonistas to at least
    experiment with Common Lisp or Scheme even if you are perfectly happy
    with Python. After all you have nothing to lose. If you don't like it
    then fine you always have Python and you've probably learned something
    and if you do like it then you have another language or two under your
    belt.

    [color=blue][color=green]
    > > 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[/color]
    > cheme[color=green]
    > > 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.[/color]
    >
    > Other Lispers posting here have gone to pains to state that Scheme is
    > not a dialect of Lisp but a separate Lisp-like language. Could you
    > give a short listing of the current main differences (S vs. CL)? If I
    > were to decide to expand my knowledge be exploring the current
    > versions of one(I've read the original SICP and LISP books), on what
    > basis might I make a choice?
    >
    > Terry J. Reedy[/color]


    This is a difficult question to answer. It's a bit like trying to
    explain the differences between Ruby and Python to a Java developer
    ;-)

    *Personally* I find it best to think of Scheme and Common Lisp as two
    different but very closely related languages. The actual languages and
    communities are quite different.

    Common Lisp is a large, very pragmatic, industrial strength language
    and its community reflects this. Common Lisp has loads of features
    that you would normally only get in add on libraries built right into
    the language, it's object
    system "CLOS" has to be experienced to be believed and its macro
    system is stunning. Some very smart people have already put years of
    effort into making it capable of great things such as Nasa's award
    winning remote agent software
    (http://ic.arc.nasa.gov/projects/remote-agent/).

    Scheme is a more functional language and unlike Common Lisp is has a
    single namespace for functions and variables (Python is like Scheme in
    this regard). Common Lisp can be just as functional but on the whole
    the Scheme community seem to embrace functional programming to a
    greater extend.

    Scheme is like python in that the actual language is quite small and
    uses libraries for many of the same tasks Python would use them for,
    unlike Common Lisp that has many of these features built into the
    language. It also has a great but slightly different macro system
    although every implementation I know also has Common Lisp style
    Macros.

    Scheme doesn't have a standard object system (it's more functional)
    but has libraries to provide object systems. This is very hard to
    explain to python developers, scheme is kind of like a big python
    metaclass engine where different object systems can be used at will.
    It's better than I can describe and it is really like a more powerful
    version of Pythons metaclass system.

    Pythonistas who love functional programming may prefer Scheme to
    Common Lisp while Pythonistas who want a standard amazing object
    system and loads of built in power in their language may prefer Common
    Lisp.

    To be honest the these tutorials will do a far better job than I
    could:

    For Scheme get DrScheme:


    and go to

    'Teach yourself scheme in fixnum days' :



    For Common Lisp get the trial version of Lispworks:


    and go get Mark Watsons free web book:


    Regards,
    Mark.

    Ps. If anyone spots a mistake in this mail please correct me, it will
    have been an honest one and not an attempt to slander your favourite
    language and I will be glad to be corrected, in other words there is
    no need to flame me :)

    Comment

    • Edi Weitz

      #32
      Re: Python syntax in Lisp and Scheme

      On 03 Oct 2003 13:37:32 +0200, Matthias <no@spam.pls> wrote:
      [color=blue]
      > 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.[/color]

      I'd say the Python /language/ also has no FFI capabilities. Either
      that, or the Jython people are lying when they say that Jython "is an
      implementation of the [...] language Python." (On the same website:
      "Many of these modules are not yet implemented. Those coded in C for
      CPython must be re-implemented in Java for Jython.")

      Common Lisp and Scheme are languages defined by ANSI standards -
      that's why you can have different implementations . Python, Perl, and
      Ruby are defined by a reference implementation. You're comparing
      apples and oranges.

      Edi.

      Comment

      • MetalOne

        #33
        Re: Python syntax in Lisp and Scheme

        kalath@lycos.co m (Mark Brady) wrote in message news:<e840346c. 0310030302.6be0 c378@posting.go ogle.com>...[color=blue]
        > Personally I find Scheme and Common Lisp easier to read but that's
        > just me, I prefer S-exps ...[/color]

        I am just barely familiar with Lisp and Scheme. However, I always
        find comments like the above interesting. I have seen other people
        make this claim also.
        However, from an earlier post on comp.lang.pytho n comparing a simple
        loop.

        Scheme
        (define vector-fill!
        (lambda (v x)
        (let ((n (vector-length v)))
        (do ((i 0 (+ i 1)))
        ((= i n))
        (vector-set! v i x)))))

        Python
        def vector_fill(v, x):
        for i in range(len(v)):
        v[i] = x

        To me the Python code is easier to read, and I can't possibly fathom
        how somebody could think the Scheme code is easier to read. It truly
        boggles my mind.

        The second thing that puzzles me is the usage of the LISP macro
        system. This system is touted as one of LISPs major strengths. I
        believe the "Do" above is a macro. Is that the best syntax that can
        be achieved with a macro for "Do". I would think there would already
        be macros to write the Scheme code above in a format similar to the
        Python code below, or some more readable syntax. I have looked for
        repositories of such macros and I can't find any. This leads me to
        think that in practice LISP macros are not used. Couple this with the
        fact that LISP programmers seem happier with S-exprs, and I can't see
        why a LISP programmer would even want to write a macro.

        I have tried on 3 occassions to become a LISP programmer, based upon
        the constant touting of LISP as a more powerful language and that
        ultimately S-exprs are a better syntax. Each time, I have been
        stopped because the S-expr syntax makes we want to vomit.

        If a set of macros could be written to improve LISP syntax, then I
        think that might be an amazing thing. An interesting question to me
        is why hasn't this already been done.

        Comment

        • felix

          #34
          Re: Python syntax in Lisp and Scheme

          On 03 Oct 2003 11:25:31 -0400, Jeremy H. Brown <jhbrown@ai.mit .edu> wrote:
          [color=blue]
          > I'm sure if you do some web-groveling, you can find some substantial
          > comparisons of the two; I personally think they have more in common
          > than not. Here are a few of the (arguably) notable differences:
          >
          > Scheme Common Lisp[/color]
          [color=blue]
          > Namespaces one two (functions, variables)[/color]

          Common Lisp has actually more than two namespaces.
          [color=blue]
          > Implementations >10 ~4[/color]

          There are loads more.
          [color=blue]
          > Performance "worse" "better"[/color]

          Nonsense.
          [color=blue]
          > Support Community Academic Applications writers[/color]

          Also nonsense.
          [color=blue]
          >
          > Try them both, see which one works for you in what you're doing.
          >[/color]

          Very good point.


          cheers,
          felix

          Comment

          • Alex Martelli

            #35
            Re: Python syntax in Lisp and Scheme

            Mark Brady wrote:
            ...[color=blue]
            > This is a difficult question to answer. It's a bit like trying to
            > explain the differences between Ruby and Python to a Java developer
            > ;-)[/color]

            Been there, done that, it's not all _that_ difficult. The average Java
            developer is quite able to understand the differences if you explain them
            in terms of similarities and differences from Lisp ("Python has immutable
            strings like Java, while Ruby's strings are mutable; Ruby has single
            inheritance like Java, plus mix-ins, while Python has multiple inheritance,
            with certain limitations", etc) and ability to interoperate ("Python has an
            implementation that runs on a JVM, uses any Java class, and can generate
            ..class and .jar files just as if you had coded in Java, Ruby doesn't").

            I think the "cultural" differences are subtler and more interesting (and
            also, no doubt, even more debatable:-) -- the distinction between a Python
            culture that takes pride in simplicity, uniformity, and avoidance of clever
            tricks, versus a Ruby one that's quite different in these regards, IMHO.

            Similarly, I suspect (but with even less reason to believe my observations
            are correct) that the concept of a language being small and simple may be a
            source of pride to the Scheme crowd (as it is, say, to the Python or C
            ones), while that of a language being large and comprehensive may appeal to
            Common Lispers (as it does, say, to C++ites or Perlmongers).

            Such "soft-sciences" considerations may help guide one's choices about what
            language to study next, I believe. E.g., a Pythonista who's looking for a
            brisk "change of pace" might be more likely to find it in large-language
            Common Lisp, while one who's looking for another "small, simple language"
            culture might be more likely to find it in Scheme.


            Alex

            Comment

            • Peter Seibel

              #36
              Re: Python syntax in Lisp and Scheme

              jcb@iteris.com (MetalOne) writes:
              [color=blue]
              > kalath@lycos.co m (Mark Brady) wrote in message news:<e840346c. 0310030302.6be0 c378@posting.go ogle.com>...[color=green]
              > > Personally I find Scheme and Common Lisp easier to read but that's
              > > just me, I prefer S-exps ...[/color]
              >
              > I am just barely familiar with Lisp and Scheme. However, I always
              > find comments like the above interesting. I have seen other people
              > make this claim also. However, from an earlier post on
              > comp.lang.pytho n comparing a simple loop.
              >
              > Scheme
              > (define vector-fill!
              > (lambda (v x)
              > (let ((n (vector-length v)))
              > (do ((i 0 (+ i 1)))
              > ((= i n))
              > (vector-set! v i x)))))
              >
              > Python
              > def vector_fill(v, x):
              > for i in range(len(v)):
              > v[i] = x
              >
              > To me the Python code is easier to read, and I can't possibly fathom
              > how somebody could think the Scheme code is easier to read. It truly
              > boggles my mind.[/color]

              Well, over in comp.lang.lisp (where we speak Common Lisp, more so than
              Scheme) we might write that:

              (defun vector-fill (v x)
              (dotimes (i (length v)) (setf (aref v i) x)))

              or

              (defun vector-fill (v x)
              (loop for i below (length v)
              do (setf (aref v i) x))) (defun vector-fill (v x)


              which seems pretty similar to the Python version.

              (If of course we didn't already have the FILL function that does just
              that.)
              [color=blue]
              > The second thing that puzzles me is the usage of the LISP macro
              > system. This system is touted as one of LISPs major strengths. I
              > believe the "Do" above is a macro. Is that the best syntax that can
              > be achieved with a macro for "Do".[/color]

              Nope. Common Lisp includes the standard macros DOTIMES and LOOP as
              shown above.
              [color=blue]
              > I would think there would already be macros to write the Scheme code
              > above in a format similar to the Python code below, or some more
              > readable syntax. I have looked for repositories of such macros and I
              > can't find any.[/color]

              I'm sure the Scheme folks will tell you were you can find such
              repositories for Scheme. But Common Lisp has them built in.
              [color=blue]
              > This leads me to think that in practice LISP macros are not used.[/color]

              That is decidedly not true of Common Lisp.
              [color=blue]
              > Couple this with the fact that LISP programmers seem happier with
              > S-exprs, and I can't see why a LISP programmer would even want to
              > write a macro.[/color]

              Well, macros aren't intended to get you away from s-exps though the
              LOOP macro does to a certain extent. They are just intended to get you
              to more to-the-point s-exps. You put your finger right on it when you
              wondered why there wasn't a better way to write your loop than DO. If
              DOTIMES didn't already exist, you'd write it as a macro that expands
              into DO. That is: DO is a almost completely general looping construct
              which makes it more than you want in a lot of situations. Macros let
              you turn what you want to write (DOTIMES) into the right version of
              the more general, more powerful construct (DO).
              [color=blue]
              > I have tried on 3 occassions to become a LISP programmer, based upon
              > the constant touting of LISP as a more powerful language and that
              > ultimately S-exprs are a better syntax. Each time, I have been
              > stopped because the S-expr syntax makes we want to vomit.[/color]

              Hmmm. If all three of those times have been with Scheme, you might
              want to try Common Lisp for a change of pace.
              [color=blue]
              > If a set of macros could be written to improve LISP syntax, then I
              > think that might be an amazing thing. An interesting question to me
              > is why hasn't this already been done.[/color]

              Some (including me) would argue it has. They just don't define
              "improve" as "get rid of all sexps".

              -Peter

              --
              Peter Seibel peter@javamonke y.com

              Lisp is the red pill. -- John Fraser, comp.lang.lisp

              Comment

              • Frode Vatvedt Fjeld

                #37
                Re: Python syntax in Lisp and Scheme

                jcb@iteris.com (MetalOne) writes:
                [color=blue]
                > [..] However, from an earlier post on comp.lang.pytho n comparing a
                > simple loop.
                >
                > Scheme
                > (define vector-fill!
                > (lambda (v x)
                > (let ((n (vector-length v)))
                > (do ((i 0 (+ i 1)))
                > ((= i n))
                > (vector-set! v i x)))))
                >
                > Python
                > def vector_fill(v, x):
                > for i in range(len(v)):
                > v[i] = x
                >
                > To me the Python code is easier to read, and I can't possibly fathom
                > how somebody could think the Scheme code is easier to read. It truly
                > boggles my mind. [..][/color]

                The scheme example can only have been written by someone who is on the
                outset determined to demonstrate that sexp-syntax is complicated. This
                is how I'd write it in Common Lisp:

                (defun vector-fill (v x)
                (dotimes (i (length v))
                (setf (aref v i) x)))

                As you can see, it matches the python example quite closely.
                [color=blue]
                > [..] If a set of macros could be written to improve LISP syntax,
                > then I think that might be an amazing thing. An interesting
                > question to me is why hasn't this already been done.[/color]

                Lisp macros and syntactic abstractions are one of those things whose
                power and elegance it is somewhat hard to explain to those who have
                not experienced it themselves first hand. Paul Graham's book "On Lisp"
                is considered by many to be a good introduction to the subject.

                I am quite comforatble with Common Lisp's syntax, and I see no
                particular need for some set of macros to improve its syntax. In fact
                I have no idea what so ever as to what such a set of macros would look
                like.

                --
                Frode Vatvedt Fjeld

                Comment

                • Paul Rubin

                  #38
                  Re: Python syntax in Lisp and Scheme

                  jcb@iteris.com (MetalOne) writes:[color=blue]
                  > Scheme
                  > (define vector-fill!
                  > (lambda (v x)
                  > (let ((n (vector-length v)))
                  > (do ((i 0 (+ i 1)))
                  > ((= i n))
                  > (vector-set! v i x)))))[/color]

                  I think you could write the scheme code like this:

                  (define vector-fill! (v x)
                  (let ((i 0))
                  (while (< i (length v))
                  (vector-set! v i x)
                  (set! i (1+ i)))))
                  [color=blue]
                  > I have tried on 3 occassions to become a LISP programmer, based upon
                  > the constant touting of LISP as a more powerful language and that
                  > ultimately S-exprs are a better syntax. Each time, I have been
                  > stopped because the S-expr syntax makes we want to vomit.[/color]

                  If you go crazy with macros, lisp gets confusing, that's for sure.

                  Comment

                  • Daniel Silva

                    #39
                    Re: Python syntax in Lisp and Scheme

                    On Fri, 3 Oct 2003, MetalOne wrote:[color=blue]
                    > I am just barely familiar with Lisp and Scheme. However, I always
                    > find comments like the above interesting. I have seen other people
                    > make this claim also.
                    > However, from an earlier post on comp.lang.pytho n comparing a simple
                    > loop.
                    >
                    > Scheme
                    > (define vector-fill!
                    > (lambda (v x)
                    > (let ((n (vector-length v)))
                    > (do ((i 0 (+ i 1)))
                    > ((= i n))
                    > (vector-set! v i x)))))
                    >
                    > Python
                    > def vector_fill(v, x):
                    > for i in range(len(v)):
                    > v[i] = x
                    >
                    > To me the Python code is easier to read, and I can't possibly fathom
                    > how somebody could think the Scheme code is easier to read. It truly
                    > boggles my mind.
                    >[/color]

                    I'd prefer one of these two implementations myself:

                    (define (vector-fill! v x)
                    (let loop ([i (sub1 (vector-length v))])
                    (unless (< i 0)
                    (vector-set! v i x)
                    (loop (sub1 i)))))

                    (define (vector-fill-again! v x)
                    (for-each (lambda (i)
                    (vector-set! v i x))
                    (build-list (vector-length v) identity)))


                    The second one actually does almost exactly what the Python version does,
                    other than creating a lambda and mapping identity across range(len(v)).

                    If you want to use macros to make a for-each that does just what your
                    example asks for:


                    (define-syntax (for stx)
                    (syntax-case stx ()
                    [(_ idx lst exp) #`(for-each (lambda (idx)
                    exp)
                    lst)]))

                    And given a function range that does the same thing:

                    (define (range r)
                    (build-list r identity))

                    Now you have the same for loop:

                    (define (my-vector-fill! v x)
                    (for i (range (vector-length v))
                    (vector-set! v i x)))


                    - Daniel

                    Comment

                    • Grzegorz Chrupala

                      #40
                      Re: Python syntax in Lisp and Scheme

                      Rene van Bevern <rvb@rvb.dyndns .org> wrote in message news:<slrnbnr2p u.1qe.rvb@negoy l.vb-network>...
                      [color=blue]
                      > I know at least one more person who came to LISP/Scheme over ruby. Maybe
                      > it needs ruby and python to enlighten people without confusing them with
                      > a syntax they are not used to first. ;)[/color]

                      I can't remember how *exactly* I came to use scheme (unfortuantely I
                      don't keep a diary), but trying to reconstruct it looks something like
                      this:

                      I am actually not a programmer, but mostly a linguist. About four
                      years ago I got interested in computational linguistics and decided to
                      learn a programming language. The first programming book I picked up
                      was "The Gentle Introduction... " (Common Lisp). I made sense to me but
                      I couldn't find a plug'n' play lisp implementation (I was pretty
                      computer-illiterate at the time: could only manage v. basic stuff on
                      Windoze). So I put that aside and decided to have a go at Perl (widely
                      used in NLP). That was much easier, I installed the ActiveState win32
                      port no problems and picked Perl up from online tutorials and the
                      multitude of other easily accessible Perl resources. After I've played
                      with perl for a while I heard about Python and Ruby, which to me
                      looked like more sophisticated versions of Perl, and I switched to
                      Ruby for most of my toy and not-so-toy scripts. While reading
                      ruby-talk and other ruby-stuff I kept coming across references to
                      Scheme and Lisp, which I was already vaguely familiar with from my
                      perusal of the "Gentle Introduction". At this point I was already
                      using Linux and so could easily install Clisp and half a dozen Scheme
                      implementations . Schemes such as Gauche, Bigloo and PLT seemed like
                      they were better suited to writing the sort of small programs or CGI
                      scripts that I was using Perl and Ruby for, so I sort of settled for
                      Scheme. (Sometime during this time I also learned Prolog in a
                      university course and it made me aware of the various advantages, as
                      well as some disadvantages, of using a very high level languages in
                      comp-ling).
                      At the moment I am quite happy with Scheme although I do miss the
                      large lively communities and the amout of libraries associated with
                      Perl, Python and Ruby. I hope the "revival" of Lisp-like languages
                      some of you have observed will gain momentum and that CL anb Scheme
                      will catch up with Python and Ruby in the areas where they are behind.

                      Cheers,
                      --
                      Grzegorz

                      Comment

                      • Philippe

                        #41
                        Re: Python syntax in Lisp and Scheme

                        mike420@ziplip. com wrote:[color=blue]
                        >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.[/color]

                        Yes. In fact Daniel Silva and I are working on an implementation of
                        the Python language for the DrScheme development environment. So you
                        don't get just a pythonistic syntax for Scheme, you directly get
                        Python in your Scheme environment. It looks like this:


                        Then Scheme programmers can reuse existing Python code and vice-versa.
                        Python programmers can also use DrScheme's tools with their code.
                        Here's an example of using DrScheme's Check Syntax tool on Python
                        code: http://www.ccs.neu.edu/home/matthias/Tmp/spy2.jpg The tool
                        analyzes the code, colors terms according to their syntactic category,
                        and draws arrows that show bindings. Note that no modification to the
                        Check Syntax tool was necessary to get it to work with Python:
                        everything was handled automatically by DrScheme's underlying syntax
                        object system. Not all of DrScheme's tools will automatically work
                        for Python without modifications like Check Syntax does because some
                        tools, like the Stepper or the analyzer, need to be aware of some
                        details about the semantics of the language, but the fact that Check
                        Syntax and DrScheme's test coverage tool already work with Python and
                        for free is quite encouraging.

                        Currently most of the Python language has been implemented and the few
                        remaining things are well within our reach (except for unicode
                        support). Daniel (who's the main developer actually - my role is just
                        to criticize everything he does :-)) is now working on the FFI so
                        Python and Scheme programmers can have access to the C-level Python
                        modules.

                        There's still a lot of work that remains to be done so if anyone,
                        whether Python or Scheme programmer, is interested in helping you're
                        more than welcome to contact us!

                        Also, if people are interested in knowing how it all works, Daniel
                        will have a short presentation of the system at the Scheme Workshop in
                        Boston next month (the day before the Lightweight Languages 2003 (LL3)
                        conference).

                        </shameless plug>

                        Philippe

                        Comment

                        • Erann Gat

                          #42
                          Re: Python syntax in Lisp and Scheme

                          In article <92c59a2c.03100 31345.57d20631@ posting.google. com>,
                          jcb@iteris.com (MetalOne) wrote:
                          [color=blue]
                          > kalath@lycos.co m (Mark Brady) wrote in message[/color]
                          news:<e840346c. 0310030302.6be0 c378@posting.go ogle.com>...[color=blue][color=green]
                          > > Personally I find Scheme and Common Lisp easier to read but that's
                          > > just me, I prefer S-exps ...[/color]
                          >
                          > I am just barely familiar with Lisp and Scheme. However, I always
                          > find comments like the above interesting. I have seen other people
                          > make this claim also.
                          > However, from an earlier post on comp.lang.pytho n comparing a simple
                          > loop.
                          >
                          > Scheme
                          > (define vector-fill!
                          > (lambda (v x)
                          > (let ((n (vector-length v)))
                          > (do ((i 0 (+ i 1)))
                          > ((= i n))
                          > (vector-set! v i x)))))
                          >
                          > Python
                          > def vector_fill(v, x):
                          > for i in range(len(v)):
                          > v[i] = x
                          >
                          > To me the Python code is easier to read, and I can't possibly fathom
                          > how somebody could think the Scheme code is easier to read. It truly
                          > boggles my mind.[/color]

                          In Common Lisp you can write:

                          (defun vector-fill (v x)
                          (loop for i from 0 below (length v) do
                          (setf (aref v i) x)))

                          or

                          (defun vector-fill (v x)
                          (dotimes (i (length v))
                          (setf (aref v i) x)))

                          But if you focus on examples like this you really miss the point. Imagine
                          that you wanted to be able to write this in Python:

                          def vector_fill(v, x):
                          for i from 0 to len(v)-1:
                          v[i] = x

                          You can't do it because Python doesn't support "for i from ... to ...",
                          only "for i in ...". What's more, you can't as a user change the language
                          so that it does support "for i from ... to ...". (That's why the xrange
                          hack was invented.)

                          In Lisp you can. If Lisp didn't already have LOOP or DOTIMES as part of
                          the standard you could add them yourself, and the way you do it is by
                          writing a macro.

                          That's what macros are mainly good for, adding features to the langauge in
                          ways that are absolutely impossible in any other language. S-expression
                          syntax is the feature that enables users to so this quickly and easily.
                          [color=blue]
                          > I can't see
                          > why a LISP programmer would even want to write a macro.[/color]

                          That's because you are approaching this with a fundamentally flawed
                          assumption. Macros are mainly not used to make the syntax prettier
                          (though they can be used for that). They are mainly used to add features
                          to the language that cannot be added as functions.

                          For example, imagine you want to be able to traverse a binary tree and do
                          an operation on all of its leaves. In Lisp you can write a macro that
                          lets you write:

                          (doleaves (leaf tree) ...)

                          You can't do that in Python (or any other langauge).

                          Here's another example of what you can do with macros in Lisp:

                          (with-collector collect
                          (do-file-lines (l some-file-name)
                          (if (some-property l) (collect l))))

                          This returns a list of all the lines in a file that have some property.
                          DO-FILE-LINES and WITH-COLLECTOR are macros, and they can't be implemented
                          any other way because they take variable names and code as arguments.

                          E.


                          ----

                          P.S. Here is the code for WITH-COLLECTOR and DO-FILE-LINES:

                          (defmacro with-collector (var &body body)
                          (let ( (resultvar (gensym "RESULT")) )
                          `(let ( (,resultvar '()) )
                          (flet ( (,var (item) (push item ,resultvar)) )
                          ,@body)
                          (nreverse ,resultvar))))

                          (defmacro do-file-lines ((linevar filename &optional streamvar) &body body)
                          (let ( (streamvar (or streamvar (gensym "S"))) )
                          `(with-open-file (,streamvar ,filename)
                          (do ( (,linevar (read-line ,streamvar nil nil)
                          (read-line ,streamvar nil nil)) )
                          ( (null ,linevar) )
                          ,@body))))

                          Here's DOLEAVES:

                          (defmacro doleaves ((var tree) &body body)
                          `(walkleaves (lambda (,var) ,@body) ,tree))

                          :-)

                          (defun walkleaves (fn tree)
                          (iterate loop1 ( (tree tree) )
                          (if (atom tree)
                          (funcall fn tree)
                          (progn (loop1 (car tree)) (and (cdr tree) (loop1 (cdr tree)))))))

                          ; This is the really cool way to iterate
                          (defmacro iterate (name args &rest body)
                          `(labels ((,name ,(mapcar #'car args) ,@body))
                          (,name ,@(mapcar #'cadr args))))

                          E.

                          Comment

                          • Kenny Tilton

                            #43
                            Re: Python syntax in Lisp and Scheme



                            Grzegorz Chrupala wrote:
                            [color=blue]
                            > Rene van Bevern <rvb@rvb.dyndns .org> wrote in message news:<slrnbnr2p u.1qe.rvb@negoy l.vb-network>...
                            >
                            >[color=green]
                            >>I know at least one more person who came to LISP/Scheme over ruby. Maybe
                            >>it needs ruby and python to enlighten people without confusing them with
                            >>a syntax they are not used to first. ;)[/color]
                            >
                            >
                            > I can't remember how *exactly* I came to use scheme (unfortuantely I
                            > don't keep a diary), but trying to reconstruct it looks something like
                            > this:[/color]

                            It would be valuable to have what you wrote next in:



                            Lisp there is defined as "any member of the Lisp family".

                            Aside: oh, great. Now the survey is going to get thrown off the ALU
                            Cliki by the Iki Police. um, could you all find something less
                            productive to focus on? Cutting and pasting thirty pages is /so/ helpful
                            to the Lisp community. Not!!!

                            You can be response #78...oops, #79.

                            Or e-mail me a go-ahead and I'll do the legwork.

                            kenny

                            Comment

                            • Sampo Smolander

                              #44
                              Re: Python syntax in Lisp and Scheme

                              In comp.lang.schem e Paul Rubin <http://phr.cx@nospam.i nvalid> wrote:[color=blue]
                              > I think you could write the scheme code like this:[/color]
                              [color=blue]
                              > (define vector-fill! (v x)[/color]

                              I guess parenthesising like

                              (define (vector-fill! v x)

                              would be more schemey.

                              [Followups set to scheme-group only]

                              Comment

                              • synthespian

                                #45
                                Re: Python syntax in Lisp and Scheme

                                Jeremy H. Brown wrote:
                                (snip)[color=blue]
                                >
                                > According to the "Revised(5) Report on the Algorithmic Language
                                > Scheme", "Scheme is a statically scoped and properly tail-recursive
                                > dialect of the Lisp programming language..." It's certainly not a
                                > dialect of Common Lisp, although it is one of CL's ancestors.
                                >
                                > I'm sure if you do some web-groveling, you can find some substantial
                                > comparisons of the two; I personally think they have more in common
                                > than not. Here are a few of the (arguably) notable differences:
                                >
                                > Scheme Common Lisp
                                > Philosophy minimalism comprehensivene ss[/color]

                                (etc)
                                Hello --

                                I would just like to point out that there's more choice out there in
                                the Lisp family than Scheme - Common Lisp.
                                In particular, I would like to mention ISLISP, which is an
                                ISO-standard Lisp. Apparently, the story goes somewhat like this: when
                                lispers went for an ANSI standard, they left out the Europeans and the
                                Japanese - which were the other people heavily using Lisp at the time.
                                Thus, ANSI Common Lisp was made all-American. So the people left out
                                went for an ISO-standard Lisp.
                                I don't know why this happened, I suspect (and I might be *very*
                                wrong) it had something to do with competition way back when Lisp were
                                aiming higher expectations market-wise (the French being very proud of
                                Prolog :-) ).
                                I have recently bumped into ISLISP. It is pretty good. It has full
                                documentation and two usable implementations : a GPL TISL, and a free for
                                non-commercial use OpenLisp (for now, at least, and I can't say for now
                                if this will change - for the better).
                                I don't have time to write a comparison table now, but let me just
                                say that it mentions in its documentation the purpose of merging the
                                perceived best features of "the family": "It attempts to bridge the gap
                                between the various incompatible members of the Lisp family of languages
                                (most notably Common Lisp, Eulisp, LeLisp, and Scheme) by focusing on
                                standardizing those areas of widespread agreement." (check the URLs
                                bellow, this quote from KMP's ISLISP site). However, it's not as big as
                                Common Lisp (but some people mention that Common Lisp is a large as it
                                is because it ported functionality that was from the Lisp Machines - but
                                I might be wrong, what do I know about Lisp Machines - I wish...).
                                ISLISP has objects, generic functions, defmacro and other good
                                things. One of its stated aims was industry-use, not academia (that's
                                from the spec).
                                The TISL implementation is not so much developed as OpenLisp, but
                                it's functional and GPLed. OpenLisp is lovely, and it beats the hell out
                                of Scheme and Common Lisp on the *huge* number of platforms it compiles
                                on. OpenLisp has compiled on over 60 platforms (yes! 16 to 64 bits!),
                                and is actively ported today to over 20! So, it's pretty amazing, when
                                you take into consideration that platform differences are an issue,
                                particularly with Common Lisp implementations (CLISP being the most
                                portable), when you need to interact with the OS. So, this is a
                                non-issue solved on OpenLisp, just as it is solved on Python or Perl. It
                                approaches Perl or Python in portability (or beats them, I dunno).
                                OpenLisp's author, unfortunately, isn't much of a "marketing" person...
                                I have tested it under win32 and NetBSD on Alpha.

                                BTW, I bumped into OpenLisp because of a Lisp-friendly unix shell
                                account provider,SDF Public Access Unix Network, a non-profit, that
                                supports OpenLisp for CGI (also having the usual Python/Perl, etc).
                                I mention ISLISP here because people are unaware of its existence,
                                and it's quite a jewel, really.
                                And let's be honest, who needs Python/Perl/Ruby when you have Lisp? ;-)

                                Well, that's my 2c, get to know and enjoy ISLISP.

                                Cheers,


                                Henry


                                OpenLisp by Eligis
                                ISLISP, ISO Lisp, Standard Lisp, OpenLisp, Embedded Lisp, Embeddable Lisp, Lisp, Portable Lisp, Windows Lisp, Linux Lisp, Lisp in C/C++

                                or http://www.eligis.com

                                TISL GPL'd ISLISP form Tohoku University (Japan) (under active development)


                                ISLISP - Standards http://anubis.dkuug.dk/JTC1/SC22/WG1.../standard.html

                                More ISLISP documentation http://www.islisp.info/, this site maintained
                                by Kent Pitman

                                ISLISP in Java http://cube.misto.cz/lisp/

                                TBK's links on ISLISP




                                Comment

                                Working...