(hello

‘world)

What I’ve been up to this month.

So I’ve noticed that I have 23 posts for January (I need a life), and only 4 for February. What have I been up to?

Mostly delving more into Scheme(see footnote), nearly to the exclusion of Common Lisp, other than the occasional tweaking of my StumpWM config.

A few years ago when I was still doing security (of the rent-a-cop sort) I was reading some Scheme book or another (I don’t remember which) in PDF format on my old Palm T3 running LispME. I miss my T3, I thought the format was just about perfect, and it was well built. I wouldn’t have given it away if I knew it would finally be figured out how to get Linux on it. Oh well, I have a laptop now. Anyway, I don’t really know why I never got more into it… I loved it, but I probably got distracted by other things after I moved (like trying to find a fucking job -_-). I don’t really know how it caught my interest again either (along with Common Lisp this time), but I figure it was inevitable with nothing else really going on.

So now I spend large portions of my time coding Scheme, and I’ll talk about a couple of the things I’ve been working on, the things I plan to work on, and some things I might eventually work on.

I wrote an IRC bot in Common Lisp as I always do when learning a new language. It was mostly a matter of the quote given in my earlier post on Scheme vs. Common Lisp, “Most newcomers eventually (and independently) decide the same thing: Scheme is a better language, but Common Lisp is the right choice for production work. CL has more libraries, and the implementations are somewhat more compatible than Scheme implementations, particularly with respect to macros.“.

But I decided, fuck that, it is the better language, and reimplemented it in Scheme. But I wasn’t happy, there wasn’t enough separation of layers, and the code to make the network interface bits portable across different Scheme implementations was a gigantic cond expression requiring the user (I always (try to) code with the assumption that other people will have to use/read it) to set a variable to the name of their implementation. All that complexity just to open a socket is bullshit, and doesn’t belong in the bot’s code.

I knew I must have been reinventing wheels, so I started looking around, and I found what I needed, Snow. It’s not perfect, but it’s still a fairly new project and pretty much does the job. And more importantly, it already has things like a portable TCP/IP package, among many others I’ve also found useful, and works on pretty much all of the major implementations. Documentation for specific packages can be sparse at times, but they *do* always at least tell you the procedures they make available and what args they expect. And one of the nice things about Lisp in general is that it’s not generally a bitch to figure out someone else’s code, should you need to.

With that, I set about writing an IRC library for Scheme using the Snow framework, to eventually use to rewrite my bot. And I dare say it’s nearing completion. The only thing currently lacking is DCC support, which will come at some later time. The IRC client protocol itself and CTCP support are pretty much there however. It was originally inspired by cl-irc but so much of it wound up being based around the ideas of the IRC “egg” for Chicken that I consider it a derivitive thereof (and is happily BSD licensed anyway). While it does have its issues (such as not checking whether a nick change actually worked…), its general design, which I thought was quite simply fucking brilliant, is obviously far superior to that of cl-irc’s (especially in how hooks/handlers and CTCP are handled). It seems I learned about as much Scheme from reading that code as I have reading any books. I only hope that my IRC code may be useful to Chicken’s, as mine likely wouldn’t exist as it does without it, so I’m going to wind up trying to write a couple patches for the parts of the egg I found lacking. Open source is grand, isn’t it?

Once that’s all done, I’ll be using it to (re-re-)implement my IRC bot in Scheme. And I think, for once, I’ll finally have the bot I always really wanted instead of a hack job that has to get around the limitations of the language it’s written in.

One of the things the bot does is retrieve information from Last.FM, so I’ll need to write an implementation of the API for Scheme too (obviously, based on the excellently written cl-audioscrobbler).

And then, I’ll get back to work on my MUD based on the ideas in Mooix NG. I’ve got a basic framework done making heavy use of Common Lisp’s CLOS, as an object system seemed the obvious tool for the job, and CLOS is simply sexy to work with. But working with Common Lisp just didn’t feel quite right, and I wound up looking more into Scheme(see other footnote).

I’m also vaguely entertaining the thought of writing Snow packages for the 9P and Freenet protocols. But what I’d really like to see is a widely supported SRFI for Foreign Function Interfaces(FFI). That would make the others (and other cool shit like POSIX) nearly trivial to do portably across implementations. Although threading at least has a couple of its own SRFI’s anyway. But in the mean time, a lot of Scheme implementations do support FFI to one extent of another… maybe someday when I’ve got more experience I’ll see about writing a Snow package to smooth over their differences, as CFFI does for Common Lisp.

So yeah. Do I need to get laid, or what?

(footnote) As it breaks compatibility both literally and ideologically to previous Scheme standards, I do not refer to R6RS as Scheme. When I say Scheme, assume R5RS.

(other footnote) Separate namespaces making me care whether it’s a variable or if I need to use #’, having to remember to use gensym in macros, should it be defvar or defparameter, … I don’t want to give a shit about the language, I just want to write what I’m trying to write, and when trying to write a MUD it was getting pretty old. Sure, I could abstract all that away. Lisp is GREAT for that sort of thing, and I started to do just that. But then I thought, why should I make Common Lisp be Scheme-like, when there’s already Scheme? If the language I really want is already there… use it.

