← Back to Scala Course | Chapter 1: Setup & Basics | Lesson 3 of 8

Scala का REPL

Scala REPL एक chat window है जहां आप एक line टाइप करते हैं और तुरंत जवाब मिल जाता है। यह विचारों को आज़माने के लिए एक scratch pad जैसा है, बिना पूरा program लिखे।

In this page:

  1. The Scala REPL
Syntax
scala
$ scala
scala> expression

The Scala REPL

Scala REPL (Read-Eval-Print Loop), जिसे बिना किसी arguments के scala टाइप करके शुरू किया जाता है, आपको expressions टाइप करने और तुरंत results देखने देता है, हर एक पर उसके inferred type का annotation होता है।

पूरा program लिखने से पहले छोटे snippets के साथ experiment करने का यह सबसे तेज़ तरीका है। आपके द्वारा दर्ज किया गया हर top-level expression अपने आप evaluate और print हो जाता है।

Note: Scala REPL से बाहर निकलने के लिए :quit टाइप करें (या Ctrl+D दबाएं)।

उदाहरण: The Scala REPL

markup
object Main extends App {
  // Simulating what you'd see typing directly into the REPL:
  val result = 2 + 2
  println(s"2 + 2 = $result")
  println("In the REPL, typing '2 + 2' alone would print 'val res0: Int = 4'")
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. REPL में एक multi-line class टाइप करना और हर line के बाद Enter दबाना, जबकि REPL हर input को तुरंत चलाता है जब तक आप :paste का उपयोग न करें।
  2. यह उम्मीद करना कि quit करने के बाद REPL variables बने रहेंगे, जबकि वे :quit के बाद खो जाते हैं।
  3. REPL के लिए scala और file चलाने के लिए scala file.scala को लेकर confuse होना, और REPL prompt देखकर हैरान होना।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.