Facebook badge

Amol Aggarwal's Facebook profile

About Me

I like to write once in a while. I hope you will like my blog.

Wednesday, July 2, 2008

About lisp -part 2

A programmable programming language
Lisp is a great tool generating tool.Those of you who don't fully know about the advantages of programming bottom up read this :
http://www.paulgraham.com/progbot.html .
It is a fairly small article and can be read quite fast.What we are talking about here is symbolic processing . Syntax manipulation is the most commonly used aspect of Lisp's symbolic processing capabilities currently. The defmacro form provided by Common Lisp allows one to define new language forms which have full access to the symbolic information of the code within their bodies. Within the macro definition, the entire facilities of the Common Lisp language may be used, including any other functions or macros you have defined. This model is extremely powerful, and many advanced techniques for using it are explained in Paul Graham's book, "On Lisp".
Ex:
The macro loop
You can do the following with a LOOP:
  • Step variables numerically and over various data structures
  • Collect, count, sum, minimize, and maximize values seen while looping
  • Execute arbitrary Lisp expressions
  • Decide when to terminate the loop
  • Conditionally do any of these

In imperative languages, a value can be assigned a name, and this name is
called a variable. For example, “x=3”, and whenever this “name” is
encountered, it is evaluated to its value. It does not make any sense, to
have variables without a assigned value. That is, the “x” is not useful and
cannot be used until you assign something to it.However, in lisp, there is
a concept of Symbols. As a way of explanation, a “variable” needs not to
be something assigned of a value. Symbols can stand by themselves in
the language. And, when a symbol is assigned a value, the symbol can
retain its symbolic form without becoming a value.This means that in
lisp, “variables” can be manipulated in its un-evaluated state. The situation
is like the need for the “evaluate” command in many languages, where the
programmer can built code as strings and do “evaluate(myCodeString)”
to achieve meta-programing.The power of symbolic processing comes
when, for example, when you take user input as code, or writing
programs that manipulates the source code, or generate programs on the
fly.
One way for a imperative programmer to understand symbols, is to think
of computing with strings, such as which Perl and Python are well known
for. With strings, one can join two strings, select sub strings, use string
pattern (regex) to transform strings, split a string into a list for more
powerful manipulation, and use “evaluate()” to make the string alive. Now
imagine all these strings need not be strings but as symbols in the language,
where the entire language works in them and with them, not just string
functions. That is symbolic computation.Here we see, a expressibility
unseen in non-lisp family of languages.

No comments: