Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About "cond" in scheme

I want to be able to do this. For example, this is my code:

    (cond [true AA]
          [else BB])

In AA, I want it to do 2 things. 1 is to set the value of a global variable, and then return a string. How would I go about doing that?

like image 834
nonion Avatar asked Jun 11 '13 13:06

nonion


1 Answers

In the cond special form, there's an implicit begin after each condition, so it's ok to write several expressions, remembering that only the value of the last one will be returned. Like this:

(cond [<first condition>
       (set! global-variable value)
       "string to return"]
      [else
       "other return value"])
like image 104
Óscar López Avatar answered Sep 22 '22 14:09

Óscar López