Arc Forumnew | comments | leaders | submitlogin
A simple way to reference Scheme procedures from Arc
7 points by CatDancer 6259 days ago | 2 comments
xdef in ac.scm exports Scheme procedures to Arc, but it's ugly to have to add every Scheme procedure I want to use to ac.scm.

Anarki has seval which evals a Scheme expression, so another way to get at a Scheme procedure is to say:

    (= semaphore-post (seval 'semaphore-post))
which is much nicer. However, if I'm only using a Scheme procedure in one place in my code, I don't want to have to stop to make it a top level function, or clutter my top level namespace. I'd like to be able to say

    ... code code code ...
    ((scheme post-semaphore) s)
    ... code code code ...
with (scheme x) being expanded a macro expansion time, instead of being evaluated at run time like seval is.

Since there's the limitation of not being able to return a procedure value from a macro expansion, I can't just say

    (mac scheme (x) (seval x))
so I was starting to think about hacks like having the macro set a uniq global variable and then expanding to that variable... when I thought, "oh wait, Arc is getting compiled to Scheme, so all that needs to happen is to have (scheme x) insert x in the compiled output".

So add to the definition of ac in ac.scm:

    ((eq? (xcar s) 'scheme) (cadr s))
and, that simply, (scheme x) does what I'm looking for.


2 points by almkglor 6257 days ago | link

The equivalent in Anarki is '$ :

  (($ semaphore-post) s)
Also, I've already exposed semaphores in Anarki. http://arclanguage.com/item?id=6204 http://arclanguage.com/item?id=6802

Anarki needs some serious documenting T.T

Edit: as an aside, $ is a "reserved" variable in SNAP; I intend to use it as a sort of "implementation-specific" variable, so any use of $ should be attached very tightly to the implementation of Arc.

-----

2 points by CatDancer 6257 days ago | link

Yes, $ does the same thing, but it evaluates at run time while I wanted something that evaluated at macro expansion time.

-----