User Tools

Site Tools


modding:function:or

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
modding:function:or [2014/12/27 04:40] – external edit 127.0.0.1modding:function:or [2017/01/26 00:26] (current) 0xabcdef
Line 1: Line 1:
-[[modding:function:or]]+[[or Talk Page|Discuss this page]]
  
 === or === === or ===
  
-[[modding:function:or]]+See [[http://xelerus.de/index.php?s=functions&function=135|or at Xelerus]]
  
-^ Syntax | (or [condition]^1) | +^ Syntax | (or exp1 [exp2 ... expn]) -> value/Nil 
-^ Arguments | [condition]Something other than Nil or Nil +^ Arguments | exp1An expression that evaluates to **Nil** or something else 
-^ | ^1 +[exp2 ... expn] Additional expressions to be evaluated 
-Returns condition: the result of oring all of the conditions | +Category | [[logical operator functions|logical operator]] | 
-[[modding:function:or]] | +^ Returns | The value of the first expression that does not return **Nil**, or **Nil** if there is noneIf there is only one argument, returns the value of that argument. | 
-Description | Returns True if any the conditions are not Nil otherwise returns Nil. |+^ Description | Uses lazy evaluation, which means that it stops after it finds a non-**Nil** value or ends up evaluating every argument if all of them return **Nil** |
  
 === Example === === Example ===
 +<code>
 +(or 1 2 3 4 5 (setq foo 6))
 +</code>
 +Return **1**. Also, foo will not be set to **6**.
 +
 +<code>
 +(or Nil (eq (setq foo "bar") "baz") "qux")
 +</code>
 +Returns **"qux"**. Also, **foo** will be set to **"bar"**
 +
 +<code>
 + (errblock (error b)
 + (setq b (or c 0))
 + b
 + )
 +</code>
 +If **c** has not been bound anything, then this code will return the error **No binding for symbol [c] ### (or c 0) ###** since errors are not **Nil**. Beware of bad code when using **errBlock**, as **or** will simply evaluate the thrown errors as **true**
  
-<code lisp>(block (someCondition)  
- (setq someCondition True) 
- (or someCondition Nil) 
- )</code> 
-This will return a True. 
 Return to [[:Functions]] list Return to [[:Functions]] list
  
modding/function/or.1419655255.txt.gz · Last modified: 2017/01/26 00:12 (external edit)