To understand a YCP script, it is strongly recommended to set the correct quotings.
|
Practical approach for beginners:
|
Use as less backquotes as possible
- Do not use the datatype symbol, use string instead
- Use always a backquote, if you call a builtin/define via UI or SCR
Example: SCR(`Read(...)) or UI( `DisplayMessage())
- Use always double backquotes, where the examples use backquotes: In UI(``{, define,
foreach, mapmap, listmap ... and similar builtins
|
|
YCP Backquotes in detail
|
There are three different backquote types:
|
1. Tag a symbol: `symbol
|
Here the single quote shows that the following string is a symbol.
The single backquote is needed, to differentiate a variable and a symbol.
See symbol
Example: `true, `easy
|
2. Do not evaluate:``(term)l or ``{term}
|
Here the single quote prevents the term from being evaluated. This behaviour is needed:
- if the written code
should be evaluated more than once like a define or for all members of
a list/map like foreach, listmap, mapmap ...
- you send your code to a client, and the client should execute it, like
UI(``{..})
|
3. Evaluate arguments, not the term:`term
|
Here the single quote shows interpreter, that the argumets should be evaluated, but the term is not evaluated.
This behaviour is needed, if we call a UI define from the WFM, and want to pass arguments from a variable.
- If we write UI(``(DisplayMessage(my_message))) The complete string is send to
the UI and the UI correctly evaluates
the define DisplayMessage. Then it trys to evaluate
my_message, and fails, because this is a variable in
the WFM context.
- If we write UI(DisplayMessage(my_message)), the WFM trys to evaluate DisplayMessage
and fails, because this a define in the UI.
- If we write UI(`DisplayMessage(my_message)), the WFM only evaluates the arguments
of the term: my_message and sends for example
DisplayMessage("Hello Wold") to the UI, the UI evalutes DisplayMessage, and the "hello Worl" is shown.
|