Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to load a program file? Lisp programs in Allegro are saved under the file extension.cl. To load a file into the Lisp console, use the following: (load.

Similar presentations


Presentation on theme: "How to load a program file? Lisp programs in Allegro are saved under the file extension.cl. To load a file into the Lisp console, use the following: (load."— Presentation transcript:

1 How to load a program file? Lisp programs in Allegro are saved under the file extension.cl. To load a file into the Lisp console, use the following: (load “myprogram.cl”) or perhaps (load “c:/myprogram.cl”) If you have a function in myprogram.cl, then you can call it in the normal manner.

2 Keyword argument Allows arguments to be given in any desired order. Arguments are not matched with parameters by positions, but rather by special tags. These tags are known as keyword. Example: (DEFUN keytest (&key x y) (- x y) )

3 Iteration (1) There are mainly 3 types of iteration constructs provided by LISP. Loop For example: (setq count 4) (loop (setq count (+ count 1)) (when (> count 7) (return count))) Termination condition

4 Iteration (2) dolist For example: (dolist (x ‘(a b c)) (print x)) Dolist is useful when u want to process the element of a list one by one. In the above example, the dolist traverse through the list, one element at a time. You can return a value from a loop by using return as seen in the previous slide.

5 Iteration (3) The most complex iteration - do (do ((x 1 (+ x 1)) (y 1 (* y 2))) ((> x 5) y) (print y) (print ‘OK) ) Initialization Update Loop condition Return value of do

6 Binding (1) Binding is defined as lexically scoped assignments. Example: The formal parameters of a function are bound to the actual parameters only for the duration of the function call. You can bind variables anywhere in a program using let as follows: (let ((var1 value1) (var2 value2) ….. ) body…)

7 Binding (2) The bound values are only visible within the let block. Variables that are bound in a particular let block cannot be referenced when defining other bindings within the same block. Example: (let ((x 1) (y (* x 2))) y ) To overcome this limitation, another special form let* is used. Now replace let in the above code with let* and see what happens.


Download ppt "How to load a program file? Lisp programs in Allegro are saved under the file extension.cl. To load a file into the Lisp console, use the following: (load."

Similar presentations


Ads by Google