Scala का REPL
Scala REPL एक chat window है जहां आप एक line टाइप करते हैं और तुरंत जवाब मिल जाता है। यह विचारों को आज़माने के लिए एक scratch pad जैसा है, बिना पूरा program लिखे।
In this page:
Syntax
$ 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
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'")
}
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
- REPL में एक multi-line class टाइप करना और हर line के बाद Enter दबाना, जबकि REPL हर input को तुरंत चलाता है जब तक आप
:pasteका उपयोग न करें। - यह उम्मीद करना कि quit करने के बाद REPL variables बने रहेंगे, जबकि वे
:quitके बाद खो जाते हैं। - 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: