LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] LISP & Prologue

[ILUG] LISP & Prologue

Smelly Pooh plop at redbrick.dcu.ie
Wed Feb 2 06:39:11 GMT 2000


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




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell