This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
harlowe:lambda [2019/04/16 04:05] l |
harlowe:lambda [2019/04/16 04:07] l |
||
---|---|---|---|
Line 22: | Line 22: | ||
lambda will not affect any other ''%%_num%%''. | lambda will not affect any other ''%%_num%%''. | ||
- | An important feature is that you can save lambdas into variables, and reuse them in your story easily. You | + | You can use the "it" shorthand to save on having to write the temporary variable's name multiple times. ''%%_num where _num > 2%%'' can be rewritten as''%%_num where it > 2%%''. Not only that, but you can even save on naming the temporary variable at all, by just using ''%%where%%'' (or ''%%via%%'' or ''%%making%%'') without the name and only using ''%%it%%'' to refer to the variable: ''%%where it > 2%%''. |
- | could, for instance, ''%%(set: $statsReadout to (_stat making _readout via _readout + "|" + _stat's name + ":" + _stat's value))%%'', | + | |
- | and then use $printStats with the [[harlowe:folded|(folded:)]] macro in different places, such as ''%%(folded: $statsReadout, ...(dataentries: $playerStats))%%'' for displaying the player's stats, ''%%(folded: $statsReadout, ...(dataentries: $monsterStats))%%'' for a monster's stats, etc. | + | An important feature is that you can save lambdas into variables, and reuse them in your story easily. You could, for instance, ''%%(set: $statsReadout to (_stat making _readout via _readout + "|" + _stat's name + ":" + _stat's value))%%'', and then use $printStats with the [[harlowe:folded|(folded:)]] macro in different places, such as ''%%(folded: $statsReadout, ...(dataentries: $playerStats))%%'' for displaying the player's stats, ''%%(folded: $statsReadout, ...(dataentries: $monsterStats))%%'' for a monster's stats, etc. |
Lambdas are named after the lambda calculus, and the "lambda" keyword used in many popular programming languages. | Lambdas are named after the lambda calculus, and the "lambda" keyword used in many popular programming languages. | ||
They may seem complicated, but as long as you think of them as just a special way of writing a repeating instruction, | They may seem complicated, but as long as you think of them as just a special way of writing a repeating instruction, | ||
and understand how their macros work, you may find that they are very convenient. | and understand how their macros work, you may find that they are very convenient. |