From ftm
Revision as of 10:41, 6 August 2010 by Diemo (talk | contribs) (see also)
Jump to: navigation, search

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?