Arc Forumnew | comments | leaders | submitlogin
3 points by cchooper 6095 days ago | link | parent

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 6095 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 6095 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 6095 days ago | link

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

-----