Pages

Tuesday, July 30, 2013

Quick sort Using LISP - Main part....


Main Part:

(defun main()

(print "Enter the Limit")

(setf  l(read))

(setf  ar ( make-array l))

(print "Enter the Elements")

(dotimes (i l)

(setf  (aref ar i)(read)))

(qsort  0(- l 1)

(dotimes (i l)

(print (aref ar i))

)
)



Note:

1)The general function for extracting the element of any array is aref.
(aref array index1 index2 ...)
eg:-  
(aref ar i)

2)A multidimensional array is created as follows:
(make-array  dimension-list)
eg:-
( make-array l)

(setf  ar ( make-array l))

3)To set the value of an element in an array you say
(setf (aref array indices...) val) 

(setf variable-symbol expression) 
Evaluates expression, and stores its value in the variable associated with variable-symbol. Then it returns the value of expression.

4)Repeatedly evaluates its arguments. One example is dotimes. This macro is an iterator (a looping control structure). Like most iterators in Lisp, dotimes requires a variable. 
Here's the format:

(dotimes (var high-val optional-return-val) expr1 expr2 ...)
eg:-
(dotimes (x 4 "yo") (print "hello"))

5) Functions are created by calling a function-making macro. This macro is called defun.
A simple version of defuntakes the following general form:

(defun function-name-symbol (param1 param2 param3 ...) expr1 expr2 expr3 ...)
eg:-
>(defun do-hello-world ( )

"Hello, World!"
)

>(do-hello-world) 

No comments:

Post a Comment