Showing posts with label lisp. Show all posts
Showing posts with label lisp. Show all posts

Friday, February 20, 2009

progn - A Special Form in Lisp

progn is a special form in lisp that causes each of its arguments to be evaluated in sequence and then returns the value of the last one.The preceding expressions are evaluated only for the side effects they perform .The values produced by them are discarded.

Syntax of PROGN:

progn form* => result*

Arguments and Values:

forms --> an implicit progn
results --> the values of the forms.

Description:

Progn evaluates forms in lisp, in the order in which they are given. The values of each form but the last are discarded. If progn appears as a top level form within that progn are considered by the compiler to be top level forms

Examples:

(progn) ==> NIL
(progn 1 2 3) ==> 3
(progn (values 2 3 4)) ==> 2, 3, 4
(setq b 1 ) ==> 1
(if b
(progn (setq b nil) 'here)
(progn (setq b t) 'there))==> HERE
a ==> NIL

Wednesday, December 24, 2008

Learning Lisp

We are going to direct our attention towards the structure of data in the Lisp language. All expressions in Lisp are in the form of a list. Even functions will be in the form of a list. And now, meet the list.

A list is a linear arrangement of objects separated by blanks and surrounded by parentheses. The obkects which make up a list are either atoms or other lists. An atom is the basic unit of data understood by the Lisp language.

Here are some atoms

carbon
eve
1
bananastand

Here are some lists:

(1 2 3 4)
((i hate) (peanut butter) (and jelly))
(you (walrus (hurt) the (one you) love))
(add 3 (mult 4 5))
(garbage (garbage) out)

Let's introduce some Lisp functions which manipulate lists. Manipulating involves taking apart, putting together, and checking the values of lists. The two functions CAR and CDR are used to get parts out of lists.

Introduced in the Lisp programming language, CAR and CDR are primitive operations upon linked lists composed of cons cells. A cons cell is composed of two pointers; the car operation extracts the first pointer, and the cdr operation extracts the second.

Thus, the expression (car (cons x y)) evaluates to x, and (cdr (cons x y)) evaluates to y.

When cons cells are used to implement singly-linked lists (rather than trees and other more complicated structures), the car operation returns the first element of the list, while cdr returns the rest of the list. For this reason, the operations are sometimes given the names first and rest or head and tail.

Small Example which describes clearly about these two. In the below example (ADD 1 2 ) is a list given as input to these two functions.
(CAR '(ADD 1 2)) results

ADD

(CDR '(ADD 1 2)) results

( 1 2 )

Tuesday, December 23, 2008

Lisp Tutorial

1. Introduction: Why Lisp ?

If you think the greatest pleasure in programming comes from getting a lot done with code that simply and clearly expresses your intention, then programming in Common Lisp is likely to be about the most fun you can have with a computer. You'll get more done, faster, using it than you would using pretty much any other language.

If you've used Lisp in the past, you may have ideas about what "Lisp" is that have little to do with Common Lisp . While Common Lisp supplanted most of the dialects it's descended from, it isn't the only remaining Lisp dialect, and depending on where and when you were exposed to Lisp, you may very well have learned one of these other dialects.

Other than Common Lisp , the one general-purpose Lisp dialect that still has an active user community is Scheme. Common Lisp borrowed a few important features from Scheme but never intended to replace it.

Originally designed at M.I.T., where it was quickly put to use as a teaching language for undergraduate computer science courses, Scheme has always been aimed at a different language niche than Common Lisp ,. In particular, Scheme's designers have focused on keeping the core language as small and as simple as possible. This has obvious benefits for a teaching language and also for programming language researchers who like to be able to formally prove things about languages.

2. Syntax and Symantics

i) Lisp is syntax is quite different from the other languages. In lisp everything is enclosed between parenthesis("(",")").

ii) The evaluation rule for function call forms is simple: evaluate the remaining elements of the list as Lisp forms and pass the resulting values to the named function. This rule obviously places some additional syntactic constraints on a function call form: all the elements of the list after the first must themselves be well-formed Lisp forms. In other words, the basic syntax of a function call form is as follows, where each of the arguments is itself a Lisp form:

(function-name argument*)

Thus, the following expression is evaluated by first evaluating 1, then evaluating 2, and then passing the resulting values to the + function, which returns 3:

(+ 1 2) so,if you want to evaluate value of 2*3+4 you should give in lisp like this (+ * 2 3 4).

Tuesday, December 2, 2008

Develop Lisp Application-Cusp Eclipse plug-in

If you think the greatest pleasure in programming comes from getting a lot done with code that simply and clearly expresses your intention, then programming in Common Lisp is likely to be about the most fun you can have with a computer. You'll get more done, faster, using it than you would using pretty much any other language.It can also help those seasoned in the Java™ programming language, PHP, or C/C++ think in new ways when developing applications. In addition, you can do some pretty cool things with Lisp. Find out how to develop Lisp applications using the Cusp Eclipse plug-in.

Cusp is development environment for common lisp programing language. Using Lisp, you can develop all sorts of applications, including Web applications. Lisp is the second oldest programming language still used widely today (after Fortran) and is known as the first functional language. The creation of Lisp began in the late 1950s and was first implemented in 1958 by the MIT Artificial Intelligence (AI) Project. Its strength is in the processing of lists: AI and symbol mathematics. You'll notice that Lisp is not at all like other general programming languages. For example, in most general programming languages, you perform multiplication just as you would on paper: int times = 5 * 5;.

With Lisp, the following would produce 75: (* 5 5 3). The maximum in this list: (MAX 9 8 7 6 20) returns 20.

Steps to install Cusp:

1) First you need to install eclipse in your system.
2) After installing it,click on 'help' in file menubar and then click on software updates, in that find and install and then select the radio button find new features to install (Help->software updates->find and install->find new feauters to install).
3) Then a small window is opened in that click on 'new remote site' then it opens a tiny window providing two text fields in that you need to fill up those as follows:

a) Name:Cusp Update Site
b) URL Name: http://www.sergeykolos.com/cusp/update

4) Then click on 'ok' button and then click on finish button.
5) Then you will be brought another new window showing new Cusp features to install ,and in that click on checkbox named "cusp update site".
6) Then continue with pressing "next" button. This will installs cusp plug-in in your ecplipse editor.
7) Then you can do the new projects as same as java i.e. click on file and then select " new lisp project" etc..