Are there languages ​​other than Perl with default variables?

I recently learned about the default Perl variable$_ . A good related article is here http://perlmaven.com/the-default-variable-of-perl . I find the ability to apply functions to it without specifying an argument fascinating. Are there other programming languages ​​with similar capabilities?

EDIT: Some of the languages ​​listed in the comments are:

Powershell - should be very similar to Perl.

Groovy - has a shared variable iterator it.

Scala - has a variable _as a generic lambda argument.

Lisp - has anaphoric macros.

HyperTalk and AppleScript - see @AmbroseChapel's answer

+4
source share
3

, , . .

, , awk sed grep .. - " ".

.

sed -e 's/fish/paste/g' myfile

myfile .

, , perl - perl sed:

perl -p -e 's/fish/paste/g' myfile

, :

LINE: while ( defined ( $_ = <ARGV> ) ) {
    s/fish/paste/g;
} 
continue { 
    die "-p destination: $!\n" unless print $!;
}

Perl ... . , "" while, for.

, - $_, - , , , .

- perl - - .

, ;

 my $regex = qr/some_pattern/;

 while ( <STDIN> ) {
    print if m/$regex/;
 }

, :

while ( my $line = <STDIN> ) { 
    if ( $line =~ m/some_pattern/ ) { 
        print $line;
     }
}
+7

Scala - $_,

(1, 2, 3) map (_ + 2)

+1

The only thing I know is HyperTalk, the Apple language for the slightly unusual HyperCard development environment, which is iteither default or implicit. You can do something like

get the length of <something>
put it into myVariable

and this kind of programming can also be done in AppleScript, see the keywords "it" and "me" .

+1
source

Source: https://habr.com/ru/post/1599263/


All Articles