Lesson 14: Local Methods and Eval Nodes

Advanced

Sometimes you need a small piece of logic that doesn’t deserve its own named method. Phograph offers two mechanisms for inline computation: local methods and evaluation nodes.

Local methods

A local method embeds a method body directly inside a node. Instead of calling a named method defined elsewhere, the node contains its own mini-graph. This is useful for one-off transformations that are only needed in one place.

  constant 5 --> [local method] --> log
                   body:
                     input --> * 2 --> + 1 --> output
                   outputs: 11

The local method has its own input and output bars, just like a regular method, but it lives inside the parent method’s canvas.

Evaluation nodes

An eval node lets you write a single inline expression instead of building a subgraph. The expression uses a simple syntax with named inputs.

  constant 3 --> [eval: a + b * 2] <-- constant 4
                  outputs: 11       (b * 2 = 8, a + 8 = 11)

Expression syntax

Eval nodes support the following operators and constructs:

  eval: score >= 60 ? "pass" : "fail"
  eval: (a + b) / 2
  eval: !is_empty && count > 0

Inject nodes

An inject node performs dynamic dispatch — it calls a method whose name is provided at runtime as a string input. This is useful when the operation to perform is determined by data rather than wired statically.

  constant "add" --> [inject] <-- constant 3
                                  <-- constant 4
                      outputs: 7

  constant "multiply" --> [inject] <-- constant 3
                                       <-- constant 4
                           outputs: 12

The first input is the method name; the remaining inputs are passed as arguments. The runtime looks up the method and calls it.

What you learned