LESSON 38 OF 52 · CHAPTER 05

Constant Expressions

Exported constants, chained imports and a function's default argument

ORIGINAL SOURCE

02-constant-expressions.srp

import "_support/constants.srp" as constants;
pub bind doubled = constants.answer * 2;
print(constants.label, constants.answer, doubled, constants.ready, constants.ratio, constants.adjust());
EXPECTED OUTPUT

stdout

Verified
constant expressions 42 84 true 0.75 42

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Exported constants, chained imports and a function's default argument

Expected behavior

constant expressions 42 84 true 0.75 42

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.

आयातित कॉन्स्टैंट अभिव्यक्ति

_support/constants.srp एक अन्य _support/constant_base.srp को आयात करता है। pub bind answer जैसे नाम दूसरे मॉड्यूल में उपलब्ध होते हैं। ऊपर की फ़ाइल में doubled इसी मान को दोगुना करता है; constants.adjust() डिफ़ॉल्ट आर्गुमेंट वाला फ़ंक्शन है।

आउटपुट: constant expressions 42 84 true 0.75 42।

अभ्यास: answer और doubled के बीच संबंध समझाएँ; pub की भूमिका पहचानें।

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 is the value of doubled when constants.answer is 42?constants.answer का मान 42 होने पर doubled का मान क्या होता है?

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

84 — The exported binding doubled is constants.answer multiplied by 2. With answer = 42, doubled is 84.84 — exported binding doubled में constants.answer को 2 से गुणा किया गया है। 42 × 2 = 84।

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/05-modules/02-constant-expressions.srp scarp exec examples/05-modules/02-constant-expressions.srp

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

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