Re: [ILUG] LISP & Prologue

From: Shane Dempsey (sdempsey at domain tssg.wit.ie)
Date: Wed 02 Feb 2000 - 10:52:38 GMT


 Hi ,
Just to put in a bit about prolog, cos I'm a big enthuasiast.

Using swi_pl and a package ( called XPCE I think ) under linux
it is possible to do everything from file io to windowing with the
ultimate goal of being able to write a fully featured text editor like
xemacs in prolog.

This sounds nuts but I tried it about a year ago and it was working until
I got sense and decided to do something more practical with my
time. A few people on the list will remember this episode..

It's not fast but it is beautiful.

factorial(1,1) :- !.
factorial(N,Ans) :- factorial(N-1,Temp) , Ans is N * Temp.

or something along those lines.

    ...shane

--
###################################
Shane Dempsey -         sdempsey at domain tssg.wit.ie
TSSG Researcher        http://www-tssg.wit.ie
###################################
----- Original Message -----
From: Smelly Pooh <plop at domain redbrick.dcu.ie>
To: <ilug at domain linux.ie>
Sent: 02 February 2000 06:39
Subject: Re: [ILUG] LISP & Prologue
> In reply to Albert White (Sysadmin)'s flatulent wordings,
> > > > Also, how are they in terms of easyness and comparibility with
respect to C?
> >
> > C and LISP are two completely different ways of approaching a problem. I
didnt f
> > ind Lisp to hard to learn once I got the idea of lists and everything
being a fu
> > nction into my head.
> > e.g. here is code to get the factorial of a number:
> > in lisp:
> > (defun fact (n)
> >         (if (= n 1)
> >         1
> >         (* (fact (- n 1)) n)))
>
> in C:
> int factorial(int n) {
> if (n==1)
> return 1;
> else
> return n * factorial(n-1);
> }
>
> > in C:
> > int factorial(int n){
> > int result=1;
> > while (n > 0) {
> >         result=result*n;
> >         n--;
> >         }
> > }
>
> in Lisp:
> (defun (factorial n)
>   (do ((result 1 (* result j))
>        (j n (- j 1)))
>        ((<= j 0) result)))
>
> factorial can be programmed recursively or iteratively in either language
> (Paradoxically, Lisp's do, which is an interation construct like a for
loop,
> is actually a macro defined in terms of recursion using Lisp's lambda
special
> form)
>
> > There are some similarities between the two, but after learning lisp you
> > will find that your C programs contain lots of functions calling other
> > functions calling functions for several months!  Ive never used Lisp in
> > Linux, when I had to use it I used Allegro in windows -
>
> Well, what you're highlighting there is the difference between the
> functional and imperative style of programming.  Functional languages like
> Lisp prefer repetition through recursion, imperative languages like C
prefer
> it through iteration, of course there's nothing preventing programming in
> either style in either language although Lisp programmers will shun you
and C
> programmers won't understand you.  There are a lot of programming concepts
in
> Lisp that you can never really do in C such as Lisp macros, higher order
> functions and continuations (a continuation is a piece of code's idea of
all
> the other code that surrounds it, in Lisp, and especially Scheme, you can
> encapsulate this as a procedure, save it, call it in a different context
or at
> a different time, whatever you want, it's an extremely flexible concept
for
> handling flow of control and you could do things like named breaks (like
in
> PERL), exception handling and even things like preemptive multitasking
using
> it).  Lisp basically covers a lot of concepts that you wouldn't even know
> about let along think about if you only programmed in C
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription
information.
> List maintainer: listmaster at domain linux.ie
>
>


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:05:20 GMT