Archive for the ‘Lisp’ Category

November 30, 2006

$ cat foo.qck
(print "Hello, world!")
M-x gen-foo
M-! parrot /tmp/quackfoo.pir
Hello, world!
$ cat /tmp/quackfoo.pir
# -*- mode: pir -*-
# auto-generated PIR from Quack Lisp code.
# For more info, see http://cvs.codeyard.net/Quack.

include "quacklib.pir"

#.namespace ["quack"]

.sub main :main :lex
  init_quack()
  $P1 = find_global "PRINT"
  $P2 = new "LispString"
  $P2 = "Hello, world!"
  $P3 = new FixedPMCArray
  # QAST tail call
  .return $P1($P2, $P3 :flat)
.end

# Local Variables:
# compile-command: "parrot quackfoo.pir"
# End:

:-D

Runtime macroexpansion is evil, indeed

October 16, 2006

I’m trying to implement an Arc-like Lisp dialect, and my code currently runs in an interpreter run within an interpreter (only made to bootstrap the Parrot code). I just finished implementing cond (I’m not implementing if in terms of cond as PG may do, the other way around makes the code simpler), and all the code that used cond was getting rather slow. Not strange, really, as I had been expanding macros at runtime. (It’s the easiest way, they are first-class objects like in Arc.) So, I made some assumptions for the bootstrapping code to allow for a simple ‘compile-time’ (well, it’s between read-time and eval-time) macroexpander. Running it on a part of the macroexpander itself took some time and memory:

code screenshot with timing

Next thing to do: make the interpreters cons less.

Parrot gets cookie

September 17, 2006

Before I encountered Lisp, I had been using Perl for a while. Nowadays I’m mostly toying with an unfinished unofficial Arc implementation. Surprisingly the two got together: Parrot, the expected Perl 6 virtual machine, is made to support other languages as well. There are already projects for Parrot implementations of APL, Basic, Befunge, Brainfuck, CL and dotnet, to name a few. The list includes a mostly working Python implementation.

Another plus: it uses continuations everywhere (not what you’d expect be necessary with Perl), so it’s ideal for a Lisp dialect host. You can use CPAN, wxPerl, SDL, sinp.py, interact with Perl and Python, and so on. There’s just one implementation, targeted at portability, so you don’t have to bother with your favorite CL implementation not supporting platforms.. Perfect. I love it.