Monday, May 22, 2006

EMI Computation in LISP

(defun emi(p r n)
  p is the principle
  r is the annual rate of interest (as a fraction, 10% is 0.1)
  n is the number of instalments
  (* p (/ r 12)
     (/ (expt (+ 1 (/ r 12))  n)
        (- (expt (+ 1 (/ r 12)) (- n 1)) 1))))

(emi 100000 0.15 36)

Wednesday, May 17, 2006

Mysterious exits of the interpreter on slime with emacs

(I am a bit of a novice in lisp etc)

I was working with some stuff with lisp in emacs and slime and the slime mode kept displaying something like "lisp connection closed unexpectedly".

When I inspected the running processes (with ps -ef) I would see the executing (I use CLISP). And if did 'M-x slime' again, it would ask me if it should start 'another inferior LISP' and on saying no would connect right back to the old interpreter - but if ran my code again the same thing would happen.

Then I poked around in the list of buffers ad cound this interesting buffer called '*inferior-lisp*' and that had the info I was looking - my program was causing a stack overflow. :-).

Looking at the buffers "*Messages*" and "*slim-events*' did not help much (apart from telling me what I already knew - the connection was lost).

Thursday, May 11, 2006

LISP Arrays

I found practically no "single source" tutorial on how to work with arrays in
(Common) LISP (although by browsing around, one can learn it -
like I did :-) ). Here I attempt to present a simple tutorial on the usage of
one-dimensional arrays. The higher dimensions can be used by imaginatively
extending the usage...

Creating Arrays

Array with 5 slots:

CL-USER>(setf foo (make-array 5))
Array with 5 slots - each initialized to 0(zero):
CL-USER>(setf foo (make-array 5 :initial-element 0))
#(0 0 0 0 0)
Array with 5 slots - initialized to a custom list of values:
CL-USER> (setf foo (make-array 5 :initial-contents '(0 1 2 3 4)))
#(0 1 2 3 4)
Array with 5 slots - initialized to heterogeneous types of values:
CL-USER> (setf foo (make-array 5 :initial-contents
'(0 "one" 'two '("t" "h" "r" "e" "e") nil)))
#(0 "one" 'TWO '("t" "h" "r" "e" "e") NIL)
Number of slots in the form associated with initial contents must match the number of slots in then array.

Working with Arrays

LISP Arrays work with a zero based index Scheme (:-) ).
Accessing the value at an index:
CL-USER> (setf foo (make-array 5 :initial-contents '(0 1 2 3 4)))
#(0 1 2 3 4)
CL-USER> (aref foo 3)
Assigning to a value at an index:
CL-USER> (setf foo (make-array 5 :initial-contents '(0 1 2 3 4)))
#(0 1 2 3 4)
CL-USER> (setf (aref foo 3) "three")
CL-USER> foo
#(0 1 2 "three" 4)
(From the above it is clear that) Like many other "pointer" functions of LISP, aref returns something that is suited both as an lvalue and an rvalue. This is magic incanted by setf macro and define-setf-expander macro. See
  1. section on assignments
    and generalized assignments
    of peter siebel's book to learn more about setf
  2. hyperspec for setf and define-setf-expander.
fill pointers control the location at which vector functions such as vector-push and vector-pop.
CL-USER> (setf foo (make-array 5 :initial-contents '(0 1 2 3 4) :fill-pointer 3))
#(0 1 2)
CL-USER> (vector-push "three" foo)
CL-USER> foo
#(0 1 2 "three")
CL-USER> (vector-pop foo)
CL-USER> foo
#(0 1 2)
CL-USER> (setf (fill-pointer foo) 4)
CL-USER> foo
#(0 1 2 "three")
CL-USER> (fill-pointer foo)
Notice that "three" is still lurking there after the pop.


Friday, May 05, 2006

Cool lisp tool!

This is a cool Lisp Tool!!

The javascript itself is not extremely complicated but its a novel idea. Really makes lisp code browsing on the web a better experience.

One would really like to combine the effects of htmlizer and this tool.

I could hsow you some examples here - only, the blog site is draconic about not allowing scripts in my post :-(.


Thursday, May 04, 2006

Who are the most recognizable scientists?

Chad Orzel posts in his blog about

This raises the question, though, of who belongs on the Mount Rushmore of Science: Who are the four most iconic scientists out there, who deserve to be memorialized in titanic stone sculptures, ideally on the Moon or somewhere similarly cool?

Iconic: see semiotic and Semiotics for Beginners

Icon/iconic: a mode in which the signifier is perceived as resembling or imitating the signified (recognizably looking, sounding, feeling, tasting or smelling like it) - being similar in possessing some of its qualities: e.g. a portrait, a cartoon, a scale-model, onomatopoeia, metaphors, 'realistic' sounds in 'programme music', sound effects in radio drama, a dubbed film soundtrack, imitative gestures;

Well, since their features are to be carved, an average 'man' must be able to identify them(the carvings) as being similarities of them(the scientists under question).

But as "art imitates art", there must already be some depictions of those scientists that are deeply engraved in people's minds for the project to serve its purpose. Otherwise one would creating those images now: not a bad idea, actually, but does not serve the purpose(there is no face that is iconic).

Einstein - yes , most certainly yes. Almost everyone has seen that one depiction of him.

Archimedes - there is a bust that is believed to represent him, but by now, it looks like a generic Greek (similar to what Julian Barnes writes about that painting the raft of medusa). Not a candidate.

Newton: hmm, we only have a dim idea of what he might have looked like (assuming you have not seen that history channel program on newton where they have actually had some actors act like newton (who knows how he 'acted'!)).

Darwin: yes - many people remember that beard-y picture in a nice angle(only, the cited article does not have the one I have in mind).

Freud : yes this photo is recognizable (not that I think he was a great scientist or anything).

Marie Curie : yes everyone knows her by face.

Faraday: may be. He and Marie Curie have beeen on currency notes already - which is one way by which many people might know their faces (but also, lets not forget that currency notes are long gone now and so are the people who used to trade with them).