我试图理解以下代码:
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 是否有这个。
那么,使用 let
与 where
有何意义?这里有必要使用let
吗? (另外,可能还有一个问题:为什么需要那些分号?)
最佳答案
使用let
引入了一个可以修改的变量。请注意 found
和 items
是如何修改的。相比之下,where
总是引入不可变符号。
FFL 中使用分号来创建命令管道。通常在 FFL 中,评估整个公式,产生一个命令或命令列表,然后执行命令。
当存在分号时,分号之前的所有内容都将被视为与分号之后的所有内容完全独立的公式。第一个公式被评估并执行,然后第二个公式被评估并执行。
分号有效地允许 FFL 中更加过程化的编程风格,没有分号,它是一种纯粹的函数式语言。
关于where-clause - 关键字 - FFL : Where vs. 让,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50457299/