Skip to content

Commit

Permalink
Make compose and complement ssyntax expand to functions rather than m…
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Sep 22, 2011
1 parent 3625aae commit cbf2bd3
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions arc.arc
Expand Up @@ -172,25 +172,23 @@
`(let self nil
(assign self (fn ,parms ,@body))))

; Ac expands x:y:z into (compose x y z), ~x into (complement x)

; Only used when the call to compose doesn't occur in functional position.
; Composes in functional position are transformed away by ac.

(mac compose args
(let g (uniq)
`(fn ,g
,((afn (fs)
(if (cdr fs)
(list (car fs) (self (cdr fs)))
`(apply ,(if (car fs) (car fs) 'idfn) ,g)))
args))))
; Ac expands x:y:z into (compose x y z)
; Can only compose functions, not macros.
; Composes in functional position are transformed away by ac, and those can
; handle macros.

(def compose fs
(if (no cdr.fs)
car.fs
(fn args
(car.fs (apply (apply compose cdr.fs) args)))))

; Ditto: complement in functional position optimized by ac.
; Ac expands ~x into (complement x)
; Can only handle functions, not macros.
; Complement in functional position transformed away by ac, and can handle macros.

(mac complement (f)
(let g (uniq)
`(fn ,g (no (apply ,f ,g)))))
(def complement (f)
(fn args (no (apply f args))))

(def rev (xs)
((afn (xs acc)
Expand Down

0 comments on commit cbf2bd3

Please sign in to comment.