(archive 'newLISPer)

August 18, 2006

TextMate – the missing 21st century editor…?

Filed under: newLISP — newlisper @ 19:31

I said I was going on holiday, and I am, but the following piece of prose has now matured enough to be almost ready for posting, so without further ado I’m posting it.

TextMate is a relatively new text editor for the Mac platform. The swaggering slogans of this new arrival – “the missing editor”, “code and markup brought to the 21st century” – position it as a rival for both BareBones’s BBEdit and the motley crowd of keyboard-oriented text editors that have been the reliable weapons of the Unix user for decades – vim, vi, pico, emacs, ed, and the rest.

There’s a nice bit of rivalry going on between TextMate and BBEdit – BBEdit’s boss made a glancing reference to ‘overnight text editors’, once, which quickly appeared on the back of TextMate t-shirts… See this wry comment at the TextMate blog.

There’s no doubting TextMate’s many virtues – just use it for an hour and you’ll spot some of them. But is it any good as an editor for newLISP? I think I can answer ‘yes’, because, unlike many of its competitors, TextMate can be taught new languages. There’s now a newLISP definition (called a ‘bundle’) for TextMate, based on the work of my distinguished co-blogger michael, and others, and further developed with the help of the TextMate community and TextMate’s author, who patiently shone some light in some of the darker corners. You can find it on the newLISP web site.

The advantage of the TextMate approach is that you’re not restricted to features that were developed for and by users of other programming languages. For example, BBEdit provides a pop-up menu showing all the functions in your document, but only if you use the mainstream languages. You can add similar functionality for your own chosen language, but only by writing a plug-in (and you’ll have to write it in some kind of C anyway, most probably).

However, if you can describe the syntax of your language with regular expressions, you can teach TextMate what function definitions look like, and which keywords belong to which categories. The approach seems a little odd at first, but it works, for the most part. TextMate’s ‘knowledge’ is evident when you’re editing newLISP code with a newLISP bundle active: the colour scheme illuminates the syntax and structure. Also, the effects of actions and commands depend on the context in which you’re working. It’s possible (and fun) to assign distinctive colour schemes to different language elements. Those destructive newLISP keywords such as replace can be made to look very menacing with garish yellow backgrounds! And how about showing those deprecated or obsolescent keywords in a sad-looking grey?

TextMate is highly configurable and sensitive to context. For example, I’m used to using the Command B key combination to select everything between enclosing parentheses. I can tell TextMate that Command B should do this when I’m writing newLISP, but that the same key stroke should do angle-bracket magic in an HTML document, and double-asterisk business when I’m writing in MarkDown. Similarly, when I press Control H, I’ll get a MarkDown syntax summary, an HTML reference page, or an extract from the newLISP manual, depending on where my cursor is at the time.

The basic task of parenthesis balancing (essential for us newLISPers) is handled quite well in TextMate but not perfectly. Moving the caret forward over a closing parenthesis briefly highlights the matching opening parenthesis – something that BBEdit can’t do. However, the other three cases (moving back over a closing parenthesis, and moving forward and backward over an opening parenthesis) don’t do anything visual – perhaps there are good reasons.

Unfortunately, TextMate’s balancing code isn’t smart enough to ignore parentheses in strings and comments. I spent 10 minutes trying to pin down a coding problem before I realised that TextMate hadn’t been telling me the truth. TextMate can’t balance this correctly:

(println "(" )

but BBEdit can, and I was used to it being able to do so. This is a bit of my newLISP formatting script, so I consider it fairly essential! I haven’t found out how to teach TextMate about this yet.

There are plenty of entertaining discussions about BBEdit and TextMate, and I think it would be hard to compare these two editors objectively without writing an enormously long – essentially pointless, for everyone has different needs – review. For example, BBEdit is AppleScript-friendly, and that’s always been a strong point in its favour for us long-time Mac users. BBEdit is well-documented, well-supported, and packed with features, and I’m comfortable with it. But TextMate also has good documentation, and the community is as helpful, and more productive. Perhaps TextMate is more flexible and customizable, and better for newLISP, too. TextMate develops quicker and costs less, but BBEdit… well, let’s stop there.

If you’re thinking of using newLISP on MacOS X, it’s worth checking out TextMate with the newLISP text bundle. Let me know how you get on, and please help to improve it!

August 10, 2006

Summer trivia: It’s the silly season

Filed under: newLISP — newlisper @ 00:21

In the English media, this time of year is known as the silly season. All the politicians, news makers, and opinion shapers have gone on holiday, to their Italian villas, country houses, or tropical islands. The newspapers are staffed by a few lonely hacks trying to fill a paper with fabricated news stories, pointless lists, and celebrity-based trivia. We can do that too! Here’s some newLISP trivia, a little light holiday reading for these lazy hot summer days and nights.

What’s simple, small, agile, cooperative, and adapting?

Why, newLISP, of course. That’s the philosophy, according to its creator.

Byoms, not biomes

Do you know what a Byom is? These guys do. It’s a cool IM search thingy. They like newLISP too.

How big?

/usr/bin/newlisp is 218932 bytes. As someone said after downloading it: “Is that really a complete language, in 220K?”. It is, and it would fit nicely on my camera’s flash memory card.

 Popularity of programming languages by Google mentions

Some lazy journalists do most of their research with Google. For example, they would write something like this:

The Visual Basic language is rapidly being superseded by Ruby, according to the latest research. Figures show the version of BASIC from the Seattle software giant is only half as popular as the trendy new object-oriented scripting language written by Yukihiro “Matz” Matsumoto.

Let’s see how popular various program languages are according to the number of hits Google finds:

5,960,000,000 c
  343,000,000 perl
  233,000,000 c++
  173,000,000 ruby
   99,500,000 pascal
   98,100,000 "visual basic"
   65,100,000 dylan
   43,000,000 python
   29,700,000 lisp
    9,000,000 haskell
    6,700,000 lua
    5,140,000 erlang
    4,330,000 ocaml
       23,300 newlisp

Scientific proof! The numbers also show that we still have quite a lot of work to do to promote newLISP. newLISP, newLISP, newLISP. There, that’s three more occurrences for Google to find and add to the list. Also, we’ll get Madonna to call her next album “naked and newLISP” – that should do the trick.


Did You Know Dept. The author of newlisp once wrote a FORTH interpreter/compiler. Here’s the first line of my FORTH interpreter:

> (while true (eval-string (read-line 0)) (println "OK"))

OK? ;-)

