Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] Lisp's attractions (was: Polymorphism)

Expand Messages
  • George Paci
    ... Compiler, or interpreter? A bit of Lisp lore: the very first Lisp interpreter was written in a few weeks, by a graduate student whom McCarthy had advised
    Message 1 of 11 , Jul 30, 2002
    • 0 Attachment
      Kevin Lawrence wrote:
      > Strangely enough, I wrote a lisp compiler a few weeks ago while
      > experimenting with genetic programming and I have to confess that I do not
      > understand the merits of that language at all.

      Compiler, or interpreter? A bit of Lisp lore: the very first Lisp
      interpreter was written in a few weeks, by a graduate student whom
      McCarthy had advised not to try.

      > I chose to generate Lisp because the syntax seemed simple - so I learned
      > just enough Lisp to understand what my gp was doing and to feed in valid
      > programs for testing. The syntax of Lisp seemed ideally suited for a code
      > generator but completed unsuitable for a human like me.

      I think you're getting close to what's great about Lisp. Basically,
      you're typing in parse trees. There's very little syntactic sugar
      to get between you and the interpreter (or compiler, these days).
      Since you've got your program in a form that's so easy for other
      programs to deal with, you can write very useful macros -- Lisp code
      that changes other Lisp code.

      The syntax can seem strange at first, but come on: even BASIC takes
      some time to get used to. Just indent all the sexps nicely, and the
      structure of the code will jump out at you (except for if -- I still
      don't feel quite right about that one).

      Or you can do what McCarthy was originally going to, but decided was
      unnecessary: come up with a more English-like syntax, and generate
      the s-expressions from that.

      --George Paci
      george@...
    • Mike Beedle
      ... The most amazing thing is what Lisp ended up being out of pure serendipity. McCarthy was going after a universal function that would compete or replace a
      Message 2 of 11 , Jul 31, 2002
      • 0 Attachment
        George Paci wrote:
        > Kevin Lawrence wrote:
        > > Strangely enough, I wrote a lisp compiler a few weeks ago while
        > > experimenting with genetic programming and I have to confess
        > that I do not
        > > understand the merits of that language at all.
        >
        > Compiler, or interpreter? A bit of Lisp lore: the very first Lisp
        > interpreter was written in a few weeks, by a graduate student whom
        > McCarthy had advised not to try.


        The most amazing thing is what Lisp ended up being out of
        pure serendipity. McCarthy was going after a universal function
        that would compete or replace a Turing machine.

        But when S.R. Russell noticed that eval could serve as an interpreter
        for LISP, and promptly coded it -- against McCarthy's advise and
        wishes, we ended up with a very special programming language, where
        code is always data, and data can be code!!, where a simple
        interpreter and a handful of primitives define a powerful language:

        (define (eval exp env)
        (cond ((self-evaluating? exp) exp)
        ((variable? exp) (lookup-variable-value exp env))
        ((quoted? exp) (text-of-quotation exp))
        ((assignment? exp) (eval-assignment exp env))
        ((definition? exp) (eval-definition exp env))
        ((if? exp) (eval-if exp env))
        ((lambda? exp)
        (make-procedure (lambda-parameters exp)
        (lambda-body exp)
        env))
        ((begin? exp)
        (eval-sequence (begin-actions exp) env))
        ((cond? exp) (eval (cond->if exp) env))
        ((application? exp)
        (apply (eval (operator exp) env)
        (list-of-values (operands exp) env)))
        (else
        (error "Unknown expression type - EVAL" exp))))

        (define (apply procedure arguments)
        (cond ((primitive-procedure? procedure)
        (apply-primitive-procedure procedure arguments))
        ((compound-procedure? procedure)
        (eval-sequence
        (procedure-body procedure)
        (extend-environment
        (procedure-parameters procedure)
        arguments
        (procedure-environment procedure))))
        (else
        (error
        "Unknown procedure type - APPLY" procedure))))

        Understanding this "universal function" is equivalent as
        understanding a 400 page programming language.

        To prove that McCarthy had little intention in doing this,
        take a look at what he wrote:

        "Another way to show that LISP was neater than Turing machines
        was to write a universal LISP function and show that it is
        briefer and more comprehensible than the description of a
        universal Turing machine. This was the LISP function eval[e,a],
        which computes the value of a LISP expression e - the
        second argument a being a list of assignments of values
        to variables. (a is needed to make the recursion work). Writing
        eval required inventing a notation representing LISP
        functions as LISP data, and such a notation was devised for
        the purposes of the paper with no thought that it would
        be used to express LISP programs in practice. Logical
        completeness required that the notation used to express
        functions used as functional arguments be extended to
        provide for recursive functions, and the LABEL notation
        was invented by Nathaniel Rochester for that purpose.
        D.M.R. Park pointed out that LABEL was logically unnecessary
        since the result could be achieved using only LAMBDA - by
        a construction analogous to Church's Y-operator, albeit
        in a more complicated way."

        Which goes to show that he had _no_ vision or plan to
        create the monster that he did: it just happened out of
        pure luck. (Feyerabend lives!) This statement is specially
        enlightening:

        "Writing eval required inventing a notation representing
        LISP functions as LISP data, and such a notation was
        devised for the purposes of the paper with no thought
        that it would be used to express LISP programs in practice."

        Thank God someone took his original notation seriously and
        literally .... otherwise, Lisp as we know it, may have never
        existed. And humanity would be deprived of its power, flexibility
        and simplicity.

        In terms of impact, Genetic programming, most Agent Technology,
        Artificial Intelligence and all of its branches (Logical programming,
        Rule-Oriented, Natural Language Processing, Neural Nets, Game
        Programming, etc. etc.), Hybrid or Multi-Paradigmic programming,
        Aspect Oriented Programming, Meta-Object Protocols, and a great
        deal of programming language research could have never been
        possible if it wasn't for Lisp.

        Literally, we would not be where we are in programming if
        it wasn't for a crazy guy that took a programming language
        research paper literally, and did a very dumb thing:

        wrote some code in a short amount of time.

        The rest was generated by this little "historical accident".

        George Paci wrote:
        > I think you're getting close to what's great about Lisp. Basically,
        > you're typing in parse trees. There's very little syntactic sugar
        > to get between you and the interpreter (or compiler, these days).
        > Since you've got your program in a form that's so easy for other
        > programs to deal with, you can write very useful macros -- Lisp code
        > that changes other Lisp code.

        Yes, absolutely, once code is data, there is not need for
        ASTs (Abstract Syntax Trees). Lisp notation is basically a condensed
        form for writing ASTs.

        But what that means is that to modify the meaning of the
        language and/or to do even things like meta-programming, Lisp
        is the natural choice. Think about this: it is easy to generate
        data from a program, right? Well, if code is data, then it
        is easy to generate _code_. Things like genetic programming are
        easy with Lisp.

        Also, parsing "other languages" is easy with Lisp. It is no
        coincidence that most ACLs (Agent Communication Languages) are
        Lisp-based, because the "verb/data exchanges" can be simply
        interpreted on either side. No need for SAX-like parsers that
        waste cycles in serialization and deserialization -- simply
        take the stream and interpret it. And if it is not exactly Lisp,
        get inspired by Lisp and create an eval-like function and then
        interpret the "new language". In that sense, eval is like a
        "universal SAX parser". Wouldn't you like to have one of those?

        On the meta-programming side, imagine this, you can set any
        level of filtering, execution of extra actions, change interpretation,
        or give new meanings to anything that is interpreted or
        "evaluates" by just changing eval. So if you want to keep
        meta data or meta processing on your programs there is nothing
        as simple as Lisp.

        In Lisp, for example, is incredibly easy to do Aspect Oriented
        Programming because you can manage at every point what happens
        to the joint and cut points of functions and it is easy
        to do so.... everything goes through eval.

        If that wasn't enough, Lisp comes with a myriad of nice features
        such as lambdas (first order functions), closures (functions that
        generate functions), powerful macros (that can generate anything
        data, functions, classes, patterns, or even other macros),
        generics (methods that cut across multiple classes in CLOS), and
        by extension, MOPs; and with a wide variety of powerful
        Open Source Lisp source code scattered throughout the planet.
        (The Lisp community was perhaps the first community that
        embraced Open Source.)

        In my opinion, Lisp is the most powerful and flexible language,
        and in fact, I would say that once you understand Lisp, other
        languages seem very constraining, underpowered and unnecessary
        complicated.

        Also, Lisp programmers were probably the first "agile developers"
        on the planet, because as far back as the mid-60s, many of the
        practices that we know today as "agile practices" or even
        "extreme programming" were already in practice:

        - Bottom-up Design. LISP programmers have practiced
        bottom-up design since the 60s. So bottom-up architecting
        and emergent design have lived in this community from
        the very beginning.

        - Test-first programming In LISP you test everything
        with eval all the time. Also it is customary to write
        libraries by writing tests at the end of source code
        that get commented when the source code is released.
        The test are typically test evaluations that you
        want to remember.

        - Development in pairs. This was used to mentor
        juniors through the "buddy system". Practiced at
        MIT, for example.

        - Customer-Driven implementations with rapid
        prototyping being practiced. It is easier
        to show the customer what he or she may want
        in LISP than to write a long document

        - Continuous Integration, since individual developer's
        speed was high, continuous integration was
        necessary and mandatory

        - Iterative Development, was natural since
        development was goal-oriented
        etc.

        etc.

        Sorry for my longish post -- I could rave and rant all day about
        the powers of Lisp.

        I'll leave you with a thought. Here is simple example to
        extend Lisp to do Object-Oriented programming. Try to do something
        similar in C, C++, Java or even Smalltalk ;-)

        (defmacro define-class (class inst-vars class-vars &body methods)
        "Define a class for object-oriented programming."
        ;; Define constructor and generic functions for methods
        `(let ,class-vars
        (mapcar #'ensure-generic-fn ',(mapcar #'first methods))
        (defun ,class ,inst-vars
        #'(lambda (message)
        (case message
        ,@(mapcar #'make-clause methods))))))

        (defun make-clause (clause)
        "Translate a message from define-class into a case clause."
        `(,(first clause) #'(lambda ,(second clause) .,(rest2 clause))))

        (defun ensure-generic-fn (message)
        "Define an object-oriented dispatch function for a message,
        unless it has already been defined as one."
        (unless (generic-fn-p message)
        (let ((fn #'(lambda (object &rest args)
        (apply (get-method object message) args))))
        (setf (symbol-function message) fn)
        (setf (get message 'generic-fn) fn))))

        (defun generic-fn-p (fn-name)
        "Is this a generic function?"
        (and (fboundp fn-name)
        (eq (get fn-name 'generic-fn) (symbol-function fn-name))))

        - Mike
      • kevinbsmith
        ... I ve only spent a few hours over the past few years looking into Lisp. It just feels like someone forgot to write the upper half of the language
        Message 3 of 11 , Jul 31, 2002
        • 0 Attachment
          --- In extremeprogramming@y..., "Mike Beedle" wrote:
          > I'll leave you with a thought. Here is simple example to
          > extend Lisp to do Object-Oriented programming. Try to do something
          > similar in C, C++, Java or even Smalltalk ;-)
          >
          > (defmacro define-class (class inst-vars class-vars &body methods)
          > "Define a class for object-oriented programming."
          > ;; Define constructor and generic functions for methods
          > `(let ,class-vars
          > (mapcar #'ensure-generic-fn ',(mapcar #'first methods))
          > (defun ,class ,inst-vars
          > #'(lambda (message)
          > (case message
          > ,@(mapcar #'make-clause methods))))))
          >

          I've only spent a few hours over the past few years looking
          into Lisp. It just feels like someone forgot to write
          the upper half of the language translator. Which, of course,
          is pretty much the historical truth.

          Posting cryptic fragments like this probably doesn't inspire
          many of us to want to learn more about the language.

          Kevin
        • Tim Moore
          ... Once you get used to it, it s not really any more cryptic than any other programming language...and it s a lot less cryptic than some. There are far fewer
          Message 4 of 11 , Jul 31, 2002
          • 0 Attachment
            > -----Original Message-----
            > From: kevinbsmith [mailto:kevinxp@...]
            > Sent: Wednesday, July 31, 2002 11:46 AM
            > To: extremeprogramming@yahoogroups.com
            > Subject: Re: [XP] Lisp's attractions (was: Polymorphism)
            >
            >
            > --- In extremeprogramming@y..., "Mike Beedle" wrote:
            > > I'll leave you with a thought. Here is simple example to
            > > extend Lisp to do Object-Oriented programming. Try to do something
            > > similar in C, C++, Java or even Smalltalk ;-)
            > >
            > > (defmacro define-class (class inst-vars class-vars &body methods)
            > > "Define a class for object-oriented programming."
            > > ;; Define constructor and generic functions for methods
            > > `(let ,class-vars
            > > (mapcar #'ensure-generic-fn ',(mapcar #'first methods))
            > > (defun ,class ,inst-vars
            > > #'(lambda (message)
            > > (case message
            > > ,@(mapcar #'make-clause methods))))))
            > >
            >
            > I've only spent a few hours over the past few years looking
            > into Lisp. It just feels like someone forgot to write
            > the upper half of the language translator. Which, of course,
            > is pretty much the historical truth.
            >
            > Posting cryptic fragments like this probably doesn't inspire
            > many of us to want to learn more about the language.
            >
            > Kevin

            Once you get used to it, it's not really any more cryptic than any other
            programming language...and it's a lot less cryptic than some. There are
            far fewer primitive syntactic elements to learn than in most languages,
            and everything else is built out of those. Contrast Perl.

            I guess it's an aesthetic thing, and it does certainly take getting used
            to if your prior experience is mostly in C-like languages.

            --
            Tim Moore / Blackboard Inc. / Software Engineer
            1899 L Street, NW / 5th Floor / Washington, DC 20036
            Phone 202-463-4860 ext. 258 / Fax 202-463-4863
          • Charlie Poole
            Mike, I ve snipped the post which was probably more than most folks wanted to know about Lisp, but I enjoyed it. One thing that made Lisp so attractive in
            Message 5 of 11 , Jul 31, 2002
            • 0 Attachment
              Mike,

              I've snipped the post which was probably more than most folks
              wanted to know about Lisp, but I enjoyed it.

              One thing that made Lisp so attractive in earlier days was
              that virtually anyone could easily create their own interpreter
              on the most minimal hardware. My 16K S-100 system couldn't
              even run the MS assembler, but I eventually got a minimal
              Lisp into it.

              Charlie Poole
              cpoole@...
              www.pooleconsulting.com
              www.charliepoole.org
            • Ron Jeffries
              ... If we didn t know the language, x = (-b + sqrt(b**2 - 4*a*c)) / ( 2*a) might seem cryptic, as (certainly) would public String[] Lines { get { return
              Message 6 of 11 , Aug 1, 2002
              • 0 Attachment
                Around Wednesday, July 31, 2002, 11:46:07 AM, kevinbsmith wrote:

                > Posting cryptic fragments like this probably doesn't inspire
                > many of us to want to learn more about the language.

                If we didn't know the language,

                x = (-b + sqrt(b**2 - 4*a*c)) / ( 2*a)

                might seem cryptic, as (certainly) would

                public String[] Lines {
                get {
                return (String[]) lines.ToArray(typeof(String));
                }
                set {
                lines = new ArrayList(value);
                }

                or for that matter, "Guten Tag" or "bon giorno".

                I don't think any of them are in fact cryptic. They're all just
                unknown. And I don't know where inspiration comes from ... in the case
                of Lisp, it can be worth finding some though.

                Ron Jeffries
                www.XProgramming.com
                FEAR = Fantasy Experienced As Reality
              • Bill de hÓra
                ... Not cryptic; idiomatic. regards, Bill de hÓra .. Propylon www.propylon.com
                Message 7 of 11 , Aug 1, 2002
                • 0 Attachment
                  > Around Wednesday, July 31, 2002, 11:46:07 AM, kevinbsmith wrote:
                  >
                  > > Posting cryptic fragments like this probably doesn't inspire
                  > > many of us to want to learn more about the language.

                  Not cryptic; idiomatic.

                  regards,
                  Bill de hÓra
                  ..
                  Propylon
                  www.propylon.com
                • Kari Hoijarvi
                  I got interested in Lisp in 1984. Because I had no interpreter available, I decided to make my own. It took three weeks and 1400 lines of Pascal. I was a
                  Message 8 of 11 , Aug 1, 2002
                  • 0 Attachment
                    I got interested in Lisp in 1984. Because I had no interpreter
                    available, I decided to make my own.

                    It took three weeks and 1400 lines of Pascal. I was a beginner then.

                    Anyway, I think it was one of my best learning experiences ever.

                    Kari

                    -----Original Message-----
                    From: Charlie Poole [mailto:cpoole@...]
                    Sent: Wednesday, July 31, 2002 12:54 PM
                    To: extremeprogramming@yahoogroups.com
                    Subject: RE: [XP] Lisp's attractions (was: Polymorphism)


                    Mike,

                    I've snipped the post which was probably more than most folks
                    wanted to know about Lisp, but I enjoyed it.

                    One thing that made Lisp so attractive in earlier days was
                    that virtually anyone could easily create their own interpreter
                    on the most minimal hardware. My 16K S-100 system couldn't
                    even run the MS assembler, but I eventually got a minimal
                    Lisp into it.

                    Charlie Poole
                    cpoole@...
                    www.pooleconsulting.com
                    www.charliepoole.org
                  • John Carter
                    ... And Ah! there you have it, lisp s attraction. It would have taken you 2000 lines or more to write a Pascal interpreter in any language of your choice. But
                    Message 9 of 11 , Aug 1, 2002
                    • 0 Attachment
                      On Thu, 1 Aug 2002, Kari Hoijarvi wrote:

                      > I got interested in Lisp in 1984. Because I had no interpreter
                      > available, I decided to make my own.
                      >
                      > It took three weeks and 1400 lines of Pascal. I was a beginner then.
                      >
                      > Anyway, I think it was one of my best learning experiences ever.

                      And Ah! there you have it, lisp's attraction. It would have taken you 2000
                      lines or more to write a Pascal interpreter in any language of your
                      choice.

                      But it takes you a screen full of lisp to write a lisp interpreter in
                      lisp.

                      Now if you really want elegance and beauty, try joy.


                      joy0 ==
                      [ [ [ joy0 body joy0 ]
                      [ [] ]
                      [ pop pop pop ]
                      [ cons pop cons ]
                      [ opcase pop opcase ]
                      [ body pop body ]
                      [ i pop joy0 ]
                      [ step pop [joy0] cons step ]
                      [ [] cons i ] ]
                      opcase
                      i ]
                      step

                      is a minimal Joy interpreter written in Joy. See

                      http://www.latrobe.edu.au/philosophy/phimvt/joy/jp-joyjoy.html

                      for an explanation...
                      --


                      John Carter Phone : (64)(3) 358 6639
                      Tait Electronics Fax : (64)(3) 359 4632
                      PO Box 1645 Christchurch Email : john.carter@...
                      New Zealand

                      This email message is intended only for the addressee(s) and contains
                      information which may be confidential and/or copyright. If you are not
                      the intended recipient please do not read, save, forward, disclose, or
                      copy the contents of this email. If this email has been sent to you in
                      error, please notify the sender by reply email and he will be
                      along to delete you, this email and any copies or links to this email.
                      No representation is made that this email, you, or the sender are free of
                      viruses. Virus scanning and prevention is recommended and is the
                      responsibility of consenting adults.
                    • Ron Jeffries
                      ... Reminds me of Forth ... Ron Jeffries www.XProgramming.com You do ill if you praise, but worse if you censure, what you do not understand. --Leonardo da
                      Message 10 of 11 , Aug 1, 2002
                      • 0 Attachment
                        Around Friday, August 2, 2002, 2:41:51 AM, John Carter wrote:

                        > Now if you really want elegance and beauty, try joy.

                        Reminds me of Forth ...

                        Ron Jeffries
                        www.XProgramming.com
                        You do ill if you praise, but worse if you censure,
                        what you do not understand. --Leonardo da Vinci
                      • Mike Beedle
                        ... ... it is its functional cousin: http://www.latrobe.edu.au/philosophy/phimvt/joy/forth-joy.html - Mike
                        Message 11 of 11 , Aug 1, 2002
                        • 0 Attachment
                          Ron wrote:
                          > John wrote:
                          > > Now if you really want elegance and beauty, try joy.
                          >
                          > Reminds me of Forth ...

                          ... it is its functional cousin:
                          http://www.latrobe.edu.au/philosophy/phimvt/joy/forth-joy.html

                          - Mike
                        Your message has been successfully submitted and would be delivered to recipients shortly.