Facebook badge

Amol Aggarwal's Facebook profile

About Me

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

Friday, December 19, 2008

c vs lisp macros

Thanks to Kevin Clancy for his post .
Original link

Lisp macros
A C preprocessor operates on source tokens. A Lisp macro
operates on the abstract syntax tree produced by parsing the source
tokens. A C preprocessor can replace a token (or a simple pattern of
tokens) with some other tokens. A Lisp macro can perform arbitrary
computations on the input syntax tree, using the full power of the
language and runtime, and the input it operates on is a structured
syntax tree represented as a Lisp list, not a stream of characters or
tokens. You could in theory make a C preprocessor do anything that can
be done in C, but if you want to go beyond what the typical preprocessor
does, you pretty much have to write a new preprocessor. Lisp's macro
facility is out of the box able to easily do anything to the input tree
that Lisp can do to lists, which is quite a lot.
A macro merely takes one sexp (which we think of as "code") and
transforms it into another sexp. Ever notice how you don't perceive
sourcecode character-by-character? You mentally see it as symbols,
numbers, etc. Well, after lisp slurps in the characters of your
sourcecode and turns it into sexps, you can conveniently manipulate or
analyze this code just like any sort of data.
Lisp macros rulezzz.

Saturday, November 29, 2008

The good things about American culture

At one of the gas stations which doesnt accept credit card I noticed that everybody fills the gas at gas station (completely blocked out of the view of the owner sitting inside a shop) and goes inside the shop honestly to make payment all the while unsupervised. This stuff is impossible to find in India. A sharp contrast to the perception some of us assume in India about American culture.
People are very hard working here . Teens start working very early and they make their own money to finance their college. The maturity level in them is high as compared to Indian teens.
People are very knowledgeable about the work they do. Meritocracy is given very high importance and everyone does his or her job well . People know their stuff and moreover they enjoy doing it well.
Lastly women are given more respect than in India and treated on a more or less equal footing as men.

Thursday, November 6, 2008

Software developers - work at home

Development of software doesn't really require you to work at a same place .First I am going to list some of the things people say about working in an office . The advantage of an office is that it gives people less of an excuse to slack off .There are other people watching you and you become sort of more accountable.Face to face communication is surely more effective than say communicating through telephone or email.Also it involves a sort of social gathering where people can chit chat for a while.Working alone does become little lonely.But these advantages do lose their significance when you compare it to working alone.People can slack off at office also.The bad thing about working in an office is that sometimes you have to pretend that you are working simply because the cubicle of boss is just next to your cubicle .Some people do come early and work till evenings not because they are doing great work but simply because they have to impress other people . There can be new models of accountability besides man hours put into work i.e. one can gauge the amount and kind of work you do in fixed time at your own sweet convenience. Ok no substitute for face to face communication but video teleconferencing comes pretty close. About being socially comfortable I believe person should put their best effort during the 'office hours' and can socialize to his or her heart's content in his free time.Although I would say there is no substitute for office friends and all those office romances. When I say you don't need to be physically present with your colleagues I mean that you can collaborate quite closely with1.an instant messenger.2.telephone.3.Some video conferencing software.4.file sharing software.That means that would save millions of dollars of rental cost ,office equipment and hardware costs.Also it would lead to increase in productivity as people would work in quite and soothing environment of their home or in whatever place they want to live.But this concept involves a paradigm shift in thinking and people are generally so impervious to change .Or wouldn't working at home and collaborating on internet like open source guys do wouldn't have become more popular in software industry from the time internet did came into widespread use.

calorie restriction

Calorie restriction is a technique for increasing the maximum life spans in humans. It is basically reducing the energy intake while packing your diet full of minerals and vitamins. Although much research hasnt been done on the subject in humans and is limited to small animals,its proponents swear that it is only scientifc proven theory that elongote life. The effect has lead to a lower cholestrol levels resulting in better cardiovascular health in humans ,reduced blood sugar preventing diabetes and BMI levels of around 19 which is at a lower level in humans and reduced weight . The clinical trials are currently going for humans .This regime is not without its side effects which include feeling lethargy and tired ,depression, and risking muscle loss .(the people generally restrict the calorie intake to 1600 cal which is around 800 calories less than 2400 calories --the recommended value for normal diet).Also CR can be pretty expensive and require quite a bit of discipline.

Driving in USA - what we Indians can learn from Americans

I just passed my driving knowledge exam and will soon start taking driving exam before I give my practical exam . Driving here is a lot safer as compared to India although cars are lot faster here . The average speed on highways is nearly 70 mph which comes to 112 km/hr while cars hardly travel at 70 km per hour on highways in india.
The emergency vehicles have a right of way. Most people will die on their way of hospital or the house will get burned down before the fire brigade arrives in India. Not here . People pull over to the right side of the road (here you drive in opposite direction) and stop . All the cars out there give way and make sure emergency vehicles reach to their destination as soon as possible....
Driving is very pleasurable. No honking of horns unless it is an emergency. People drive at one speed in their own lane. Seperate lane for motorbikes. The road gets constructed extremely fast here and hardly you see bad roads. An array of road signs to help you in every possible way.
The businesses ( shops ) are required to have proportionate parking space for vehicles. That means you will never have any parking problems . Also a seperate parking area for disabled people.
Good traffic engineering allows less wait times at signal . Go left (right in india ) if there is no oncoming traffic.
Hey best part for pedestrians . One yields the way for pedestrians if they are crossing the road near signals or businesses parking spaces . One cant imagine a similar situation in India where you can die if you try to go before on foot before a vehicle .
Stop behind a school bus if it has a red signal behind it . YES traffic light attached behind a school bus. :)

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.

About lisp

Why not lisp :->
1. CL lacks standardized support for many operations that are necessities in today's world (e.g. sockets, database connectivity,foreign functions). i.e. these features are not in the ANSI standard (which is 14 years old which may explain why new features were not standardised).Therefore one must choose between using implementation-specific features or writing to the least common denominator (ie writing code which works for all implementations which is very inefficient). Implementing new revisions to standard requires a lot of time and money.
2.Some of CL's core is badly designed. For example, consider NTH and ELT. The functionality of ELT is a strict superset of NTH, so why have
NTH cluttering up the language? Say I want to get nth element in a list i get confused as both elt and nth are in the language.
Why is the function that computes the difference of two sets called SET-DIFFERENCE, but the function that computes the intersection
of two sets called simply INTERSECTION? And why do all of these functions operate on lists, not sets? It's because there are no sets in
CL, which means that CL leads one to prematurely "optimize" sets as lists.More to come on this.
3.Lisp sadly lacks good library support . That means sometimes very ordinary stuff which can be done very easily in say Java will take quite a lot of time in lisp. Say you need a functionality to do something quickly ,you simply take an appropriate function from a well documented library. Creating your own libraries is not a solution when stuff needs to be done within a deadline as expected by business clients.
4.Lisp is not a mainstream language and is hardly been used in the software industry. Just being good enough is not sufficient . The lisp on your resume is not going to make much impact .Ron Garret who programmed in lisp for twenty years and has also written some highly referenced papers on lisp says that his adoption of lisp as a career option destroyed his career as a programmer.You could contact him on comp.lang.lisp on google groups.