gusl: (Default)
2006-06-17 05:00 pm
Entry tags:

the value of flet

flet saves us from repeating often-used arguments:

(defun funky (x)
  (flet ((mult (y) (* x y)))
    (mult 4)))

(funky 5)
=> 20

A more realistic example, in which we want functions to use implicit arguments: (Coming soon...)
Read more... )

It would be nice to have something to automatically bring a function in and out of an flet, i.e. the scope of another function.
* flet2defun would make explicit the implicit arguments (i.e. variables that are global relative to the flet) by adding these variables to the lambda list.
* defun2flet would do the opposite: it would make the lambda list shorter by eliminating arguments already defined in the new scope. The latter can be accomplished by currying.

This implicit/explicit distinction can be observed in C++: class methods can use class properties as well as arguments passed. Class properties are usually seen as not being "inherent" to the function, or at least it's not what one should focus on when trying to understanding what the function does.
gusl: (Default)
2006-06-17 03:50 pm
Entry tags:

ideas for tracing in Lisp: trace calls, not functions

One could use an expression like "~" to mark the expressions that one would like to trace when evaluated.

(defun analyze (group)
  (let* ((games (get-pairs group))
	 (scores (mapcar #'(lambda (game)
			     (progn (format t "~A:" game)
				    `(,game ,(read))~ )) ;; <--- THE ~ IS HERE!
	 (table (make-table group scores)))
    (format t "~A~%" scores)))

would only print the result of the hidden "list" calls (quasiquote expands to (list game (read))).

I really think this would be better than the commonly-used solutions out there. Other tracing solutions:

* tracing functions: usually nice, except sometimes you only want to see the result of a particular call in the code, not all calls. Also, I sometimes wish I could define the condition on which the trace is shown... i.e. a test of the arguments.
* breakpoints: sometimes you don't want to trace, not break!
* copying expressions: awkward, non-modular, messy (need to be deleted later).
* assigning the value to a variable, printing it later: one can always substitute EXPR with (let ((temp EXPR)) (format t "~A~%" temp) temp). Maybe the ~ could be interpreted as a macro expanding to this.
gusl: (Default)
2006-06-15 04:17 am
Entry tags:

Lisp: interactivity

(defun convert ()
  (format t "Fahrenheit: ")
  (let ((fahr (read)))
     (format t "Celsius: ~a~%" (/ (- fahr 32) 1.8))))

Thanks to Jabberwockey, randomly found at
gusl: (Default)
2006-06-02 10:29 am
Entry tags:


Linj is brilliant! It's a Lisp dialect for translating into Java and it produces readable, editable code:

from the Linj Manual:
Finally, and because a language is not only syntax and semantics but also pragmatics, Linj also tries to translate between Common Lisp conventions and Java conventions.

Even the language manual is quite entertaining, at least in the beginning. I like the jokes with obfuscated code.

Linj, like CL, saves you from explicitly declaring types. When translating to Java, it infers what the type should be.
gusl: (Default)
2006-05-02 03:17 am
Entry tags:

Hamburg and Lisp

The Lisp conference was pretty good. Very intensive and exhausting to me. Despite meeting lots of interesting people, the introvert in me eventually started complaining loudly, so much so that on Monday I took the day for myself.
Here's some of the people I met:

* Jans Aasman from Franz Lisp, who used to be a cognitive modeler / human factors professor and is now into semantic web stuff. Much of it was called "70s AI". There are some interesting SQL Prolog hybrids, in which one can make very expressive queries that SQL simply cannot do, because they involve deduction (SQL would need to create a separate table for every possible deduction).

* James Anderson, who works for a strange company in Marbella, Spain (a beach resort full of British tourists). They try to predict the stock market by using time series information ("technical analysis") as well newspaper headlines (i.e. "market-external", "fundamental analysis"). From my perspective, this is very cool epistemological work: how do we combine this information of different kinds? Again, they probably benefit from semantic web stuff (when I asked, he said "I am not allowed to answer your question").

* Andreas Franke, who works in Mathematical Knowledge Management with the Saarbr├╝cken people.

* Christophe Rhodes, who demo'd some some CLIM graphics software, in particular a terminal shell that mixes text with graphics, and where everything is clickable. This is a really obvious idea, which makes me wonder why I never thought of it (or don't remember having had this thought specifically).

Unfortunately, I missed the last talk on numerical simulation / signal processing, which was considered the best talk by many people. Afterwards, I had dinner standing up, and talked to more people.

After 16 hours indoors, I finally went home at around 1am. I really wasn't clicking with people very much. While I can be arguably said to be a language geek, I am mostly a user: I mainly use Lisp for assisting me with my theoretical endeavours. I am *not* a compiler geek or an implementation geek, or a graphics library geek, etc... so most of the conversations going on at the conference were over my head, and not that interesting to me (unlike most of the talks).

Anyway, Hamburg reminded me of Amsterdam, only dirtier.


On the train back from Hamburg, I found out I had power, so I decided to write some generic machine learning code... I decided on the goal of doing some pattern discovery. So I started by writing a linear regression algorithm.

Lisp is great here because you can pass functions. This way, you can pre-process the dataset and/or create extra tables over which to do the regression. The data set is basically a bunch of parametrized lists. With SELECT, you can filter your dataset before sending it to the regression (i.e. "only consider males").

As a tangent, I came up with this very short implementation of "transpose" (yes, matrix transpose), of which I am proud:

Here is the spoiler for those who want to try it out for yourselves firstRead more... )

Needless to say, the 6 hours passed really quickly.
gusl: (Default)
2006-04-29 03:44 am
Entry tags:

Lisp meeting in Hamburg

This trip to Hamburg is costing me more than I expected:

175EUR in train fares
110EUR in hotel rates
137EUR in conference fee + dinners

Hopefully, what I learn and who I meet will make it worth it.
gusl: (Default)
2006-04-25 06:24 pm
Entry tags:

Lisp and shell commands

(run-program "/bin/sh" '("ls"))
source: 1

Now I just have to figure out how to get the output into Lisp.

(sb-ext:run-program "/bin/ls" '() :output *standard-output*)

will print the contents of the current directory into my SBCL shell, but it still returns # < SB-IMPL::PROCESS 28608 :EXITED > .

Since this stuff is implementation-specific, I don't know the right place to search for documentation.

(with-output-to-string (s) (sb-ext:run-program "/bin/ls" '() :output s))

returns the output of ls! Exactly what I wanted!

Now I just need the Lisp equivalent of Perl's split();
gusl: (Default)
2006-04-10 08:02 am
Entry tags:

Lisp optimizations

given a, fn, l, test

1: (member a (mapcar fn l) :test test)
2: (exists #'(lambda (x) (test a (funcall fn x))) l)

If fn is purely-functional code (i.e. no side-effects), then these two are the same, since they evaluate to the same thing. The former is easier to write, but the latter is more efficient. A declarative language should allow you to express things the former way, and yet compute it efficiently.

Are there Lisp code optimizers that work by doing this kind of code rewriting?
gusl: (Default)
2005-05-12 10:49 pm

how do you prove theorems about Lisp code?

It's impossible to prove Pi_1 statements without axioms that talk about infinity.

If it were possible, I would like to do it right now with Lisp. I have implemented a refuter for general Pi_1 statements, but even though implementing a verifier would never be successful, I still firmly believe in some proofs of Pi_1 statements. That means that I must implicitly accept axioms about infinity, much as I'd like not to.

Here's a nice theorem:
;;;All numbers with an odd number of divisors are perfect squares:
(forall #'(lambda (n) (implies (not (perfect-square-p n)) (evenp (n-divisors n)))))

And here's a nice proof:

(Lemma 1) Forall n in N, n is a perfect square IFF its prime factorization has an even power at all the primes.
(Lemma 2) Forall n in N, n-divisors(n) = PRODUCT (power(p_i,n) + 1) for each prime p_i in the factorization of n

Suppose n is not a perfect square (1)
Then there is a prime p in the prime factorization of n such that its power is odd. (by 1, L1)(2)
Since power(p,n) is odd, then power(p,n) + 1 is even. (3)
Then n-divisors(n) is even. (by 3, L2) (4)

But which axioms am I using in this proof? Are they too hard to dig out of the lemmas? My justification for the lemmas is my visual intuitions. Somewhere in proving them in any kind of system, you would need an axiom about infinity, right?

in case you want the rest of the Lisp code:
Read more... )