netzstaub

beatz & funkz

Monday, March 14, 2005

ParenScript

I actually have a lot of real work to do, so I had to quit my “opensource-programming” procrastination as fast as possible. That’s why I rushed the release of my Lisp to Javascript “compiler” ParenScript. Compiler is actually a very big word, as ParenScript doesn’t do much more than correctly indent a Lisp expression representing Javascript code (it does a few optimization on the way, though). I had at first written a very hackish implementation of the compiler, with an undefinite intermediary representation somehow consisting of strings and lists of strings. After I got the mess working, I decided to rewrite the compiler in a clean way. ParenScript in the version 0.1.0 actually is a lot cleaner, a few people may even understand its inner workings, but there still is a lot to do. It has been given next to none testing in a real setup. The indentation is a bit weird sometimes, and could be given a lift up. The error handling is very minimal.

However, as rushed as I was to release ParenScript, I put the whole day into its manual, and I think it has turned out to be quite nice. Here is the ParenScript webpage, the software, the manual and the language reference. ParenScript it also installable using ASDF-INSTALL, just type

(asdf-install:install 'parenscript)

and it should install fine.

To give you a little idea of what ParenScript does, here is a ParenScript program and the generated JavaScript:

(defun apply-effect () 
   (when (and document.all photoslider.filters) 
      (let ((trans photoslider.filters.reveal-trans)) 
          (setf (slot-value trans ’*Transition) 
                (floor (* (random) 23))) 
          (trans.stop) 
          (trans.apply))))

The generated JavaScript code looks like this:

function applyEffect() { 
   if (document.all && photoslider.filters) { 
      var trans = photoslider.filters.revealTrans; 
      trans.Transition = Math.floor(Math.random() * 23); 
      trans.stop(); 
      trans.apply(); 
   } 
} 

From the feature list:

  • Supports all the expressions and statements of EcmaScript 262
  • Converts Lisp symbols to java-style camelcase (taken from linj)
  • Lisp-style iteration with DO, DOTIMES, DOEACH, DOLIST
  • Complete macro environment with MACROLET, SYMBOL-MACROLET
  • Uses the Lisp reader for reader macros
  • ParenScript HTML generator for embedding HTML in JavaScript code (not more ugly document.writes)
  • Allows for recursive compilation of ParenScript (generate Javascript in Javascript in Javascript…)
  • Lispy CSS syntax

UPDATE: I’ve blogged about the javascript compiler before. In english here: javascript experiences, and in german here: lisp to CSS, javascript, so eine geile sprache, javascript expressions , javascript compiler and lisp to javascript.

posted by manuel at 9:32 pm  

Monday, March 14, 2005

Saugnapf 5 online

Gestern war wieder Saugnapf-Sonntag, dieses mal keine Themensendung, sondern Schrammel, Folk, Hiphop, und CD-Verpeilung. Torrent ist hier Saugnapf 5.

posted by manuel at 11:03 am  

Saturday, March 12, 2005

Interview mit Guy Steele in Dr Dobb’s

Guy Steele ist gerade das Thema in ziemlich allen Lisp-Weblogs. Er hat gerade den “Excellence in Programming Award 2005” von Dr Dobb’s bekommen, und die neue Ausgabe für April 2005 ist ein längeres Interview von ihm. In dem Interview erzählt hautpsächlich von seinem Werdegang an MIT, Harvard, dann bei Thinking Machines und dann Sun. Deswegen habe ich mir für 20$ ein Jahr lang Premium Access zu Dr. Dobb’s geklickt, was recht nett ist. Man kann die neue Ausgabe immer als PDF runterladen, und auch alle Backissues.

Jedenfalls habe ich gestern beim Rumbasteln an meinem HTML Pattern Matcher Nested Backquotes gebraucht. Siehe da, in CLtL2, das Guy Steele geschrieben (bzw. editiert) hat findet sich in Appendix C eine Implementierung von BACKQUOTE, geschrieben von Guy Steele. Code von “Legenden” ist eigentlich immer lesenswert. Auch die Lambda-Artikel von Guy Steele sind extrem spannend.

posted by manuel at 3:03 pm  

Wednesday, March 9, 2005

Saugnapf 4 Online

Endlich ist auch die Seite für die saugende, quiekende und das Trommelfell-massierende Spitzensendung Saugnapf, 4. Ausgabe, Online. Hier ist das Tracklisting, hier das Torrent. Dass das Leechen euch erfreuet, und der Sound euch zum Hüpfen, Tanzen und Zittern bringt.

posted by manuel at 9:41 pm  

Wednesday, March 9, 2005

ecto

Ecto somehow managed to fuck up all the fixed-width text used for program code in the LISP entries. This will get fixed ASAP, sorry.

Update: it should be better now :). Here is the LISP sourcecode I used to cleanup the entries. I replace P entries with monospace font with PRE entries. This sourcecode uses the HTML pattern matcher which can be found at svn://bknr.net/trunk/bknr/src/html-match . It is a real memory abuser, and quite slow too, but it works 🙂

(defun load-file (file)
  (with-open-file (s file :direction :input)
    (let ((lines (loop for line = (read-line s nil 'eof)
                    until (eql line 'eof)
                    collect line)))
      (reduce #'(lambda (s1 s2) (concatenate 'string s1 s2)) lines :initial-value ""))))

(defun cleanup-ecto (file output-file)
  (let* ((body (cons :html
                    (net.html.parser:parse-html (load-file file))))
         (res (html-replace body
               (html-pattern ((:p :style "font-family:monospace;font-size:13pt;") ?body)
                             (cons :pre
                                   (html-replace ?body
                                                 (html-pattern :br (string #\Newline))))))))
    (with-open-file (s output-file :direction :output :if-exists :supersede)
      (net.html.generator:html-stream s
          (mapcar #'(lambda (x) (net.html.generator:html-print x s))
                  (cdr res))))))
posted by manuel at 3:44 pm  

Wednesday, March 9, 2005

Festival mit esd unter Gentoo

Unser Router, welcher in einem unbenutzten Kuechenschrank untergebracht ist, hat Soundkarte und Boxen, schliesslich wollen wir Musik von jedem Computer innerhalb unseres Netzes mittels poc in die Kueche senden. Natuerlich wollen wir die Soundkarte fuer mehr nutzen: beispielsweise fuer die cron-gesteuerte Standuhr zur vollen Stunde oder fuer per Text-to-Speech umwandelbare Informationen. Fuer Text-to-Speech verwenden wir festival, welches auch als Gentoo Package zur Verfuegung steht. Leider ist in der aktuell von Gentoo angebotenen Version kein esd Support per USE-flags einstellbar. Da wir esd benoetigen, musste nachgeruestet werden:

Die unterstuetzten Audiomodule (esd, freebsd, irix, linux, mplayer, nas, sun und win32) werden vom Paket speech-tools bereitgestellt. Welche dabei konkret mit einkompiliert werden, haengt von der Datei config/config.in ab. Im ausgelieferten tgz ist esd-Support deaktiviert. Um diese Datei innerhalb des Gentoo-Buildvorgangs zu aendern, fuegen wir in der Datei /usr/portage/app-accessibility/speech-tools/speech-tools-1.2.3-r1.ebuild ans Ende der src_unpack Funktion folgendes an: use esd && sed -i 's/# \(INCLUDE_MODULES += ESD_AUDIO\)/\1/' config/config.in. Dies bewirkt, dass bei aktiviertem esd USE-flag das esd-Modul mitkompiliert wird.

Da wir auf unserem Router kein X installiert haben, muss die Makefile-Konfiguration des esd-Moduls angepasst werden: Wir fuegen zusaetzlich use X || sed -i 's/-lX11 -lXt//' config/modules/esd_audio.mak in das ebuild-Script ein, um nicht benoetigte Libraries zu entfernen.

Um zu ueberpruefen, ob unsere Aenderungen angewendet wurden, rufen wir ebuild /usr/portage/app-accessibility/speech-tools/speech-tools-1.2.3-r1.ebuild unpack auf und pruefen die unter /var/tmp/portage/speech-tools-1.2.3-r1/work/speech_tools/config/ liegenden Dateien config.in und modules/esd_audio.mak. Danach verwenden wir emerge um speech-tools und festival zu installieren. Ein aufgerufenes saytime verwendet daraufhin esd fuer die Audioausgabe.

posted by manuel at 12:26 pm  

Wednesday, March 9, 2005

Javascript experiences: tooltips

I finally wrote my first “real” javascript program this weekend. I have a lot of articles about biology. Each article can have tables, figures, and references to other articles. Furthermore, each article has a kind of small introductory text, called the “definition”. I wanted to have tooltips showing these figures, tables and definitions when dragging the mouse over a link. For example, if a paragraph features a link to another article, I wanted to have a tooltip showing the title, author and definition of the other article showing up. This would also be the first “real” program written with my “lisp to javascript” compiler.

(more…)

posted by manuel at 10:42 am  

Wednesday, March 9, 2005

Utz utz das Technomuseum

Kam gerade in einer Mail, die mir der liebe Mrf gevorwärtst hat. Ursprünglich über die netaudio Mailingliste. Ein kleines Lisp Snippet hat das übrige erledigt.

Das Technomuseum


(defun load-techno-urls (file)
  (with-open-file (s file :direction :input)
    (loop for l = (read-line s nil 'eof)
	  with last-url = nil
	  with res = nil
	  until (eql l 'eof)
	  do (if (and (>= (length l) 7)
		      (string-equal (subseq l 0 7) "http://"))
		 (progn
		   (when last-url
		     (push last-url res))
		   (setf last-url (string-trim (list #\Space #\Tab #\Newline) l)))
		   
		 (if (and (>= (length l) 1)
			  (eql (char l 0) #\Space))
		     (when last-url
		       (push last-url res)
		       (setf last-url nil))
		     (when last-url
		       (setf last-url (concatenate 'string last-url l)))))
	  finally (return (remove-duplicates (cons last-url res) :test #'string-equal)))))
		 
posted by manuel at 10:32 am  

Wednesday, March 9, 2005

A short practical overview of MOP: part 2

This is the second posting of what will be a series about practical uses of the Metaobject Protocol. The MOP enables introspection and customization of the Common Lisp Object System. In the first posting, we saw how to create custom slot definition objects, and how to add new slots to a class definition. In this posting we will see how we can use these custom slot objects to control slot access to our indexed objects.

(more…)

posted by manuel at 9:00 am  

Tuesday, March 8, 2005

A short practical overview of the Metaobject Protocol

I’ll try to write this blog entry in english. I’m not very used to writing in english though, so please bear with me 🙂

I will try to show how to use the Metaobject Protocol for CLOS (the Lisp OO system). When learning how to use MOP, I had quite a hard time finding examples on the web, and the seminal work about MOP (The Art of the Metaobject Protocol) doesn’t offer that much help either. Furthermore, MOP is not really standardized as it is, and most Lisp implementations offer subtly different implementations. The code I’ll present here has been tested with PCL-based Lisp implementations (SBCL and CMUCL, for example), and with Allegro CL. I guess it can easily be ported to other Lisp implementations, but haven’t got around to do it for now.

A good deal of the functionality of BKNR is based on the Metaobject Protocol, namely:

  1. the Indices package, which offers object-oriented indices on CLOS objects.
  2. the XML import/export package, which offers XML bindings for CLOS objects,
  3. the Datastore package, which offers persistent CLOS objects and support for logged transactions.

The Metaobject Protocol is a “meta”-layer above CLOS which allows both introspection and customization of the Object System.

(more…)

posted by manuel at 5:00 pm  
« Previous PageNext Page »

Powered by WordPress