Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Verbs With Implicit Taking #3

Open
3 tasks
tajmone opened this issue Aug 21, 2019 · 0 comments
Open
3 tasks

Optimize Verbs With Implicit Taking #3

tajmone opened this issue Aug 21, 2019 · 0 comments

Comments

@tajmone
Copy link
Owner

tajmone commented Aug 21, 2019

Remove useless IF clause to check that implicit-take went well in various verbs, for it's not needed.

  • Find all verbs that have implicit-take and an IF clause to check that it succeeded.
  • Remove the IF clause surrounding the code to be executed after the implicit take.
  • Find if other verbs have similar redundant IF clauses, in contexts other than implicit taking.

Rationale

Various verbs that carry out implicit-taking use an IF clause to check that the implicit take succeeded. E.g. from lib_classes.i, verb give on liquid:

  VERB give -- LIQUID
    WHEN obj
    DOES ONLY
      -- >>> implicit take >>>
      IF THIS NOT IN hero
        THEN
          IF vessel OF THIS = null_vessel OR vessel OF THIS IS NOT takeable
            THEN "You can't carry" SAY THE THIS. "around in your bare hands."
            ELSE LOCATE vessel OF THIS IN hero.
              "(taking" SAY THE vessel OF THIS. "of" SAY THIS. "first)$n"
          END IF.
      END IF.
      -- <<< implicit take <<<

      IF THIS IN hero
        -- i.e. if the implicit taking was successful
        THEN
          "You give" SAY THE vessel OF THIS. "of" SAY THIS. "to" SAY THE recipient. "."
          LOCATE vessel OF THIS IN recipient.
      END IF.

The problem here is that there's no need to carry out that check, for if the LOCATE statement in the implicit-take action were to fail for any reason (e.g. the object is held by an actor) then the rest of the verb execution would be aborted, so there's no risk (nor chance) that the rest of the DOES body is executed anyhow — therefore the whole IF clause surrounding the final part of the verb is unneeded.

Unfortunately, this aspect of Alan VERBs is not covered clearly in the Alan Manual, but here is a proof of this:

--==============================================================================
-- "Test Verb Execution Abortion" by Tristano Ajmone
--==============================================================================

THE room IsA LOCATION
END THE room.

THE box IsA object AT room.
  CONTAINER
    EXTRACT CHECK
      "You can't take things from Bruno's box, he'd be mad at you!"
END THE box.

THE ball IsA object IN box.
END THE ball.

SYNTAX take = take (obj)
  WHERE obj IsA object
    ELSE "You can only take objects."


ADD TO EVERY object
  VERB take
    DOES
      locate obj in Hero.
      "You take $+1." --> If the previous line fails this is not executed!
  END VERB take.
END ADD TO object.

Start at room.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant