Scripting OS X with Scheme

Scheme-OSA stands for Open Scripting Architecture. It provides an abstract interface for applications to compile, execute, and manipulate scripts without needing to know the details of the particular scripting language. Scheme-OSA bridge furnishes a Scheme user with a means of accessing the OS X multimedia and other resources from Apple and the third parties – introducing graphics, scientific plotting, dialog boxes, music, etc. into the world of Scheme language.

(via comp.lang.scheme)

How to do something to all elements of a list but the last

In this post on the PLT discussion list I sleepily wondered how to do something to all elements of a list but the last.

The reasons I asked is because I had used ‘do’ loops in lieu of something better, and from what I can gather, you basically never write ‘do’ loops in Scheme (maybe once every 30 years you do use ‘do’).

I hastily posted a solution using the ‘match’ library as I had just read the documentation while cutting over from ‘mzlib/match’ to ‘match’. Both Robby and Ethan replied with much, much faster solutions. Have a look:


#lang scheme

(require (prefix-in srfi/1: srfi/1))

; Grant's
(define (foo1 args fun last-fun)
  (match args
    [(list arg args ..1)
     (fun arg)
     (foo1 args fun last-fun)]
    [(list arg)
     (last-fun arg)]))

(provide/contract
 [foo2 (-> (cons/c any/c (listof any/c))
           (-> any/c any)
           (-> any/c void?)
           void?)])

; Robby's
(define (foo2 args fun last-fun)
  (let loop ([fst (car args)]
             [rst (cdr args)])
    (cond
      [(empty? rst) (last-fun fst)]
      [else (fun fst) (loop (car rst) (cdr rst))])))

(define data (srfi/1:make-list 10000 "hi"))

; Ethan's
(define (foo3 lst fun funl)
  (begin
    (for-each fun (srfi/1:drop-right lst 1))
    (funl (srfi/1:take-right lst 1))))

(time
 (foo1 data
       (λ (x) (void))
       (λ (x) (void))))

(time
 (foo2 data
       (λ (x) (void))
       (λ (x) (void))))

(time
 (foo3 data
       (λ (x) (void))
       (λ (x) (void))))

> cpu time: 2593 real time: 2625 gc time: 718
> cpu time: 0 real time: 0 gc time: 0
> cpu time: 0 real time: 0 gc time: 0

In the end, I only needed this functionality in two places, and I probably would not have required it if I had designed things better in the first place.

Joel Bartlett’s Famous Scheme->C System

Joel Bartlett’s original Scheme->C system has been in stealth mode for some years now, but with a recent re-license under F/OSS terms by HP, the allocation of a web site http://scheme2c.alioth.debian.org/, the integration of all known useful patches including LINUX/i386 and LINUX/amd64 ports, and uploading into the Debian incoming queue, this zippy R4RS Scheme is on the move again!

(via comp.lang.scheme)

Larceny Scheme

Larceny is a simple and efficient implementation of the Scheme programming language. Created originally as a test vehicle for research on garbage collection and compiler optimizations, Larceny has grown into a major multiplatform system, and is currently the only implementation that supports all four de facto standards for Scheme: IEEE/ANSI, R5RS, ERR5RS, and the R6RS.

Setting the memory limit in DrScheme

When you use DrScheme, you should be sure to set the memory limit by going to the menu-item:

Scheme->Limit Memory

Doing so allows DrScheme to “play nice” with the operating system when you write some code that eats up all of the free memory. Rather than taking the whole operating system down; DrScheme dies gracefully.

Maglev Ruby

Ruby is often compared to Smalltalk; and I’m sure a bunch of folks have always wondered when someone would implement Ruby either on top of Smalltalk (or even in a similar manner to Smalltalk, aka Rubinius).

Avi Bryant wondered as such, and seems to have gotten a job out of it in producing Maglev Ruby (it is a video).

Maglev seems to be the combination of a Ruby VM implemented along with a distributed, concurrent object system to support the needs of Ruby on Rails.

I heard Avi speak at OSCON 06, and he seems to be a nice fellow; I’ll be interested to see how this pans out.

Strangely, I haven’t heard Maglev mentioned by anyone I know, perhaps Ruby VMs aren’t interesting.