Access Scheme from Arc

(extend ac (s env) (and (errsafe:acons s) (is (car s) 'scheme))
  `(begin ,@(cdr s)))

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

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

(= scheme-f (read "#f"))
(= scheme-t (read "#t"))

(scheme ...)

The 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> (scheme (let ((a 3))
               (+ a 20)))

What works and doesn’t work inside an scheme expression is dependent on the precise details of how Arc code is compiled into Scheme code. For example, the arc3 compiler compiles an Arc lexical scope into an MzScheme lexical scope, and keeps the same variable names, but this could change in another release of Arc.

arc> (let a 4
       (scheme (* 2 a)))

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

Arc’s period syntax provides a useful abbreviation for referring to Scheme functions. For example,

arc> (scheme.+ 3 (pos #\b "abc"))

is the same as saying

arc> ((scheme +) 3 (pos #\b "abc"))

which calls Scheme’s + on the Arc arguments. Contrast this with wrapping the whole expression in scheme, which calls Scheme’s + with Scheme arguments.

arc> (scheme (+ 3 (string-length "foo")))

(ac-global-name name)

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

(ac-denil lst)

Converts an Arc list into an MzScheme list by converting the trailing nil into an MzScheme '().

(ac-niltree lst)

The reverse of ac-denil: converts an MzScheme list into an Arc list by changing MzScheme '() into Arc’s nil.

(ac-set-global name value)

Sets the Arc global variable name to value. Useful when we need to bypass assign.

scheme-t, scheme-f

The Scheme true and false values, #t and #f.


This hack uses arc3.1, defarc0, defarc-ac0, and extend0.

Get this hack

Using the hackinator:

$ hack \ \ \ \ \


Same as Arc.

Contact me

Twitter: awwx
Email: andrew.wilcox [at]