Topic variable: Difference between revisions

Scala solution added
m (→‎{{header|Perl 6}}: fix markup)
(Scala solution added)
Line 586:
The style of programming using $_ as an implicit parameter is gradually losing favor in the Ruby community.
 
=={{header|Scala}}==
<lang scala>object TopicVar extends App {
class SuperString(val org: String){
def it(): Unit = println(org)
}
 
new SuperString("ggggg"){it()}
new SuperString("ggggg"){println(org)}
 
Seq(1).foreach {println}
Seq(2).foreach {println(_)}
Seq(4).foreach { it => println(it)}
Seq(8).foreach { it => println(it + it)}
}</lang>
=={{header|Sidef}}==
The underscore (''_'') topic variable is defined at compile-time in every block of a program. To call a method on it, we can just use the prefix dot (''.'') operator, followed by a method name, which is equivalent with ''_.method_name''
Anonymous user