awwx.ws

scheme0

Access Scheme from Arc

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

(= ac-denil       scheme.ac-denil)
(= ac-global-name scheme.ac-global-name)
(= ac-niltree     scheme.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))
       nil)))

(= 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)))
23

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)))
8

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"))
4

is the same as saying

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

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")))
6

(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.

Prerequisites

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

Get this hack

Using the hackinator:

$ hack \
    ycombinator.com/arc/arc3.1.tar \
    awwx.ws/defarc0.patch \
    awwx.ws/defarc-ac0.patch \
    awwx.ws/extend0.arc \
    awwx.ws/scheme0.arc

License

Same as Arc.

Contact me

Twitter: awwx
Email: andrew.wilcox [at] gmail.com