You are on page 1of 6

Assignment

Submit by

Haider Ali
(17708)

Submitted To
Aisha Naseem

BACHELOR OF
SCIENCE
In computer science

6th Semester B

Department of computer science


RIPHAH INTERNATIONAL
UIVERSITY FAISALABAD
CAMPUS.
Modern programing languages
Assignment
Topic:
LISP (list processing)

 Introduction:
Lisp, which stands for list processing, is a functional programming
language that was created to facilitate the manipulation of data strings.
Lisp is one of the oldest programming languages still in use, with several
dialects that have influenced the development of other languages.

 History:

In 1959, John McCarthy at the Massachusetts Institute of Technology


created th first version of Lisp. The language was first officially
implemented on an IBM 704 mainframe using punched cards. More than
a dozen mainstream dialects were developed and used in a variety of
contexts between the 1960s and the 2000s.
As programmers shifted to more modern programming languages in the
1990s, Lisp's popularity began to wane. However, computer scientist and
entrepreneur Paul Graham was instrumental in reviving interest in Lisp.

 Advantage:

The advantages of lisp are.


 It’s a relatively simple language.
 It has a fantastic metaprogramming capability. Its macros are very
powerful.
 It's a neat approach to functional programming.
 Some implementations, such as SBCL, are extremely fast.
 It's a relatively simple language with a powerful CLOS extension
for object-oriented programming.
 Basic syntax of Lisp
LISP programs are made up of three basic building blocks
 atom
 list
 string
Atom
An atom is a number or string of contiguous characters. It includes numbers
and special characters.
Following are examples of some valid atoms.
hello-haider-learn-program
8789902
Color#268
atom145
haider
*hello*
List
A list is a sequence of number or string contiguous characters in parentheses.

(g ( e e a) 12 34 5)
(sun mon tue wed thur fri sat)
()
( People call me list)
(haider ( Love programming))
String
 A string is a group of characters enclosed in double quotation marks.
" People call me string"
"Steps require to solve this is:"
"Hello 'How are you haider'! "
"a ba c d efg #$%^&!"

Example
Example 1:
Block code
#! /usr/bin/gcl -f

; create a block of statements,


; can be placed anywhere a single statement would be,
; first element of the block is treated as its name (not evaluated)
; the return value of the block is the return value
; of the last statement

(block
myBlockName
(format t "this is my block~%")
(format t "return the list 1 2 3~%")
'(1 2 3)
)

; the name allows us to have nested blocks, and thus


; to use the name of a specific block when we want to
; do something like return-from, e.g.
(defvar result
(block
outer
(format t "in the outer block~%")
(block
inner
(format t "in the inner block~%")
(return-from outer 3))
(format t "back in the outer block~%"))) ; <-- never reached

(format t "after all loops, result is ~A~%" result)

; note that many of the different block forms (let, prog, etc)
; either use an implicit block name of nil
; or allow the programmer to assigne a name to the block

Example 2:
Local function
; sample global function, f1, with local functions f2 and f3
(defun f1 (p1)
; local function f2
(labels ; the first part of labels is a block of local function definitions
( ; create a local function f2, that takes parameters p2 and x
(f2 (p2 x)
; the body of the function prints p2 and x and returns their sum
(format t "in f2, p2 is ~A~%" p2)
(format t "in f2, x is ~A~%" x)
(+ p2 x)
)
; create a local function f3 that just squares p1
(f3 () (* p1 p1))
) ; end of local function definitions

; begin the body of f1


(format t "in f1, p1 is ~A~%" p1)
(format t "in f1, result of calling f3 is ~A~%" (f3))
(f2 7 3.5) ; call and return result of f2
)
)
Example 3:
Misc of time
#! /usr/bin/gcl -f

(format t "the current time/date is ~A~%" (get-universal-time))

(format t "the internal system run time for this process is ~A~%" (get-internal-
run-time))
(format t "...and now the time is ~A~%" (get-internal-run-time))
(format t "display the time to compute (* 3.5 3.5):~%")
(time (* 3.5 3.5))

You might also like