Arc Forumnew | comments | leaders | submitlogin
4 points by drcode 6148 days ago | link | parent

i think you want "withs"

  (withs (bar [+ 1 _]
          foo [bar _])
         (foo 5))
..in hindsight, you're arguing it needs mutual recursion, which withs doesn't have either...


3 points by cchooper 6148 days ago | link

Ooh... I hadn't seen withs before. That'll be useful.

But you're right, it still doesn't fix it. The closest thing is labels in Common Lisp, but that can only be used to create functions. Perhaps if even CL can't do it then it's not that useful after all.

-----

4 points by drcode 6147 days ago | link

of course you can do this:

  (with (foo nil
         bar nil)
        (= foo [bar _])
        (= bar [+ 1 _])
        (foo 5))
That is the Right Way to solve this in arc, I think... Handles mutual recursion without problem. Easily wrappable in a macro, if desired.

-----

3 points by cchooper 6147 days ago | link

You just beat me to it:

  (mac fwiths (defs . body)
    `(with ,(intersperse-nils (keep-odd-pos defs))
           ,@(make-setters defs)
           ,@body))

  (def keep-odd-pos (lst)
    (if lst (cons (car lst) (keep-odd-pos (cddr lst)))))

  (def intersperse-nils (lst)
    (if lst (cons (car lst) (cons nil (intersperse-nils (cdr   lst))))))

  (def make-setters (lst)
    (if lst (cons (list '= (car lst) (cadr lst)) (make-setters (cddr lst)))))

-----

3 points by shiro 6148 days ago | link

The closest thing you want is letrec in Scheme, which binds both functions and variables.

-----