Arc Forumnew | comments | leaders | submitlogin
Using conditions within a withs
2 points by bOR_ 5995 days ago | 2 comments
Hi all. I've rewritten a very unlispy java program into ruby, and now translating it to arc. One of the things I am now encountering is that in a list of variable assignments, there are a few assigments that depend on a condition. Is there a way in which if statements can be within a withs?

  arc> (withs (i 3 (if (> 3 5) (x 5) (x 1))))
  Error: "Can't understand fn arg list 3"
  arc> (withs (i 3 (if (> 3 5) (= x 5) (= x 1))))
  Error: "Can't understand fn arg list 3"
  arc> 
and if the answer is 'no', should this be fixed in the language, or in my understand of how to write decent programs? ;). Right now, I'd work around it by assigning nil to the variables I'll be needing later on.


6 points by rntz 5995 days ago | link

    (withs (i 3
            x (if (> 3 5) 5 1))
      ... insert code here ....)
Conditionals in arc (and all lisps) are expressions; so use it as a value to assign to a variable, rather than using a conditional to wrap a conceptual "assignment statement".

-----

1 point by bOR_ 5994 days ago | link

Thanks! That might be the first thing I learn from lisp where things work fundamentally different than ruby. This gives some interesting possibilities.

-----