LESSON 28 OF 52 · CHAPTER 04

Typed Declarations

Type annotations for vector/float/tile/boolean/string

ORIGINAL SOURCE

04-typed-declarations.srp

bind samples: vector = [1.0, 2.0, 3.0];
var total: float = sum(samples);
total += 0.5;
bind grid: tile = tile(samples, 1, 3);
bind ready: boolean = width(grid) == 3;
bind label: string = "typed";
print(label, ready, total);
EXPECTED OUTPUT

stdout

Verified
typed true 6.5

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Type annotations for vector/float/tile/boolean/string

Expected behavior

typed true 6.5

Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.

टाइप एनोटेशन

bind samples: vector, var total: float, bind grid: tile, bind ready: boolean और bind label: string से प्रकार स्पष्ट होते हैं। total में बाद में 0.5 जुड़ता है।

आउटपुट: typed true 6.5।

अभ्यास: width(grid) == 3 बूलियन कैसे बनाता है?

Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.

TRY IT LOCALLY

Verify, then execute

Use the pinned compiler from the course root. Keep any imported _support files next to the source.

scarp verify examples/04-collections/04-typed-declarations.srp scarp exec examples/04-collections/04-typed-declarations.srp

The website does not run code. Read the CLI guide ↗

Pinned compiler: Scarp v0.0.6-alpha.3 · ceff07d9014f. No simulated output.