Archive for the ‘Lisp’ Category

On tail recursion

Thursday, May 28th, 2009

Like many, I was not very interested in tail recursion – it’s just a way of writing a loop in a more verbose way, right?  Luckily, Joe Marshall wrote a series of blog posts that made me reconsider my view – while self-calls might “only” be loops, mutual, never-ending tail-calls implement continuation-passing style, state machines etc.  Glad I got one more erroneous belief out of my system!

ʇsodƃoʃq-uʍop-ǝpısdn x-W

Monday, January 12th, 2009

Things to do when you’re vacationing in one of the most beautiful places in the world (i.e., Bali):

Why, implement code to turn text upside-down in your favorite editor, of course!

Public Service Announcement

Tuesday, February 5th, 2008

If you compile sbcl from source yourself, and you want to have threading enabled, then look at the top of the file base-target-features.lisp-expr and do what it says therein.

Thank you.

Just for fun …

Wednesday, December 19th, 2007

cocoa-listener.png

The McCLIM listener in a cocoa window, running on the latest Clozure CL beta.

It took some time, since on OS X 10.5 CGFloat can be either single-float or double-float, depending on the processor. At the moment, I just rewired the hardwired (coerce … ’single-float) calls and numeric constants in the beagle backend. Also, it crashes on the all-important “Show Class Subclasses t” benchmark. Still, very nice.

ParenScript vs script.aculo.us

Wednesday, December 12th, 2007

Currently, my job does not involve a whole lot of programming, and I’m getting a bit rusty and irritated. So, last weekend I decided to noodle around aimlessly with some systems I meant to try out for a while now.

Parenscript advertises itself as being easy to integrate with javascript libraries such as Prototype, but the manual gives no examples on how to do this. Furthermore, the Parenscript manual uses aserve / htmlgen for its examples, while much of the action these days is with hunchentoot. So, without further ado, a pointless example integrating hunchentoot, cl-who, parenscript and script.aculo.us. Load the code after loading hunchentoot, cl-who and parenscript into your running Lisp.

;;; Just the standard intro
(defpackage :js-hax
  (:use :common-lisp :hunchentoot :cl-who :parenscript))
(in-package :js-hax)
(start-server :port 8080)

