@@ -136,7 +136,7 @@ object LexicalScopes extends ScalaTutorialSection {
136136 * There are two ways to overcome this problem.
137137 *
138138 * You could write the multi-line expression in parentheses, because semicolons
139- * are never inserted inside `(... )`:
139+ * are never inserted inside `(… )`:
140140 *
141141 * {{{
142142 * (someLongExpression
@@ -151,20 +151,78 @@ object LexicalScopes extends ScalaTutorialSection {
151151 * someOtherExpression
152152 * }}}
153153 *
154- * = Summary =
154+ * = Top-Level Definitions =
155155 *
156- * You have seen simple elements of functional programing in Scala.
156+ * In real Scala programs, `def` and `val` definitions must be written
157+ * within a top-level ''object definition'', in .scala file:
157158 *
158- * - arithmetic and boolean expressions
159- * - conditional expressions if-else
160- * - functions with recursion
161- * - nesting and lexical scope
159+ * {{{
160+ * object MyExecutableProgram {
161+ * val myVal = …
162+ * def myMethod = …
163+ * }
164+ * }}}
165+ *
166+ * The above code defines an ''object'' named `MyExecutableProgram`. You
167+ * can refer to its ''members'' using the usual dot notation:
168+ *
169+ * {{{
170+ * MyExecutableProgram.myMethod
171+ * }}}
172+ *
173+ * The definition of `MyExecutableProgram` is ''top-level'' because it
174+ * is not nested within another definition.
162175 *
163- * You have learned the difference between the call-by-name and
164- * call-by-value evaluation strategies.
176+ * = Packages and Imports =
177+ *
178+ * Top-level definitions can be organized in ''packages'':
179+ *
180+ * {{{
181+ * // file foo/Bar.scala
182+ * package foo
183+ * object Bar { … }
184+ * }}}
185+ *
186+ * {{{
187+ * // file foo/Baz.scala
188+ * package foo
189+ * object Baz { … }
190+ * }}}
165191 *
166- * You have learned a way to reason about program execution: reduce expressions using
167- * the substitution model.
192+ * Definitions located in a package are visible from other definitions
193+ * located in the same package:
194+ *
195+ * {{{
196+ * // file foo/Baz.scala
197+ * package foo
198+ * object Baz {
199+ * // Bar is visible because it is in the `foo` package too
200+ * Bar.someMethod
201+ * }
202+ * }}}
203+ *
204+ * On the other hand, definitions located in other packages are not directly
205+ * visible: you must use ''fully qualified names'' to refer to them:
206+ *
207+ * {{{
208+ * // file quux/Quux.scala
209+ * package quux
210+ * object Quux {
211+ * foo.Bar.someMethod
212+ * }
213+ * }}}
214+ *
215+ * Finally, you can import names to avoid repeating their fully qualified form:
216+ *
217+ * {{{
218+ * // file quux/Quux.scala
219+ * package quux
220+ * import foo.Bar
221+ * object Quux {
222+ * // Bar refers to the imported `foo.Bar`
223+ * Bar.someMethod
224+ * }
225+ * }}}
168226 */
169227 def nothing (): Unit = ()
170228}
0 commit comments