Run newLISP scripts easily

Did You Know Dept. Did you know that you can easily run newLISP scripts from the MacOS X menu bar? All you need is Apple’s Script Menu, designed both for AppleScripts and other scripts. (If you can’t see it, run /Applications/AppleScript/AppleScript Utility.) The Script Menu shows both global scripts and the scripts that are designed for the application you’re running. Global scripts should be stored in /Users/you/Library/Scripts/. Scripts to be run in, say, Safari should be in /Users/you/Library/Scripts/Applications/Safari/.

Here’s a bit of script to get you started:

(define (get-safari-page-link)
        (format [text]osascript -e 'tell application "Safari" to set urlLink to URL of front document
        return urlLink'[/text] )))
(define (get-safari-page-title)
        (format [text]osascript -e 'tell application "Safari" to set urlTitle  to name of front document
        return  urlTitle'[/text] )))
(define (get-safari-page-source)
        (format [text]osascript -e 'tell application "Safari" to set urlSource  to source of front document
        return urlSource'[/text] )))

You don’t have to use a special suffix for the file. Output goes to the console. And don’t forget to make the file executable first…(like I do)!

 10 quotes about newLISP from the internet

Hey, who needs Common LISP, now we have newLISP!

‘newLISP’ is a farce.

I’m trying to get started with lisp and newlisp is just way more accessible than this huge thing called common lisp

If I could, I would euthanize newlisp for the good of programmers the world over.

It’s really fast and cool for programming, really enjoyable…

It’s appropriately named – sort of like Orwell’s newspeak…

It is a remarkable language. I don’t want to write code in anything else.

Rarely can one point to a language that’s even more fucked up than early Perl or PHP, but today you can…

It’s faster than bejeepers. I run it on my webhost as a scripting language. Simple, fast, elegant.

It seems worse than a disaster.

The designers seem to know how to spell intuition.

Seems to be really alien.

Yes. I love it. It is small quick-hack-friendly and easy.

(That’s not 10 – Ed.)

Come back soon!

That’s all from me for a few weeks. Have a good holiday!

August 3, 2006


Filed under: newLISP — newlisper @ 00:27


The famous Hungarian-born photographer Brassai, ‘the eye of Paris’, used to time the long exposures of his night-time photographs by smoking a cigarette: after opening the shutter, he lit a cigarette, waited until it had burnt down, then closed the shutter again. He used the cheap, fast-burning Gauloise for brighter scenes and a more expensive, slower burning, brand such as Boyard for darker conditions.

I liked this story when I first heard it many years ago – something about the creative maverick genius striding around the streets of Paris at night solving problems with some casual lateral thinking, or something.

No such luck with the following, I’m afraid. It’s all strictly digital and stolidly unromantic. I wanted a timer that would wait a given number of seconds before sounding an alarm. Looking through the applications on my computer, I realised that I didn’t have such a thing installed – I’ve got plenty of alarms and calendars, but no countdown timers. I found a little dashboard widget on a web site somewhere, but that didn’t work for me. And I’m not a smoker so I didn’t have anything that would reliably take a precise number of minutes… So I thought it shouldn’t be too difficult to write a countdown timer in newLISP.

The reason it’s ended up as a Unix command-line utility is the problem of a user interface: it’s still easier for me to write a command-line program that accepts text input than to write any kind of application with a nice graphical interface. Until something suitable comes along for newLISP, this cool 1970s technology is about the only thing I can use.

(unless (main-args 2)
    (begin (println "usage: countdown duration [message]\nspecify duration in seconds or h:m:s")
(define (set-duration)
" convert input to seconds "
  (set 'duration
    (dolist (e (reverse (parse duration-input ":")))
     (if (!= "" e)
      (inc 'duration (mul (int e) ('(1 60 3600 86400) $idx)))))))
(define (seconds->hms s)
" convert seconds to h:m:s display"
    ((secs (mod s 60))
     (mins (mod (div s 60) 60))
     (hours (mod (div s 3600) 24)))
    (format "%02d:%02d:%02d" hours mins secs)))
(define (clear-screen-normans-way)
    (println "27[H27[2J"))
(define (notify announcement)
    " this is platform-specific"
    " on Mac, do some beeps and growls, and speak the supplied announcement"
    (exec (string {osascript -e 'tell application "Finder" to beep 3'}))
    (if (!= announcement nil) (exec (string [text]osascript -e 'say "[/text] announcement [text]"'[/text])))
    (exec (format "/usr/local/bin/growlnotify %s -m \"Finished count down \"" (date (date-value) 0 "%Y-%m-%d %H:%M:%S"))))
; start
(set 'duration-input (main-args 2) 'duration 0)
(set 'start-time (date-value) 'target-time (add (date-value) duration))
(set 'banner
    (string  "Started countdown of "
        (seconds->hms duration)
        " at "
        (date start-time 0 "%Y-%m-%d %H:%M:%S")
        "\nFinish time:                     " (date target-time 0 "%Y-%m-%d %H:%M:%S")))
(while (<= (date-value) target-time)
    (println banner "\n\n"
        "Elapsed: "
        (seconds->hms (- (date-value) start-time ))
        " Remaining: "
        (seconds->hms (abs (- (date-value) target-time))))
    (sleep 1000))
; finished
(println "Countdown completed at " (date (date-value) 0 "%Y-%m-%d %H:%M:%S") "\n")
(notify (main-args 3))

The Rubric Theme Blog at WordPress.com.


Get every new post delivered to your Inbox.