Cat’s hacks:

ac

Hack the Arc compiler from Arc

ac0.patch

diff --git a/ac.scm b/ac.scm
index 791a4ca..3f1663b 100644
--- a/ac.scm
+++ b/ac.scm
@@ -22,6 +22,7 @@
         ((ssyntax? s) (ac (expand-ssyntax s) env))
         ((symbol? s) (ac-var-ref s env))
         ((ssyntax? (xcar s)) (ac (cons (expand-ssyntax (car s)) (cdr s)) env))
+        ((eq? (xcar s) 'ac-scheme) (cadr s))
         ((eq? (xcar s) 'quote) (list 'quote (ac-niltree (cadr s))))
         ((eq? (xcar s) 'quasiquote) (ac-qq (cadr s) env))
         ((eq? (xcar s) 'if) (ac-if (cdr s) env))

ac0.arc

(= ac-denil       (ac-scheme ac-denil))
(= ac-global-name (ac-scheme ac-global-name))
(= ac-niltree     (ac-scheme ac-niltree))

; for when we can't use assign

(mac ac-set-global (name val)
  (w/uniq (gname v)
    `(with (,gname (ac-global-name ,name)
            ,v ,val)
       (ac-scheme (namespace-set-variable-value! ,gname ,v))
       nil)))

description

The title “Hack the Arc compiler from Arc” is more aspiration than reality at this point :-) But as I find ways to make my hacks shorter by exposing bits of the Arc compiler inside of Arc, this is a place to put them.

ac-scheme

The ac-scheme syntax quotes an expression, protecting it from being compiled by the Arc compiler. The expression is passed through unchanged to the MzScheme language that Arc is written in, and thus is interpreted as an MzScheme expression by MzScheme.

 arc> (ac-scheme (let ((a 3))
                   (+ a 20)))
 23

What works and doesn’t work inside an ac-scheme expression is highly dependent on the precise details of how Arc code is compiled into Scheme code. For example, the arc3 compiler happens to compile an Arc lexical scope into an MzScheme lexical scope, and keeps the same variable names:

 arc> (let a 4
        (ac-scheme (* 2 a)))
 8

but this could completely change in another release of Arc.

An Arc macro can expand into an ac-scheme form, and so can generate the Scheme code which is tunneled through the Arc compiler.

ac-global-name

ac-global-name takes an Arc global variable name, and returns the name of the global variable inside of MzScheme.

get this hack

wget http://ycombinator.com/arc/arc3.tar
tar xf arc3.tar
cd arc3
wget -O - http://hacks.catdancer.ws/ac0.patch | patch
wget http://hacks.catdancer.ws/ac0.arc
mzscheme -m -f as.scm
(load "ac0.arc")

license

public domain