Beginner
Primitives are built-in operations provided by the Phograph runtime. They cover arithmetic, comparison, logic, string manipulation, and more. This lesson focuses on the arithmetic and comparison primitives.
| Primitive | Inputs | Output | Description |
|---|---|---|---|
+ | a, b | a + b | Addition |
- | a, b | a - b | Subtraction |
* | a, b | a * b | Multiplication |
/ | a, b | a / b | Division |
mod | a, b | a mod b | Modulo (remainder) |
abs | a | |a| | Absolute value |
round | a | round(a) | Round to nearest integer |
Load the Basic Arithmetic example. It computes (3 + 4) * 2 = 14.
3, 4, and 2 fire immediately.+ receives both inputs (3 and 4), fires, outputs 7.* receives 7 from + and 2 from the constant, fires, outputs 14.14 flows to the output bar.
Notice that the constant 2 fired at the same time as 3 and
4. It didn’t need to wait — it has no inputs. The
* node waited for both its inputs before firing. This is the
data-driven firing rule.
| Primitive | Inputs | Output | Description |
|---|---|---|---|
= | a, b | Boolean | Equal |
!= | a, b | Boolean | Not equal |
< | a, b | Boolean | Less than |
> | a, b | Boolean | Greater than |
<= | a, b | Boolean | Less than or equal |
>= | a, b | Boolean | Greater than or equal |
Comparisons output true or false. They are essential for
control flow, which we’ll cover in Lesson 5.
| Primitive | Inputs | Output | Description |
|---|---|---|---|
and | a, b | Boolean | Both must be true |
or | a, b | Boolean | Either can be true |
not | a | Boolean | Invert |
Build a method that converts Fahrenheit to Celsius: C = (F - 32) * 5 / 9
main with 0 inputs and 1 output.212 (boiling point of water in °F).32.- primitive: 212 - 32 = 180.5 and 9. Wire them with * and / to complete the formula.100.Compute the area of a circle with radius 7: A = pi * r * r.
7 for the radius.3.14159 for pi.* nodes to compute r * r then pi * r^2.inspect node (so it prints and passes through).153.938 in the console.Use fan-out from the radius constant — connect two wires from
its output to both inputs of the first * node.
17.mod with constant 2 to get the remainder.= with constant 0 to check if the remainder is zero.log.[log] false (17 is odd).42 and run again — should be true.inspect to see intermediate values during development.