LESSON 40 OF 52 · CHAPTER 05

Public Private Api

Exported function calls an internal helper without exporting it

ORIGINAL SOURCE

04-public-private-api.srp

import "_support/inspection.srp" as tools;
print(tools.label, tools.adjusted(39));
EXPECTED OUTPUT

stdout

Verified
module tools 42

UNDERSTAND THE CODE

Explanation & practice

What this example teaches

Exported function calls an internal helper without exporting it

Expected behavior

module tools 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.

public और private कोड का अंतर

_support/inspection.srp मॉड्यूल में pub से उपलब्ध label और adjusted फ़ंक्शन हैं, लेकिन helper तथा offset केवल मॉड्यूल के भीतर उपयोग किए जाते हैं। adjusted(39) के भीतर 1 और डिफ़ॉल्ट step = 2 जोड़ने से 42 आता है। दूसरे मॉड्यूल से private नाम को सीधे उपयोग करने की अनुमति नहीं मिलती।

आउटपुट: module tools 42।

अभ्यास: adjusted सार्वजनिक होने पर भी helper को निजी क्यों रखा जा सकता है?

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/05-modules/04-public-private-api.srp scarp exec examples/05-modules/04-public-private-api.srp

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

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