Arc Forumnew | comments | leaders | submitlogin
1 point by eds 6057 days ago | link | parent

I've been working on a version of infix syntax written in arc that relies only on the ability to switch the first and second places in a function call when the functional position contains a number. This means that the solution relies on minimal changes to ac.scm, and can be loaded either automatically or optionally into the running arc toplevel.

I also added setter forms so the user can now define precedence of an operator as such:

  (= (precedence %) 2)
or

  (= (precedence %) /)
And I also experimented with pg's other suggestion for literals being constant functions when in functional position. I found you can have both that and switching arguments at the same time, for example:

  [3] ; always evaluates to 3
  (3 + 4) ; same as (+ 3 4)
  (3 + 4 * 5 - 6) ; when using my infix library
This version being written directly in arc, it is probably slower than the scheme version. But considering it is much less intrusive to ac.scm, I will probably push this version to the arc-wiki.

The code can be obtained at the following url:

http://blackthorncentral.net/files/infix.arc

Changes to ac.scm required to make this work:

  (define (literal? x)
    ; ...
    (procedure? x) ; to allow (eval `(,+ 3 4))

  (define (ar-apply fn args)
    ; ...
    ((or (number? fn) (symbol? fn)) ; (3 + 4) means (+ 3 4)
     (if (pair? args) (apply (car args) fn (cdr args)) fn))


1 point by eds 6054 days ago | link

Pushed this to the arc-wiki.

This means that infix.arc now gets loaded by default when arc starts. Since infix.arc redefines the existing +-/* operators, if you don't want this to happen when arc loads, you can remove it from the list in libs.arc, then load it or not at your leisure.

-----