1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-09 22:09:41 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/pragmas/Pragma_ _procedure.tid

55 lines
1.9 KiB
Plaintext
Raw Normal View History

2022-10-07 15:56:21 +00:00
created: 20221007132845007
modified: 20230419103154329
2022-10-07 15:56:21 +00:00
tags: Pragmas
title: Pragma: \procedure
type: text/vnd.tiddlywiki
2022-10-09 16:34:22 +00:00
<<.from-version "5.3.0">> The ''\procedure'' [[pragma|Pragmas]] is used to [[define procedures|Procedure Definitions]]. It is a shortcut syntax for the SetVariableWidget with an implicit ParametersWidget.
2022-10-07 15:56:21 +00:00
The usual form allows procedures to span multiple lines:
```
\procedure <procedure-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...)
<multiple-line-definition-text>
\end [<procedure-name>]
2022-10-07 15:56:21 +00:00
```
Note that the `\end` marker can optionally specify the name of the procedure to which it relates which allows procedure definitions to be nested.
2022-10-07 15:56:21 +00:00
There is also a single line form for shorter procedures:
```
\define <procedure-name>(<param-name>[:<param-default-value>],<param-name>[:<param-default-value>]...) <single-line-definition-text>
```
2022-10-09 12:54:33 +00:00
The first line of the definition specifies the procedure name and any parameters. Each parameter has a name and, optionally, a default value that is used if no value is supplied on a particular call to the procedure. The lines that follow contain the text of the procedure text (i.e. the snippet represented by the procedure name), until `\end` appears on a line by itself:
2022-10-07 15:56:21 +00:00
For example:
```
2022-10-09 12:54:33 +00:00
\procedure sayhi(name:"Bugs Bunny")
Hi, I'm $name$.
\end
2022-10-07 15:56:21 +00:00
2022-10-09 12:54:33 +00:00
<<sayhi "Jeremy">>
2022-10-07 15:56:21 +00:00
```
Alternatively, the entire definition can be presented on a single line without an `\end` marker:
```
2022-10-09 12:54:33 +00:00
\procedure sayhi(name:"Bugs Bunny") Hi, I'm $name$.
2022-10-07 15:56:21 +00:00
```
Procedure definitions can be nested by specifying the name of the procedure in the `\end` marker. For example:
<<wikitext-example-without-html src:"""\procedure special-button(caption:"Click me")
\procedure actions()
<$action-sendmessage $message="tm-notify" $param="HelloThere"/>
\end actions
<$button actions=<<actions>>>
$caption$
</$button>
\end special-button
<<special-button>>
""">>