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

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

Expand Messages
  • Kevin Lawrence
    From: kevinbsmith ... I can definitely appreciate the simplicity and the elegance of a language where every language construct
    Message 1 of 1 , Jul 31, 2002
    • 0 Attachment
      From: "kevinbsmith" <kevinxp@...>

      > --- 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

      I can definitely appreciate the simplicity and the elegance of a language
      where every language construct (assignment, selection, sequence, iteration,
      function call, function definition, arrays, trees and any other kind of
      data) have exactly the same syntax, but I agree with (the other) Kevin that
      the more code snippets I see, the less I feel inclined to learn it. That may
      be more a reflection of me than of Lisp ... but ...

      As an aside, I got into all this because I came up with the idea of
      *evolving* a competitor for Robocode ( http://robocoderepository.com/ ) and
      was finding it tricky to generate the necessary Java code and a friend told
      me "you know that's called Genetic Programming and it would be much easier
      in Lisp" - and sure enough it was much easier.

      What I am actually doing is generating a parse tree that I evaluate directly
      like this ...


      but I found it convenient to serialize the trees into Lisp syntax so I could
      read what the GP had generated. I could also write my unit tests in Lisp to
      make sure everything else was working correctly. For example .....

      public void TestNestedAdd()
      AssertResult(6, "(+ 1 (+ 2 3))");

      public void TestEquals()
      List a = Compile("1");
      List b = Compile("(1)");
      List c = Compile("(+ 1 2)");
      List d = Compile("(+ 1 2)");
      List e = Compile("(+ 1 3)");

      AssertEquals(a, b);
      AssertEquals(c, d);

      public void TestNodeCount()
      AssertEquals(1, Compile("0").NodeCount);
      AssertEquals(3, Compile("(+ 1 2)").NodeCount);
      AssertEquals(5, Compile("(+ 1 (- 4 5))").NodeCount);

      public void TestCustomFunction()
      compiler.AddFunction(Sqrt.TOKEN, typeof(Sqrt));
      AssertResult(4.0, "(sqrt 16)");

      I actually learned Lisp test-first - I would read a line from the spec,
      write a test for it then modify my compiler to pass the test. Cool way to
      learn a new language, but just looking at those examples makes me glad I am
      writing C#, not Lisp ! (maybe someone could translate one of them for the
      comparison ?)

      My next step is to generate Java or C# from the parse tree and compile that
      into bytecode because evaluating the results is too slow for efficient GP.

      To summarize - I am thankful that there is such a thing as Lisp - but I am
      also thankful that I don't have to write it.


      Diamond Sky Software
    Your message has been successfully submitted and would be delivered to recipients shortly.