February 25, 2008 Posted by prael | Common Lisp, IRC, Last.FM, Meta, Programming, Scheme, StumpWM, cl-audioscrobbler | | No Comments Yet

How will this software get my users laid?

Middle of the night surfing, I came across the site of one of the original XEmacs and Netscape (and later, Mozilla) developers, where is the small article, Groupware Bad. It makes a lot of good points that I think a lot of people miss, especially on why Netscape 4.0 was trash (heh, I remember when everyone called it ‘Nutscrape’) and making software that people actually want to use (and contribute to).

Of course, the titular quote:
“How will this software get my users laid” should be on the minds of anyone writing social software (and these days, almost all software is social software).

February 25, 2008 Posted by prael | Programming, web | | No Comments Yet

The Art of War… ish.

Chapter One
Making Of Plans

Master Sun said:
War,
War never changes
It is a place
Of life and death,
A road
To survival and extinction,
A matter
To be pondered carefully.

When deciding whether to go to war
Or remain in peace
Flip a coin
If one flip decides upon peace
Try for the best three out of five

Chapter Two
Waging War

Master Sun said:
When your weapons are dulled,
Your ardor damped,
Your strength exhausted and your treasure spent,
Other chieftains will spring up
To take advantage of your extremity

At this time you should
Ask the enemy for a time out
So that your men can rest
And their weapons can be sharpened

Chapter Three
Attack By Strategem

Master Sun said:
Ultimate excellence lies
Not in winning
Every battle,
But in defeating the enemy
Without even fighting.
So try to concentrate hard enough
To make the enemy’s heads explode;
Perhaps by training on watermelon first
And working your way up to humans

Chapter Four
Tactical Dispositions

Master Sun said:
Position is key
To success in battle.
When planning your angle of attack,
Make sure you are directly facing the harsh rays of the sun;
This will make it easier for your men
To tell what time it is,
Giving you a distinct advantage

Chapter Five
Weak Points And Strong

Master Sun said:
You can be sure of succeeding
In your attacks if you only attack
Places which are undefended;
Therefore you must not attack
Until the enemy is at their most vulnerable;

Like when their entire army
Removes their armor
Wanders from the safety of their camps
To drop deuces in a ditch
Then they all fall asleep in that ditch
At exactly the same time
Attack at this moment
And only this moment
And you will be victorious

Chapter Six
Maneuvering

Master Sun said:
If your men hear a strange sound
In the middle of the night
The best tactical maneuver available
Is to have everyone split up
And wander aimlessly in the woods
By themselves
While yelling “Hello?”

Chapter Seven
The Use Of Spies

Master Sun said:
All warfare is based
On deception;
Have your army dress themselves
In the enemy’s clothing
And sneak into their camp before dawn;
Then, when they least expect it,
Have your men disembowel themselves

Your enemy will think a large number
Of their own men have died
Score one for
Team awesome

Chapter Eight
Terrain

Master Sun said:
An army with higher ground
Is at a distinct advantage;
If you find yourself on a level battlefield
Have your men drop their weapons
And stand on one another’s backs
Forming a giant pyramid
With the man at the very top wielding a sword
This height advantage should make him
More powerful than an entire army

Chapter Nine
The Attack By Fire

Master Sun said:
There are six ways of attacking with fire
The first is to burn soldiers in their camp;
The second is to burn stores;
The third is to burn baggage trains;
The fourth is to burn arsenals and magazines;
The fifth is to hurl dropping fire amongst the enemy;
The sixth is to set all of your provisions on fire
And hope your enemy steps on them by mistake

Epilogue
Master Sun said:
Take these tactics which have proven
Disastrous on the battlefield
And bind them into a volume;
Then make sure it falls
Into the hands of my enemies
Who will be eager to use
My strategies against me

But don’t write this part
You’re not writing this
Are you
Okay good

February 18, 2008 Posted by prael | humor | | No Comments Yet

.stumpwmrc 0.7


; -*-lisp-*-

;;; 0.7

;; 2008/02/13

;; Replaced my MusicPD code with Patzy's as it's far more complete.

;; Using external 'unclutter' again.
;; (run-with-timer 5 5 'banish-pointer) became too annoying.

;; A few cleanups, mostly involving variable names.

(in-package :stumpwm)

;; Include Patzy's MPD code.
(load "~/.stumpwm/contrib/mpd.lisp")

;;; Internal variable definitions.

(defparameter *foreground-color* "darkcyan")
(defparameter *background-color* "black")
(defparameter *border-color* *foreground-color*)

(setf *format-time-string-default* "%a %b %e %k:%M")

(setf *mpd-port* 2100)
(setf *mpd-volume-step* 10)

;;; Internal function definitions.

;; Found at:
;; http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(defun cat (&rest strings) "A shortcut for (concatenate 'string foo bar)."
  (apply 'concatenate 'string strings))

;;; Theme.

;; Window border colors.
(set-focus-color *foreground-color*)
(set-unfocus-color *background-color*)

;; Input box colors.
(set-fg-color *foreground-color*)
(set-bg-color *background-color*)
(set-border-color *border-color*)

;; Modeline colors.
(setf *mode-line-foreground-color* *foreground-color*)
(setf *mode-line-background-color* *background-color*)
(setf *mode-line-border-color* *border-color*)

;; Background.
(run-shell-command (cat "xsetroot -solid " *background-color*))

;;; Init stuff.

;; Make frames and windows 1-indexed.
;; See: http://lists.gnu.org/archive/html/stumpwm-devel/2006-08/msg00002.html
;; Found at: http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(setf *frame-number-map* "1234567890")
(setf *window-number-map* "1234567890") ; This doesn't actually do anything.

;; Rename the first group to Browse and create the other groups.
;; Found at: http://en.wikipedia.org/wiki/User:Gwern/.stumpwmrc
(setf (group-name (first (screen-groups (current-screen)))) "Browse")
(run-commands "gnewbg Edit" "gnewbg Term" "gnewbg Comms" "gnewbg Misc")

;; Change the prefix key
;; keycode 115 = F20 in ~/.xmodmaprc, 115 being the left "windows" key.
(set-prefix-key (kbd "F20"))

;; Set up X cursor and colors.
(run-shell-command (cat "xsetroot -cursor_name left_ptr -fg " *background-color* ; Cursor body
                                                      " -bg " *border-color*)) ; Cursor outline

;; Keep the X cursor out of the way.
(run-shell-command "unclutter -idle 5 -jitter 5 -root")

;; Configure and start the modeline. Colors are handled above.
(setf *mode-line-border-width* 1)
(setf *mode-line-pad-x* 1)
(setf *mode-line-pad-y* 1)
(setf *mode-line-position* :bottom)
(setf *mode-line-timeout* 10) ; Update every 10 seconds if nothing else has triggered it already.
(setf *screen-mode-line-format* (list "((%n %w) (" ; Current group and frames
                                      `(:eval (format-time-string))
                                      ") (%m))")) ; Patzy's MPD code.

;; Switch mode-line on only if needed. Found at:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc
(if (not (head-mode-line (current-head)))
     (toggle-mode-line (current-screen) (current-head)))

;; Found this tidbit browsing the source. Defaults to :ignore
(setf *mouse-focus-policy* :click) ; I'm fucking lame.

;;; Keyboard shortcuts.

;; Fluxbox-style Alt-F# virtual desktop (group in StumpWM-speak) switching. Modified from:
;; http://hcl-club.lu/svn/development/lisp/.stumpwmrc
(dotimes (i 13)
  (unless (eq i 0) ; F0 is non-existant and will error.
    (define-key *top-map* (kbd (format nil "M-F~a" i)) (format nil "gselect ~a" i))))

;; Applications.
(define-key *root-map* (kbd "b") "exec firefox ")
(define-key *root-map* (kbd "e") "exec xemacs ")
(define-key *root-map* (kbd "c") (cat "exec urxvt -fg " *foreground-color*
                                                " -bg " *background-color*
                                                " -pr " *foreground-color*
                                                " +sb "))

;; Audio controls, uses un-numlocked keypad.
;; Some keys duplicated, not sure which I prefer yet.
(define-key *top-map* (kbd "KP_Up")       "mpd-volume-up")
(define-key *top-map* (kbd "KP_Add")      "mpd-volume-up") ; Redundant
(define-key *top-map* (kbd "KP_Down")     "mpd-volume-down")
(define-key *top-map* (kbd "KP_Subtract") "mpd-volume-down") ; Redundant
(define-key *top-map* (kbd "KP_Left")     "mpd-prev")
(define-key *top-map* (kbd "KP_Right")    "mpd-next")
(define-key *top-map* (kbd "Num_Lock")    "mpd-toggle-pause") ; The light indicates play/pause ;) 

February 13, 2008 Posted by prael | Common Lisp, StumpWM | | No Comments Yet

This space reserved for jelly stains.

Finished reading those books. Actually, I read the first two within half a day of getting them, the 3rd took a while. They include footnotes as to the differences between Scheme and Common Lisp where relevant, many of which are simply to deal with CL being a Lisp-2. And they were all worth every fucking penny.

The Little Schemer was far more basic than I had expected but it did get around to covering the Y combinator, in quite an interesting way. Probably not so basic if you havn’t worked through SICP, HTDP, TSPL, and such. Heavy on recursion, only actually uses a very small subset of Scheme. It goes on to, much like SICP, write a small Scheme interpreter inside Scheme itself.

The Seasoned Schemer is pretty much what you would expect: more Scheme. Gets into let, set!, call/cc, etc…, including Y! which I don’t recall seeing before. Interesting to note, there’s a footnote for Common Lisp in chapter 19 that simply says: “This is impossible in Lisp, but Scheme can do it.”. It was referring to a particular use of letcc (aka call/cc), but it gave me a chuckle.

The Reasoned Schemer… wow. Despite being the shortest, I really had to take my time with that one. It’s pretty much entirely on using and writing a Prolog implementation in Scheme.

And if you havn’t guessed from the title of this post, they all use foods as example data, in an oft humorous way.

February 1, 2008 Posted by prael | Books, Scheme | | No Comments Yet