首页 > 解决方案 > 关键字 - 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 似乎同时具有letwhere,但是通过对他们的 haskell 文档的肤浅阅读,我并没有学到很多东西。他们也有一个let...in,我不明白,但如果 FFL 有它会很好。

那么,使用letvs有什么意义where呢?有必要在这里使用let吗?(另外,可能还有另一个问题:为什么需要这些分号?)

标签: where-clauseletanuraffl

解决方案


在这之前在FFL里从来不知道let,肯定是非常少见的。

不管有什么见解,分号必须是绝对必要的,以便在使用绑定变量之前强制执行。换句话说,在使用分号之前,变量是不存在的。没有界限值。

where这与不需要分号的 有很大区别。

鉴于分号不是完全适合初学者的结构,我可以向初学者推荐一些关于变量的建议,where直到了解分号的诡计。


推荐阅读