Links of the day


Thursday, October 22, 2009



Scheme allows punctuation marks in its identifiers, which allows for some funky naming convention. One of the most widely adopted convention is to name functions which return a boolean so that they end in ? (e.g. prime?), and name functions which have side effects to end in ! (e.g. set-random-seed!).

One problem with the Scheme language is that that convention hasn't been fleshed out any further. Here is the extension Tim and I designed.

(define (foo?? fn) ...) ;; Tests whether fn is a predicate for foo.

(define (foo!? fn) ...) ;; Tests whether fn is the setter for foo.

(define (foo?! fn) ...) ;; Sets a global predicates that will be used to test for foo's. For instance...

(define (true?! fn) ...) ;; Sets how we will be testing for true from now on, a.k.a. true?! redefines the behavior of if and cond.

(define (foo!! fn) ...) ;; Sets a setter for foo's. I'm not sure what this means. I'm tempted to say it is a setter for foo's that generates a yelling sound on the pc speaker as a side effect of the side effect.

It is also interesting to consider function names consisting of nothing but suffixes.

(define (? v) ...) ;; This is the predicate which doesn't specify what it is testing for. It is the vacuous predicate, It is the predicate that always returns true.

(define (?? fn) ...) ;; Tests whether the given function is a predicate. The ?? function is a kind of runtime type system. In other words, ?? applies the (any . -> . bool?) contract.

(define (!? fn) ...) ;; Tests whether fn might have side effects. !? is part of a compiler optimization pass.

(define (?! fn) ...) ;; Sets the global vacuous predicate. I'm not sure what this means either. I think it sets which logic you want to operate with. For a good time, set it to (lambda (v) false) and watch your entire model of computation collapse under the contradictions generated.

(define (! heap continuation) ...) ;; ! is the function that sets everything. It is the function that takes in a reified heap and a continuation and sets your interpreter state, wiping off the current state, then calls the continuation.

Defining function for names consisting of suffixes of three or more bangs and uhs (and nothing else) is left as an exercise to the reader.

While Scheme allow most punctuation marks in identifiers, somehow parentheses are forbidden. What a gross oversight. If we had it we could have define the smiley operator.

(define (:) v) ...) ;;; This is the smiley operator. It consumes a value and return a happy version of that value.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]