关键字 - FFL:Where vs. Let [英] keyword - FFL: Where vs. Let
问题描述
我试图理解以下代码:
def() ->commands
if(deferred_passive_abilities != [],
let [{ability: class passive_ability, creature: class creature}] items = [];
let found = false;
map(deferred_passive_abilities,
if(cmd = null, add(items, [value]), [cmd, set(found, true)])
where cmd = value.ability.static_effect(me, value.creature));
if(found,
set(deferred_passive_abilities, items);
evaluate_deferred_passive_abilities(),
set(deferred_passive_abilities, []))
)
Haskell 似乎同时具有 let
和 where
,但我通过粗略阅读他们的 Haskell 文档并没有学到太多东西.他们也有一个 let...in
,我不明白,但如果 FFL 有那个,我会很高兴.
Haskell appears to have both let
and where
, but I didn't learn much by a superficial reading of their haskell docs. They also have a let...in
, which I didn't understand but it would be good to know if FFL has that.
那么,使用 let
和 where
的意义是什么?这里有必要使用 let
吗?(另外,可能还有一个问题:为什么需要那些分号?)
So, what is the significance of using let
versus where
? Was it necessary to use let
here? (Also, possibly another question: why does it need those semicolons?)
推荐答案
使用 let
引入了一个可以修改的变量.注意 found
和 items
是如何修改的.相比之下,where
总是引入不可变符号.
Using let
introduces a variable that can be modified. Note how found
and items
are modified. By contrast, where
always introduces immutable symbols.
分号在 FFL 中用于创建命令管道.通常在 FFL 中,对整个公式进行求值,生成一个命令或命令列表,然后执行这些命令.
Semi-colons are used in FFL to create a command pipeline. Normally in FFL, an entire formula is evaluated, resulting in a command or list of commands, and then the commands are executed.
当存在分号时,分号之前的所有内容都被视为与分号之后的所有内容完全不同的公式.第一个公式被评估和执行,然后第二个公式被评估和执行.
When a semi-colon is present, everything before the semi-colon is treated as an entirely separate formula to everything after the semi-colon. The first formula is evaluated and executed and then the second formula is evaluated and executed.
分号有效地允许 FFL 中的程序化编程风格,没有分号它是一种纯函数式语言.
Semi-colons effectively allow a much more procedural programming style in FFL, without semi-colons it is a purely functional language.
这篇关于关键字 - FFL:Where vs. Let的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!