Arc Forumnew | comments | leaders | submitlogin
2 points by aw 5144 days ago | link | parent

Racket has an XML parser http://docs.racket-lang.org/xml/index.html which is easy to call from Arc: http://awwx.posterous.com/how-to-call-racket-code-from-arc

I should update that post to show how to use dynamic-require though, it's a lot shorter.



1 point by waterhouse 5144 days ago | link

Oh, nice, you have addressed exactly what I was asking for. Hmm, but question... Why not do this? I mean, you mention that it's not the only way, but this seems to work and doesn't require anything like gensymming.

  arc> ($:require xml)
  #<void>
  ;then
  (= parse-xml ($:lambda (s) (xml->xexpr
            (document-element
              (read-xml (open-input-string s))))))
I guess the advantage of your approach is that you can choose to only import the functions you want. If that's particularly important for some reason, then, sure, do it. But I suspect it might actually be useful to import the entire module, especially at the REPL when you're just starting out using it. Particularly if you have a "scheme apropos" function.

  (def scheme-apropos (x)
    (sort < (keep [findsubseq x string._] ($.namespace-mapped-symbols))))
  (mac saps (x)
    `(scheme-apropos (string ',x)))
  arc> saps.xml
  (_parse-xml _xml-clean display-xml display-xml/content exn:xml? read-xml
  read-xml/document read-xml/element syntax:read-xml syntax:read-xml/element
  write-xml write-xml/content xexpr->xml xml->xexpr)
I added the "sort <" part just now, by the way. Can't believe I didn't think to do that originally (though I did at least add it to the "aps" thing somewhat earlier).

-----

1 point by aw 5144 days ago | link

There was something or other that wasn't working when using $ directly because it was Racket-specific and it didn't work in Arc's mzscheme module. I forget now what it was though. (Clearly parse-xml is a bad example as it does work with a simple require).

-----