XLisp Maximum of a list

Discussion of other Lisp dialects (Arc, Clojure, AutoLisp, XLISP, etc.)
Post Reply
paul ince
Posts: 1
Joined: Sun Jul 25, 2010 8:08 am

XLisp Maximum of a list

Post by paul ince » Sun Jul 25, 2010 8:23 am

Hello there, I am a beginner in Lisp, I am currently practicing XLisp, so I have this little program to find the maximum of a given list,recursively. So i came up with this so far, I am quite sure this is the correct solution, except there is one problem - I do not have a clue what should i put in the terminating case, when the list is null, what should I return after I checked the whole list, so the program could end? Thanks in advance

(defun maxim(list)
(cond
((null list) (???))
((> (car list)(car(cdr list)) (car list) (maxim(cdr list))))
)
)

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: XLisp Maximum of a list

Post by ramarren » Sun Jul 25, 2010 9:45 am

Recursion in programming is similar to mathematical induction. You should not think about terminating case as such, although it certainly has to terminate to work, but about a base case, which is the simplest case for a given function.

For a maximum function on a list one formulation of a simplest case is, that given a number and nothing, the number is returned. An empty list would then be checked, if ever, as argument consistency check, not recursion case. You might also consider using an accumulator argument, which would allow the function to be written tail recursively.

I am not sure how to explain this better. If you have problems, try to express the operation in words first, before writing code. In particular, your COND condition expression, unless XLisp is very different from CL, doesn't really make sense.

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: XLisp Maximum of a list

Post by edgar-rft » Fri Aug 06, 2010 6:55 am

Maybe important to know (if you run across XLisp for the first time) is that there exist several different XLisp versions, which are unfortunately more or less incompatible to each other. The "X" in XLisp stands for "experimental" and that's what XLisp is most about.

XLisp 1.x - I have never worked with this version and cannot tell much about it.

XLisp 2.x - is an object-oriented Lisp and one of the predecessors of Common Lisp, but instead of CLOS, XLisp_2.0 uses a SmallTalk-like message passing object model. Shortly after the release of XLisp_2.0 by David Betz (original author of XLisp) in the early 1980s, the Common Lisp discussions began.

XLisp_2.0 then was further developed by a group of programmers around by Tom Almy, who tried to make XLisp_2.0 more compatible with Common Lisp. They released several XLisp_2.0 derivates under Names like "XLisp_2.1" and "XLisp-Plus", which are only partially backwards compatible with XLisp_2.0.

XLisp 3.x - is a complete rewrite of XLisp_2.0 to Scheme, again by David Betz, but more or less fully backwards incompatible to XLisp_2.x.

The official XLisp Homepage of David Betz (original author of XLisp) can be found here:

XLisp 3.0 homepage: http://www.xlisp.org/

I myself have worked several years with XLisp as part of the "Nyquist" programming language for sound synthesis and music composition by Roger Dannenberg, which is based on XLisp_2.0 by David Betz:

Nyquist homepage: http://www.cs.cmu.edu/~music/music.software.html

Over the years I have collected and HTML-ified all documents and papers I could find in the net about XLisp_2.0. You can read and download the XLisp_2.0 documents collection for free from the german Audacity forum. Audacity is a free audio editor with an integrated Nyquist/XLisp interpreter.

XLisp_2.0 documents collection: http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-index.htm

Please note that this document collection is not very useful with the current XLisp_3.0 version, which is based on Scheme. The XLisp_3.0 documentation can be downloaded from David Betz's homepage (see above).

For the sake of completeness and because there are still many XLisp_2.1.x (the "x" is a lowercase letter from "a" to "g") and XLisp-Plus versions around in the net, here the link to Tom Almy's XLisp-Plus page:

XLisp Plus homepage: http://almy.us/xlisp.html

There also exist several other XLisp derivates:

S-Lisp documentation: http://sig.biostr.washington.edu/share/skandha4/html/slisp_toc.html - XLisp + the skandha4 3d-graphics library
Winterp homepage: http://nielsmayer.com/winterp/ - XLisp + the Motif graphics toolkit
(X)Lisp-Stat homepage: http://www.stat.uiowa.edu/~luke/xls/xlsinfo/xlsinfo.html - using XLisp for statistical computations

To answer Paul's "maximum of a list" question it would be very helpful to know the exact XLisp version number and wether it's one of the David Betz original versions or one of the many derivates.

Post Reply