LESSON 26 OF 52 · CHAPTER 04

Vector Windows

Selecting and combining numeric windows

ORIGINAL SOURCE

02-vector-windows.srp

// Zero-copy selection and checked re-materialization from visible ranges.
bind values = [10.0, 20.0, 30.0, 40.0];
bind middle = window(values, 1, 2);
print(middle);
print(stitch(middle, [50.0]));
print(window(middle, 2, 0));
EXPECTED OUTPUT

stdout

Verified
[20.0, 30.0]
[20.0, 30.0, 50.0]
[]

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Selecting and combining numeric windows

Expected behavior

[20.0, 30.0], [20.0, 30.0, 50.0], []

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.

वेक्टर विंडो

window(values, 1, 2) दूसरे स्थान से दो मान चुनता है। stitch उसके साथ नया वेक्टर जोड़ता है। शून्य लंबाई की विंडो खाली है।

आउटपुट: [20.0, 30.0], फिर [20.0, 30.0, 50.0], फिर []।

अभ्यास: विंडो में 10.0 क्यों नहीं आया?

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

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

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

Which values are printed for window(values, 1, 2)?window(values, 1, 2) के लिए कौन-से मान प्रिंट होते हैं?

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

[20.0, 30.0] — Starting at index 1 selects the second and third values of [10.0, 20.0, 30.0, 40.0].[20.0, 30.0] — index 1 से शुरू करने पर [10.0, 20.0, 30.0, 40.0] में दूसरे और तीसरे मान चुने जाते हैं।

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/02-vector-windows.srp scarp exec examples/04-collections/02-vector-windows.srp

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

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