Composition without combinators

There is still far too much functional noise in the two-line combinator samefringe. Here's how I'd really like to write it:

samefringe = (composition (or eq (and (and* consp) ((and (eq car) (samefringe cdr)) rotate-right))))
rotate-right = (while (composition (consp car)) (composition (cons caar (cons cdar cdr))))

Something like this would do it:

(defmacro composition (body)
  (labels ((translate (term)
             (typecase term
               (symbol (if (fboundp term) `#',term term))
               (cons (case (car term)
                       (or `(hor ,@(mapcar #'translate (cdr term))))
                       (and `(hand ,@(mapcar #'translate (cdr term))))
                       (t (cons (if (cddr term) 'h '|.:|) (mapcar #'translate term)))))
               (t `(k ,term)))))
    (translate body)))

This is a language where composition, not application, is the Form Without A Name.

(Edit 6 January: fixed examples.)

No comments:

Post a Comment

It's OK to comment on old posts.