Search code examples
where-clauseletanuraffl

keyword - FFL: Where vs. Let


I was trying to understand the following code:

    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 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.

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?)


Solution

  • Using let introduces a variable that can be modified. Note how found and items are modified. By contrast, where always introduces immutable symbols.

    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.

    Semi-colons effectively allow a much more procedural programming style in FFL, without semi-colons it is a purely functional language.