The following are functions that provide procedural programming capabilities as found in languages such as FORTRAN and C.
Important: In the descriptions below, items enclosed in square brackets [
]
are optional. If you choose to include the optional
information, do not include the square brackets, only the items within them.
If...then...else function
CLIPS provides an
if...then...else
structure to allow for conditional execution of a set of actions.The syntax is
(if <expression> then <action> [else <action>] )
Any number of allowable actions can be used inside of the
then
andelse
portions, including otherif...then...else
structures. Theelse
portion is optional. If<expression>
evaluates to anything other than the symbolFALSE
, then the actions immediately following thethen
are executed.Otherwise, the actions following the
else
are executed. Although theif
function returns a value, it is not useful in Ansys Polyflow.Example:
This function sets the local variable
?Val
to 3. if the variable?v
is equal to 6, and sets?Val
to 1. otherwise. In addition to=
, you can use the comparison operators <, >,<=
, and >=
.(if (= ?v 6) then (bind ?Val 3.) else (bind ?Val 1.) )
While
The
while
function is provided to allow simple looping. Its use is similar to that of theif
function.The syntax is
(while <expression>[do] <action>)
Any number of functions can be included in the
<action>
. The symboldo
can appear after the<expression>
but it has no effect on the function.If
<expression>
is evaluated toFALSE
, then the function stops and does nothing. If<expression>
is notFALSE
, then<action>
is executed. Then<expression>
is reevaluated: ifFALSE
, the function stops; if notFALSE
,<action>
is executed again, and the process continues until<expression>
evaluates toFALSE
.Example:
(while (< ?v 10) (bind ?v (- (* ?v ?v) 10)) )
This function take the value of
v
and, if it less than 10, repeatedly replaces it with the value of-10
untilv
is greater than 10.Loop-for-count
The
loop-for-count
function is provided to allow simple iterative looping.The syntax for this function is
(loop-for-count <range-spec>[do]<action>)
where
<range-spec>
has the syntax<end-index> | (<loop-variable>[<start-index><end-index>])
where
<start-index>
and<end-index>
are integer expressions.Any number of functions and expressions can be included in the
<action>
.Example 1:
(loop-for-count 5 (bind ?X1 (sin ?X1)))
This example replaces
?X1
by the value of .Example 2:
(deffunction PowerSeries4 (?x) (bind ?y 0) (loop-for-count (?Count 0 4) do (bind ?y (+ ?y (** ?x ?Count))) ) ?y )
This example takes a number and returns