Arc Forumnew | comments | leaders | submitlogin
2 points by almkglor 5600 days ago | link | parent

Here's a simple Arc-F package (which is intended to work on hl in the future) that provides pointers.

Pointers are dereferenced by (ptr), so you use (ptr) to get the contents and (= (ptr) v) to assign.

  (in-package pointer)
  (using <arc>v3) ; replace with <hl>v1
  (interface v1
    pointer)
  ; replace with (mac (pointer e) ...)
  (mac pointer (e)
    (if (acons e)
        (let vars (map [uniq] e)
          `(with ,(mappend (fn (var val) `(,var ,val)) vars e)
             ; replace with (tag...)
             (annotate 'pointer
               (cons (fn () ,vars)
                     (fn (v) (= ,vars v))))))
        (w/uniq v
          `(annotate 'pointer
             (cons (fn () ,e)
                   (fn (,v) (= ,e ,v)))))))
  ; replace with (defm (sref (t p pointer)... ) ...)
  (defm sref ((t p pointer) v)
    ((cdr:rep p) v))
  (defcall pointer (p)
    ((car:rep p)))
Usage:

  (= stuff (list (pointer a)
                 (pointer (car b))
                 (pointer c!x)))
  (each p stuff
    (pr (p))
    (= (p) (something)))
If someone's ported nex3's 'defcall and 'defm onto Anarki-on-arc3, the above can be made to work by just removing the package stuff.