Scol standard library package
0.3.1
Common and usefull functions for all Scol applications
|
Functions | |
std_doWhile (cond, cbfun, param) | |
Perform a do while-like loop, as some another languages. More... | |
std_for (start, end, inc, cbfun) | |
Perform a for-like loop, as some another languages. More... | |
std_forF (start, end, inc, cbfun) | |
Perform a for-like loop, as some another languages. More... | |
std_if (cond, cbfun, param) | |
Perform a IF-like, as some another languages. More... | |
std_switch (cond, cbfun, list) | |
Perform a switch-like loop, as some another languages. More... | |
std_switchStr (cond, cbfun, list) | |
Perform a switch-like loop, as some another languages. More... | |
std_switchStri (cond, cbfun, list) | |
Perform a switch-like loop, as some another languages. More... | |
Package to load : lib/std/loop.pkg
Dependancies :
std_switch | ( | cond | , |
cbfun | , | ||
list | |||
) |
Perform a switch-like loop, as some another languages.
The switch statement is similar to a series of IF statements on the same expression. According to a value / a result of expression, a function is called with a specific argument.
The list contains a tuple with an integer and any object. This integer is the expression result.
Prototype: fun [I fun [I u0] u1 [[I u0] r1]] u1
I | : a variable or an expression. |
fun | [I u0] u1 : the function to call |
[[I | u0] r1] : a list with the result of the condition and the user parameters |
std_switchStr | ( | cond | , |
cbfun | , | ||
list | |||
) |
Perform a switch-like loop, as some another languages.
The switch statement is similar to a series of IF statements on the same expression. According to a value / a result of expression, a function is called with a specific argument. Value or result expression must be a string(S). This function is case-sensitive.
The list contains a tuple with an integer and any object. This integer is the expression result.
Prototype: fun [S fun [S u0] u1 [[S u0] r1]] u1
I | : a variable or an expression. |
fun | [I u0] u1 : the function to call |
[[I | u0] r1] : a list with the result of the condition and the user parameters |
std_switchStri | ( | cond | , |
cbfun | , | ||
list | |||
) |
Perform a switch-like loop, as some another languages.
The switch statement is similar to a series of IF statements on the same expression. According to a value / a result of expression, a function is called with a specific argument. Value or result expression must be a string(S). This function is case-insensitive.
The list contains a tuple with an integer and any object. This integer is the expression result.
Prototype: fun [S fun [S u0] u1 [[S u0] r1]] u1
I | : a variable or an expression. |
fun | [I u0] u1 : the function to call |
[[I | u0] r1] : a list with the result of the condition and the user parameters |
std_for | ( | start | , |
end | , | ||
inc | , | ||
cbfun | |||
) |
Perform a for-like loop, as some another languages.
As in C, std_for has the following internal behavior :
for (expr1; expr2; expr3) statement
The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.
In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and statement is executed. If it evaluates to FALSE, the execution of the loop ends.
At the end of each iteration, expr3 is evaluated.
However, expr1,2 or 3 can not be nil (in this case, std_for stops and returns nil). There is no 'break'.
According to a value / a result of expression, a function is called with a specific argument. Value or result expression must be a string(S). This function is case-insensitive.
The list contains a tuple with an integer and any object. This integer is the expression result.
Prototype: fun [I I I fun [I] u0] u0
I | : a starting value. |
I | : an ending value. |
I | : an increment (or decrement) like 2 or -5 ... |
fun | [I] u0 : the function to call to each iteration |
See too : http://www.scolring.org/files/doc_html/forI.html
See too : http://www.scolring.org/files/doc_html/forList.html
See too : http://www.scolring.org/files/doc_html/forTab.html
std_forF | ( | start | , |
end | , | ||
inc | , | ||
cbfun | |||
) |
Perform a for-like loop, as some another languages.
As in C, std_for has the following internal behavior :
for (expr1; expr2; expr3) statement
The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.
In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and statement is executed. If it evaluates to FALSE, the execution of the loop ends.
At the end of each iteration, expr3 is evaluated.
However, expr1,2 or 3 can not be nil (in this case, std_for stops and returns nil). There is no 'break'.
According to a value / a result of expression, a function is called with a specific argument. Value or result expression must be a string(S). This function is case-insensitive.
The list contains a tuple with an integer and any object. This integer is the expression result.
Prototype: fun [F F F fun [F] u0] u0
F | : a starting value. |
F | : an ending value. |
F | : an increment (or decrement) like 2.2 or -5.54 ... |
fun | [F] u0 : the function to call to each iteration |
std_doWhile | ( | cond | , |
cbfun | , | ||
param | |||
) |
Perform a do while-like loop, as some another languages.
It is similar then while do but the statment is always executed once time.
The function loops while the 'cond' is not equal at 1.
Prototype : fun [fun [] I fun [u0] u1 u0] u1
fun | [] I : the "cond" to ends the loop. If this function can never return 1, the loop will be infinite. If the function is nil, std_doWhile does nothing and return nil |
fun | [u0] u1 : the function "called" to each loop |
u0 | : a parameter at your convenience for the called function |
If needed, you can use mkfunX function to add parameters to the "called" function.
std_if | ( | cond | , |
cbfun | , | ||
param | |||
) |
Perform a IF-like, as some another languages.
This is a conveniance function to avoid write an "else" statment.
var a=5;
cbIfCond(){ a == 5; }
cbIf2(param, param2){ set a = 0; _fooS param: param2; }
cbIf(param){ param; }
main(){ _showconsole; _fooS std_if mkfun2 "END !" "BEGIN"; // END ! _fooS std_if "NOT POSSIBLE !"; // NIL 0; }
Prototype : fun [fun [] I fun [u0] u1 u0] u1
fun | [] I : the "if" expression/condition |
fun | [u0] u1 : function to call if the condition is true |
u0 | : a parameter at your convenience for the called function |