martes, 15 de mayo de 2012

Lisp debugging, step by step. Step 1

Debugging lisp is not as straightforward as one might think at first.  Being a live environment I thought it would be a joy, like in smalltalk, racket, or elisp, which provides a quite decent tracer and stepper.  Smalltalk is another world, but I'm already getting used to it so it doesn't surprise me that much.

We all heard stories about lisp machines (genera), and eventually read some article or seen some talk about how awesome it's lisp to debug.. but for me it was not so straightforward.

I'm using SBCL for all my experimentation in CL, so the examples here are going to be all sbcl related.  First of all, some reasons on why there's not an easy mapping between your debugger on the language next door and lisp when debugging:

- Lisp normally compiles the source code to native code. Doing so, it runs lots of optimizations on your source, so the code executed has no direct mapping to your written code.
- Lisp is not line oriented, so the order of execution of code is not so easily mappable to the typical next-line, next-line... debugging.
- On the other side, you have 'trace' that lets you track all executions of a function, with params, and so. It's not so live, but with all the instrumentation that sbcl and slime provide, you can track down a fair amount of bugs just with trace.

To instrument a method to be debuggable more easily, my advice is to add this declarations.

  (declare (optimize (speed 0) (space 1) (compilation-speed 0) (debug

That'll keep sbcl out from doing optimizations that can make variables 'disappear' in runtime.

A little more info in:

and obviously, in your nearest implementation manual

lunes, 14 de mayo de 2012

CompGuile. Compile guile in ubuntu

Guile is the Gnu Scheme implementation and official extension language for gnu apps. Let alone most gnu apps disregard this rule. I always found guile a good companion because it was easily instalable in all my linux boxes.

 The other day I tried to install a newer version to work with geiser (and because I had been reading some nice things related to new versions on Wingo's blog), but the installing process wasn't as simple as ./configure && make install. Mostly my fault, because I just needed many *-dev packages that were not present in my box. But after installing gmp and some other easy-to-find libs, I got stuck into "No package 'bdw-gc' found". As jao put in a mail in guile maillist,

"You can tell configure where BDW is located by setting the above
mentioned environment variables. With libgc-dev installed from a deb, i
routinely do (in a bash prompt):

  $ BDW_GC_CFLAGS=-L/usr/lib BDW_GC_LIBS=-lgc ./configure

domingo, 13 de mayo de 2012

imap for emacs (insert templates on emacs)

You just miss good old :imap for your temporary configuration of your editor (remember vim?).  When you know you'll be going to insert similar strings over and over.

And you love the way vim allowed you to do crazy stuff inside a map.  But now you're in emacs, so let's see how we can scratch your itch.

My concrete case was inserting strings like (?* ?x) where x is a parameter.

  •  Skeletons. Skeletons can do that and much more. it's a classical template inserter.  For example, you can setup a skeleton of the desired output and interleave str symbol, that will be replaced for the input you'enter.
    Skeleton can do more sophisticated things, like inserting multiple lines while user keeps entering data.  I can imagine myself using this when entering lots of data with some desired format.

  • Yasnippets. Yasnippets are skeletons on steroids. Sad thing is that there's no direct way to bypass the file used to define snippets. I guess you can open a new buffer, put it into yasnippet-mode, and c-c c-c to activate the binding for just this session, but maybe it's too much of a hassle.

  • defun+insert.  The dumb way to do it, but the most straightforward if you tend to forget rarely used functionalities like skeletons.  Just define an interactive function that inserts your shit there, and call it at will.  That's the option I go when I don't wanna spend a minute looking for skeleton docs.
Then to call the functions/skeletons, you have different ways, if you want to global-set-key, or even just set the key in insert mode (using evil), reminding of imap style,

I'd love to hear other solutions on that same issue. Any suggestions?

sábado, 12 de mayo de 2012

The art of demo programming

Some time ago I met a guy on the internetz that was quite fond of demoscene. I never looked at it before, but since then,, I'm quite amazed by everything related to demos.

BIG BIG respect.

 From programming techniques, to creativity. Raymatching, compressing, and music. Everything pushed to its limits. There's been a recent thread in HN, with a quite a few links to tutorials, videos. 

And here's the freaking amazing demo that started the hn thread. Prepared to shit bricks? All that thing fits in 4096 bytes.

Yeah. 4kb.


jueves, 3 de mayo de 2012

simple made easy, twice

Here there are a couple of videos of the same talk "Simple, made easy", by Rich Hickey. I love Rich's talks, and I think it's even enlightening seeing the same talk twice, fine tuned for different audiences.

First one is from RailsConf 2012 Keynote. Done with a ruby audience in mind.

Second one is from StrangeLoop 2011. much more hilarious and punchy IMHO, and maybe a little less serious tone, but equally enlightening.

Here it is. bye!