Desi Founder @ Work

19 Apr, 2008

What Lisp & Assembly instill

Posted by: sharjeel In: Programming

My Assembly Programming Language teacher, Belal Hashmi Sahib said in the first lecture of the course, “Assembly is extremely simple. It is so simple that students don’t expect such simplicity and hence it starts appearing complex to them”. Then he wrote MOV AX, BX on the board, explained it and asked if everyone understood it. Everybody nodded. He asked again to make sure there was not even a slightest bit of confusion. It seemed very simple and trivial to everyone. He proceeded by saying “This is the end of the assembly language programming course. The rest of the course is just the revision of MOV AX,BX”. Everybody thought it was a joke but later it turned out that assembly indeed ended at MOV AX, BX. The rest of the course was about learning other concepts to fully utilize the potential of MOV AX, BX.

Last year I learned Lisp on my own and then TAed a course on Lisp at LUMS with Dr. Umar Saif. In the first lecture the first thing Dr. Umar taught was (lambda (x) (+ x x)). At this moment I realized that just like Assembly, Lisp had finished! Because if students had understood it, there was nothing much about the language left. All they needed now was to understand some important concepts such as recursion, closures etc. to use Lisp.

What is common between Assembly and Lisp? Both of these two languages are very simple to learn as they have little syntax or fancy language features. However the process of learning them compels one to grasp some important concepts. For instance by learning assembly you are bound to understand some flavor of computer architecture, interrupts, timers and other hardware related stuff. Similarly by learning Lisp you automatically get to know functional programming, interpretation, recursion, closures etc.

A programmer familiar with assembly can easily understand the use of unions, options such as __decl and other such features of C because he knows the underlying magic. Similarly if one wants to understand the philosophy of the features of Javascript, Python & Ruby I strongly recommend learning Lisp.

Tags: ,

19 Responses to "What Lisp & Assembly instill"

1 | Rob

April 19th, 2008 at 7:55 pm

Avatar

From a long time assembly language programmer, what you say is absolutely true. Reading assembly is probably easier to understand than some of the hieroglyphics of other languages. As one who is just trying to find some time to learn Lisp, I’ll keep what you wrote here in mind.

2 | Bobo

April 19th, 2008 at 8:01 pm

Avatar

C is just if statements and for loops.

3 | rascunho » Blog Archive » links for 2008-04-19

April 19th, 2008 at 8:37 pm

Avatar

[...] Desi Founder @ Work » Blog Archive » What Lisp & Assembly instill Assembly is extremely simple. It is so simple that students don’t expect such simplicity and hence it starts appearing complex to them” (tags: sharjeel.2scomplement.com 2008 mes3 dia19 at_home Lisp Assembly programming blog_post simplicity) [...]

4 | Ralph

April 19th, 2008 at 8:59 pm

Avatar

I was an assembly programmer for many years, and have often written patch code in straight machine language. Writing assembler obviously brings the programmer closer to the machine.

I’ve also used various paradigm-shifting higher-level languages such as Snobol, Logo and Prolog. These take the programmer further away from the physical machine, and for good reason.

I’ve worked on p-code compilers and interpreters. I have designed and implemented some language extensions for concurrency.

On several occasions I’ve learned the rudiments of Lisp. The problem for me is that I’ve never found a good application for using Lisp.

Now I do almost exclusively web-based programming. Is there some reasonably straightforward and practical way to use Lisp to construct smart web pages? If so, I would be very pleased to try it.

5 | steve

April 19th, 2008 at 9:08 pm

Avatar

Of course the tricky thing about assembly is figuring out how all these CPU-level operations can be mapped to more high-level operations.

6 | Gareth Morgan

April 19th, 2008 at 9:24 pm

Avatar

“C is just if statements and for loops.”

Those are the simplest constructs. Take a C function

printf(”The value is %d.”, 10);

The first thing this line must do is store the string. A simple solution would be to push each character onto the stack one at a time. That’s 17 pushes including the terminal character. Next you move a pointer to the first string into a register, then the value 10 into another register. You then work out and store the return address for the call. Then you make a jump to the function code. I’ll leave the function as undefined but it must store a return value in a register, pop the return address from the stack into a register and then jump to that position. Finally the calling function will pop the string back off the stack.

Hardly the definition of simplicity.

7 | machinehuman

April 19th, 2008 at 10:01 pm

Avatar

Very well said. Reminded me Abelson’s overview and introduction to LISP (Structure and Interpretation of Computer Programs).

9 | Assembly and Lisp | Wisdom and Wonder

April 19th, 2008 at 10:12 pm

Avatar

[...] is the connection? Find out here. This was written by Grant. Posted on Saturday, April 19, 2008, at 4:12 pm. Filed under Link. [...]

10 | Carlos

April 20th, 2008 at 12:27 am

Avatar

If you think C is just Ifs and loops, you don’t understand strings and malloc, therefore you should go learn assembly.

11 | sharjeel

April 20th, 2008 at 9:52 am

Avatar

Jerf put a very nice thought:

