Tuesday, 1 May 2012

Make a Function

In LISP, we can make function that have procedure in it. With function, we can resolve complicated problems with just a command. To make a function, follow the instruction below:



  1. Determine the name of the function and what parameter we need. 
  2. Determine what problem we will solve. Make a plan how to resolve the problem.
  3. Write the function in LISP. 
  4. Format of the function is 
                  (defun function-name (parameter1 parameter2 parameter3 ...)
                           (process how to solve problem)
                  )


Some example:
1. This function will add a b. 

    (defun add (a b)
         (+ a b)
    )

2. This function will multiple a to b

    (defun multiple (a b)
          (* a b)
    )


In LISP, we just need to write the name of function.
1. (add 4 5) 
    ==> 9
2. (multiple 3 4)
    ==> 12


Screenshot


No comments:

Post a Comment