From ftm
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 45: Line 45:
 
===See also===
 
===See also===
  
[[How can I work with lists passed to an ftm.mess object?]]
+
[[How can I work with lists passed to an ftm.mess object?]]
  
[[Category:Expressions]] [[Category:ftm.mess]] [[Category:FTM Documentation]]
+
[[Category:Expressions]] [[Category:Functions]]
 +
[[Category:ftm.mess]] [[Category:FTM Documentation]]

Latest revision as of 10:48, 6 August 2010

Syntax

 if <num: condition> <any: true value> [<any: false value>]

Synopsis:

Choose between two values (both conditional values are evaluated). If the <false value> argument is missing, nothing is output.

Description

The if function (not method) should be pretty clear if you keep in mind the two drawbacks:

1. it is a function, i.e. all three arguments are evaluated before the if gets to decide which one to output, i.e. something like

   (if ($1 != 1) ($myfmat mul 2) ($myfmat zero))

always multiplies and then zeros the myfmat!

2. The result of if can only be one atom, not a list. If you want to output one list or another, use tuples, with a subsequent ftm.list, the list function, or the output tuples as list (untuple) inspector option of ftm.mess. This can be used with a 'route' to send different lists out to one or another connection, like this:

   (if ($mydict exists $1) {1 $mydict[$1]} {2 $1 42})
   |
   ftm.list
   |
   route 1 2

or

   (list (if ($mydict exists $1) {1 $mydict[$1]} {2 $1 42}))
   |
   route 1 2

or with untuple

   (if ($mydict exists $1) {1 $mydict[$1]} {2 $1 42})
   |
   route 1 2


See also

How can I work with lists passed to an ftm.mess object?