Another example: If you understand what “x = 2″ really, really means, and the basic operations, you already understand all of conventional algebra. (That is, what is taught in K-12, not what a real mathematician would call “algebra”.)

(I actually think that this is where conventional math education goes most wrong, right here at the beginning; kids have a fuzzy conception of equals, and simply never recover from that. Without that, the kids are right, they are just wasting their time learning useless things.)

Too many kids learn the equality symbol as a directional operator, the majority I daresay. They will agree that x => 2, but if we take this fact and rewrite “2 + 2 = 4″ with “x + x = 4″, they will object that you can’t do that.

But of course you can. You can do whatever you want with an equality relation. You aren’t limited to some officially-sanction numerical recipes/magic and the simplication (meta-)operation… but that’s exactly how most people learn equality.

Once you understand, really understand that you can do anything you want to an equation, as long as you do it to both sides (correctly), algebra goes from mystifying to obvious, and instead of being an arcane collection of magical tricks, becomes an accelerated session of sharing the work of centuries to put together what we now teach as algebra.

A lot of people who would be reading this probably understand this so well already they can’t even conceive of the misapprehension I’m speaking of, but it’s the only explanation I have for some of the things I’ve seen “in the field”.

Similarly, in college, I took the “advanced” calculus. And the first thing that happened in my advanced calculus is that we spent three or four weeks working with the limit, until we had that thing down cold. And then yet more time working directly with the integration and differentiation equations and deriving all the shortcuts from scratch, repeatedly. It sounds like a waste of time, but A: If you’ve got a professor throwing every limit edge case he’s ever seen at you it’s harder than you think and B: after that, standard calculus isn’t mysterious any more. Ironically, at, say, week 4, we seemed to be way behind the “normal” calculus class, but in fact it’s only an illusion that the other class was ahead of us, in a way, because they were learning the sanctioned magic and we were learning calculus.

12 | Martin

April 20th, 2008 at 2:38 pm

Avatar

Ralph:

Try http://www.paulgraham.com/arc.html.

Also http://www.lispcast.com/ is a very good intro to web programming using CL.

Martin

13 | Shawn Fumo

April 20th, 2008 at 4:13 pm

Avatar

Ralph,

You might try looking up Weblocks, which uses Lisp to do websites. It looks pretty powerful..

14 | sacado

April 20th, 2008 at 4:42 pm

Avatar

@Ralph

“Now I do almost exclusively web-based programming. Is there some reasonably straightforward and practical way to use Lisp to construct smart web pages? If so, I would be very pleased to try it.”

You could have a look at Arc : http://arclanguage.org. It’s a new dialect of Lisp targetting at web apps. It’s rather new and still under active development,but if you are just interested in learning how Lisp could be used for web apps, you should definitely give it a try.

16 | rplevy

April 22nd, 2008 at 7:48 pm

Avatar

Hi Ralph,

Some people mentioned Arc, but it is very new, and is actually a new dialect of lisp built on top of Scheme. The idea is to make a language that could last 100 years. It was just released in kind of a pre-alpha state.

I have been experimenting with Weblocks, and would recommend it if you are interested in using Common Lisp to develop web sites. It makes use of Lisp’s ability to pass continuations in order to present a persistant state. Moreover it automatically handles browser and version compatibility, including the ability to replace Ajax behaviors with page reloads if the browser does not have javascript or has it disabled.

Rob

17 | hassan

May 14th, 2008 at 2:29 am

Avatar

One of the few things that i hate about assembly is the branching structure. BEQ, BNE and its brothers and sisters. It could have been simple IF. The second this is the small register set. The teachers usually give huge matrices to solve on only $t0 - $t9 registers. Also the text manipulation codes takes huge time and sometimes still doesnt work.

18 | Bob

July 13th, 2008 at 2:17 am

Avatar

Scheme (a Lisp) has first-class continuations, which in assembly terms are like return addresses that can be returned to any number of times. They’re a bit more than that, as they have closure and whatnot, but that’s the basic idea.

This has some nice effects for web programming. You can encode a continuation into a dynamically produced page as a URL, and when that URL is followed the continuation is invoked, so control passes back to where the function that produced the page was called. This makes the process of sending out a page over HTTP and getting back a response a single function call.

You get more control than that, though, because the continuations are values, so access to them, their lifetime etc, can be managed.

For instance, something like an order form, which may have multiple steps, but where the order can only be placed once, is made a real headache by such things as the “back” button and the “open in new tab/window” option.

This kind of thing still flusters many successful websites. Making continuations first class helps with this problem. The state(s) of the interaction is saved between pages transparently, so all of the stages can be accessed at any time in a seamless manner, until the order has completed. Then the application can destroy the continuations associated with all the intermediate steps, making them inaccessible. So things like accidental double orders or other confusions are less likely to happen.

I don’t know of any websites that have actually used this, but I think it has promise nevertheless.

For more about this, see:

http://www.cs.brown.edu/~sk/Publications/Papers/Published/khmgpf-impl-use-plt-web-server-journal/paper.pdf

19 | Bob

July 13th, 2008 at 2:18 am

Avatar

THat was at Ralph, by the way

Comment Form