LESSON 27 OF 52 · CHAPTER 04

Integer Collections

Explicit integers values and integer window helpers

ORIGINAL SOURCE

03-integer-collections.srp

bind values: integers = ints_range(1, 5, 1);
bind window = ints_window(values, 1, 3);
bind changed = ints_set(values, 0, 9);
var total: integer = 0;
repeat ints_len(window) as index {
    total += window[index];
}
print(values, changed, window, total);
print(ints_to_vector(window), ints_join([integer: 6], [integer: 7]));
EXPECTED OUTPUT

stdout

Verified
[integer: 1, 2, 3, 4, 5] [integer: 9, 2, 3, 4, 5] [integer: 2, 3, 4] 9
[2.0, 3.0, 4.0] [integer: 6, 7]

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Explicit integers values and integer window helpers

Expected behavior

Printed windows, replacements and totals

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.

पूर्णांक कलेक्शन

integers पूर्णांकों का विशेष क्रम है। ints_range, ints_window, ints_set, ints_len, ints_to_vector तथा ints_join के साथ अलग-अलग गणनाएँ होती हैं। repeat से विंडो का योग निकाला गया है।

आउटपुट: values में 1–5, बदले हुए क्रम में पहला मान 9, और विंडो का योग 9 है।

अभ्यास: ints_set नया क्रम देता है या मूल बाइंडिंग को बदलता है?

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

SOURCE-BACKED SELF-CHECK · स्रोत-आधारित अभ्यास

Quick checkpoint / त्वरित अभ्यास

What total is produced by summing the integer window [2, 3, 4]?integer window [2, 3, 4] का योग कितना होता है?

Reveal the source-backed answer / सही उत्तर देखें

9 — ints_window selects 2, 3 and 4, and the repeat loop adds these three integers to obtain 9.9 — ints_window से 2, 3 और 4 चुने जाते हैं। repeat लूप इन्हें जोड़कर 9 प्राप्त करता है।

This question checks understanding of a recorded compiler output. It does not run Scarp in the browser. यह प्रश्न सत्यापित आउटपुट पर आधारित है; ब्राउज़र में Scarp नहीं चलता।

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/03-integer-collections.srp scarp exec examples/04-collections/03-integer-collections.srp

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

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