On Sep 5, 5:40 pm, David Kirkby <david.kir...@onetel.net> wrote: >What seems to be a common theme is using Python, but it's not clear to >me this is optimal. It might be simpler to pass the unmodified input >from Sage to Lisp and do the rest there. > >RJF thinks Lisp is the best language >William thinks Python is God > >It needs an objective look at this.
I started learning Lisp a couple of years ago when I left the Sage project and created a fork of a Lisp-based CAS called Yacas. The fork is called MathPiper (http://mathpiper.org) and I spent a full year refactoring it and documenting it as part of the process of learning how it worked. I have experience using a compiler compiler like Yacc to create a programming language interpreter and I also have some experience writing programs in Python. Here are some of my thoughts on using Python vs. Lisp for developing CAS related programs. I think one of the most critical differences between Python and Lisp is that Python is a programming language, but Lisp isn't really a "programming language" for reasons which are described in this blog post: http://lispy.wordpress.com/2007/10/24/lisp-isnt-really-a-programming-language/ The post begins by stating that "...practically any program written in Lisp could be considered to be a DSL." For those who don't know, the term DSL stands for Domain Specific Language and as an example, MathPiper is a DSL which is written in lisp. The whole post is informative, but the following paragraph gets to the heart of what I think makes Lisp fundamentally different than Python: "Now there’s an interesting thing about those data structures you make with car, cons, and cdr. They’re an abstract syntax tree. Now in most other languages, if someone wants to do something cool, they convert what they’re working with to an abstract syntax tree and then go to town with it. If you want to convert something from in-fix notation to something more lisp-like, its trivial once you can get that original notation into an abstract syntax tree. But the thing is, if you’re using lisp, you’re using lists. And Lisp’s lists are essentially abstract syntax trees by definition. So in Lisp, a lot hard things are easy… by default. Finally, your Lisp code is itself written in terms of list data structures. This means its easy to write code to execute transformations of your code. This is what macros do and this is why other languages can’t do this." This isn’t a good place to go into the details of what an Abstract Syntax Tree (AST) is or how with Lisp one works with an AST directly, but perhaps I can a provide bit of a feel for this. Here is a simple while loop in MathPiper syntax, along with the Lisp AST code it is transformed into: %mathpiper,title="The output fold contains the internal Lisp form of the MathPiper while loop." LispForm(Hold([ x := 1; While(x <= 10) [ Write(x,,); x := x + 1; ]; ])); %/mathpiper %output,preserve="false" Result: <snip> Side Effects: (Prog (:= x 1 ) (While (<= x 10 ) (Prog (Write x , ) (:= x (+ x 1 ))))) . %/output For people who have not programmed in Lisp yet, it is usually challenging to get one's mind around what is being indicated by the Lisp syntax. I experienced this difficulty too when I first started learning MathPiper's Lisp, so I made a function called ViewList which displays Lisp code in graphic box diagram form. Here is the above Lisp code displayed in this graphic form: https://sites.google.com/site/mathpiper/screenshots/graphic_view_of_while_loop_lisp_code.png?attredirects=0 Its difficult to explain how amazingly powerful it is to be able to directly work with the AST form of the code one is developing. In the blog post it states "You don’t write Lisp code so much as you extend the Lisp language until it becomes a custom language for whatever it is you’re trying to do." This ability enables a developer to customize and extend the MathPiper syntax to an astonishing degree. If you were interested in experiencing some of the power of Lisp before diving in and learning Lisp syntax, MathPiper provides a relatively easy was to do this. Now that I understand MathPiper's Lisp fairly well, I have been spending time learning Common Lisp. Recently, I have been experimenting with using Mockmma to translate Mathematica expressions into Lisp format so that I can read them into MathPiper. For example, here is a short Mathmatica expression: -PolyLog[2,1-a*c-b*c*x]/e And here is the Lisp code that Mockmma translates it into: (TIMES (TIMES -1 (POLYLOG 2 (PLUS 1 (TIMES -1 (TIMES A C)) (TIMES -1 (TIMES B C X))))) (POWER E -1)) The following program uses MathPiper's Lisp code reader to read the code into a MathPiper internal AST structure: %mathpiper,title="MMA to Lisp" lispCode := PipeFromString( "(TIMES (TIMES -1 (POLYLOG 2 (PLUS 1 (TIMES -1 (TIMES A C)) (TIMES -1 (TIMES B C X))))) (POWER E -1)) ") LispRead(); %/mathpiper %output,preserve="false" Result: TIMES(TIMES(-,1,POLYLOG(2,PLUS(1,TIMES(-, 1,TIMES(A,C)),TIMES(-,1,TIMES(B,C,X))))),POWER(E,-,1)) . %/output Once this code has been read into MathPiper's internal AST format, it can be manipulated in numerous ways. Of course, ViewList can also be used to see a graphic representation of it: https://sites.google.com/site/mathpiper/screenshots/mathematica_to_lisp.png?attredirects=0 Anyway, I am not a very good Lisp programmer yet, but I would be willing to help you learn some Lisp if you decide to use Mockmma to parse Mathematica syntax. >It is however very clear there are far more people who know Python than >Lisp, so use of Python is more attractive to more developers. Its interesting though, because Lisp has been making a significant comeback lately. For example, the Clojure (http://clojure.org/) community has been growing at a very good rate, an exciting Java implementation of Common Lisp has been coming along nicely (http:// common-lisp.net/project/armedbear/), and sites like Hackers News (http://news.ycombinator.com/) mention Lisp all the time. Even MathPiper is participating in this comeback. MathPiper is the main CAS used by GeoGebra and GeoGebra had roughly 10,000 downloads per day during October of last year (which was the last time I checked). Even if Lisp were not making a comeback, my thought is that it would still be a good idea to build your system on top of Mockmma. Even though there are lots of programmers in the world, the probability that you will be able to get any of them to help with the development of your code is fairly low no matter what language you pick. With Mockmma, a significant amount of the work is already done and I think that using would greatly increase your chances of success. Ted Kosan -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org