内联评估冒险

  • Inline Evaluation Introduction: Inline evaluation has been around for a while but not all programmers have used it. A simple editor with code examples is provided where Control-r (or ^r for shorthand) is used to run/evaluate code. Small parts of expressions and multi-line expressions can be evaluated easily.
  • Using Inline Evaluation for Function Discovery: When unsure about function names or behavior, inline evaluation can be used to quickly check if a function exists and behaves as expected. For example, evaluating (show-html "<h1>It's in a DIV!</h1>") and (display-html "<h1>It's in a DIV!</h1>") to determine the correct function.
  • Applying Inline Evaluation in a Game Context: In a text adventure game example, functions like (look), (move :east), (stack), (push :picture), (peek), (pop), and (unlock-function :\_something?\_) are evaluated using inline evaluation to understand their purpose and effect on the game state.
  • Building and Enhancing Code with Inline Evaluation: Code is built to format the data returned by the (look) function as HTML. Functions like p (for paragraph), look-html, and adding image tags are defined and evaluated using inline evaluation to improve the game display.
  • Using Inline Evaluation as a Development and Exploration Tool: Several game interaction functions are evaluated using inline evaluation to explore the text adventure. Suggestions are also given to enhance the user interface.
  • Final Thoughts: Inline evaluation is a valuable technique that deserves wider adoption. It shows that interactivity is very real and can be applied in professional settings. The author argues that it isn't that Clojure or Lisp is inherently superior, but that inline evaluation is valuable across programming environments.
阅读 9
0 条评论