;;; Set the path to where you unpacked script.aculo.us
;;; create-folder-dispatcher-and-handler publishes subdirectories:
;;; http://.../js/lib/prototype.js
;;; http://.../js/src/scriptaculous.js
(push (create-folder-dispatcher-and-handler
       "/js/" #p"/home/someone/source/scriptaculous-js-1.8.0/")
      *dispatch-table*)

(defmacro js-script (&rest body)
  "Utility macro for including ParenScript into the HTML
   notation of cl-who"
  `(with-html-output (*standard-output*)
     (:script :type "text/javascript"
              (format t "~%// <!--[CDATA[~%~A~%//]]-->~%" (ps ,@body)))))

;;; Slider example, taken from the scriptaculous wiki
(defun foo ()
  (with-html-output-to-string (*standard-output* nil :prologue t)
    (:html
     (:head (:title "script.aculo.us Tests")
            (:script :language "JavaScript" :type "text/javascript"
                     :src "/js/lib/prototype.js" "stupid firefox")
            (:script :language "JavaScript" :type "text/javascript"
                     :src "/js/src/scriptaculous.js" "stupid firefox"))
     (:body
      (:h1 "script.aculo.us vs. ParenScript")
      (:p "The humble slider.")
      (:p
       (:div :id "track1"
             :style "width:200px;background-color:#aaa;height:5px;"
             (:div
              :id "handle1"
              :style "width:5px;height:10px;background-color:#f00;cursor:move;"))
       (:div :id "debug1" :style "padding-top: 5px;"))
      (js-script
       ;; Create the Slider object
       (new (*control.*slider
             ;; Hook it up to the UI elements ...
             "handle1" "track1"
             ;; ... and assign behavior
             (create on-slide (lambda (v)
                                ;; Prototype-style DOM accessors:
                                ;; $('debug1').innerHTML = ...
                                (setf (slot-value ($ "debug1")
                                                  'inner-h-t-m-l)
                                      (+ "slide: " v)))
                     on-change (lambda (v)
                                 (setf (slot-value ($ "debug1")
                                                   'inner-h-t-m-l)
                                       (+ "changed! " v)))))))))))

(push (create-prefix-dispatcher "/foo" 'foo) *dispatch-table*)

All in all quite painless. The only point where I had to sit and think a bit was the translation of the prototype-style DOM accessors to parenscript notation.

Edit: Oh, and the js-script code above is missing the CDATA bits which were eaten by the web. Check page 6 of the parenscript documentation for the missing pieces.

Edit2: Thanks to Aankhen for pointing out that the CDATA wasn’t et after all, just hiding. I’ll go wrestle with this blog now to fix the stupid smartquotes.

Alien technology sighted in Leopard

Tuesday, October 30th, 2007

Leopard sandboxes are flexible and interesting. They’re apparently compiled from Scheme programs (sandbox-compilerd embeds TinyScheme) that live in /usr/share/sandbox. You can break sandbox-compilerd open in TextEdit and read the compiled-in Scheme code; they’ve got a lot of the bases covered, including obscure stuff like SYSV IPC, the BSD sysctl interface, and signals. 

http://www.matasano.com/log/981/a-roundup-of-leopard-security-features/

“I see no reason to do further business with you”

Tuesday, August 14th, 2007

Well, that would have been nice: amazon.ca held something of a fire sale, offering two very good books for 4 Dollars each. As did many others, I ordered “Lisp in Small Pieces” and Jaynes’s book on probability theory. Additionally, since I was paying for shipping anyway, I ordered a full-price book as well. But, as John Philpott’s order vahished, so did mine – almost: of course, Amazon was prepared to send me the full-price book anyway, with the overseas shipping and handling charges.

I’m not angry that I will not get the books, of course – if I had not heard about that special offer at all, I would not have anything to be angry about either. But when I said “vanished”, I mean it: Amazon dropped two out of three books from my order, without notifying me, and would have sent me a full-price book overseas; I would have paid at least twice the store price. And since I did not save their order confirmation email, I cannot even prove that the entire thing happened …

[Update] Well, better late than never – I got a notification email explaining that it was all a dream that the books had been displayed with an incorrect price.  I guess they simply ran out of stock, since the people who ordered before the madness started did get their LiSP at Small Prices.  Still, a notification email plus 10$ gift certificate is close to the right thing.

What’s all this, then?

Friday, April 20th, 2007

Hmm…Seems to be a Smalltalk-in-Flash, implemented using Strange Alien Technology, and having the eye candy. Just when I didn’t need another toy…[Update]The above wasn’t very clear – it’s a Smalltalk-on-Lisp-in-Flash-and-.Net – fun stuff.

Aquamacs rocks

Wednesday, February 14th, 2007

Aquamacs continues to be my emacs distribution of choice, mostly because it manages to behave both like an OS X application and like emacs.

The only inconsistency I discovered was with Undo: Aquamacs uses redo.el, which removes the emacs undo function and installs more familiar, but less powerful undo/redo functions in its place. Since redo.el clobbers the original undo function, I couldn’t adjust the keybindings myself without hacking Aquamacs distributed files, so I sent a whiney bug report.

24 hours and a short email back-and-forth later (choice quote: “You are the first to complain, but that doesn’t mean you’re not right.”), the nightly builds don’t clobber undo any more, C-/ and C-_ use emacs undo and undo/redo is available via Cmd-Z/Cmd-S-Z and the pull-down menu.

This is a good example of what I understand to be the general design philosophy of Aquamacs: offer emacs functions where an emacs user expects to find them, offer Mac-like functionality where a Mac user looks.  And its developer, David Reitter, is very responsive and friendly indeed.

“Progress”

Monday, August 28th, 2006

Portable AllegroServe is still in hibernation, but I have at least updated the asdf-installable version to current cvs so it compiles under sbcl again.