Lesson 2: Data and Constants

Beginner

Every wire in Phograph carries a value. This lesson covers the data types you can work with and how to create constant values.

Data types

Phograph is dynamically typed — you don’t declare types in advance. The engine figures out types at runtime. Here are the most common types:

TypeExamplesDescription
Integer0, 42, -7Whole numbers (64-bit signed)
Real3.14, -0.5Floating-point (64-bit double)
String"hello"UTF-8 text
Booleantrue, falseLogical values
List(1 2 3)Ordered collection
NullnullAbsence of a value

There are more (Dict, Data, Date, Object, Error, Enum, External), but these six cover most programs. We’ll meet the others in later lessons.

Constant nodes

A constant node has no input pins and one output pin. It produces a fixed value every time it fires. The value is shown as the node’s label.

42 (integer) "name" (string) true (boolean)

To add a constant: right-click the canvas and choose Constant. Then select the node and edit its value in the Inspector.

No variables Phograph has no local variables. Data exists only as values on wires. If you need a value in two places, connect two wires from the same output pin — fan-out is allowed.

Fan-out: one output, many destinations

An output pin can have multiple wires leaving it. The value is copied to each destination. This is called fan-out.

5 + * log

The constant 5 is delivered to three different nodes simultaneously.

Fan-in is not allowed

An input pin accepts at most one wire. If you need to combine two values, use a primitive like + or concat to merge them first.

The inspect primitive

inspect is like log, but it also passes through its input as output. This lets you see a value without breaking the data flow.

7 val inspect prints "[inspect] 7" val + value 7 continues

Exercise 2.1 — Multiple constants

  1. Create a new project (Cmd+N).
  2. Add a method called main with 0 inputs and 0 outputs.
  3. Add three constant nodes with values 10, 20, and 30.
  4. Add three log nodes and wire each constant to one log.
  5. Run. All three values should print to the console.

Exercise 2.2 — Fan-out

  1. Add a single constant with value "echo".
  2. Wire it to two separate log nodes (two wires from one output pin).
  3. Run. The message should appear twice.

Exercise 2.3 — Inspect a value

  1. Load the Basic Arithmetic example (Cmd+Shift+E).
  2. Insert an inspect node between the + node’s output and the * node’s input. (Delete the existing wire, then wire +inspect*.)
  3. Run. The console should show [inspect] 7 (the intermediate sum) and the final result 14.

Key Concepts