package a;
sub func {
print 1;
}
package main;
a::->func;
IMO it's enough to have a::func
,a->func
.
a::->func;
looks very strange to me, why Perl supports this kind of strange looking syntax?
To make sure that the function is valid, we need to check whether we get exactly one output for each input, and whether there needs to be any restriction on the domain.
Use the vertical line test to determine whether or not a graph represents a function. If a vertical line is moved across the graph and, at any time, touches the graph at only one point, then the graph is a function. If the vertical line touches the graph at more than one point, then the graph is not a function.
The VALID function determines whether x , a reference to a scalar pictured value, has a value that is valid with respect to its picture specification. The result is a bit string of length one that indicates if the character-string value of x can be edited into the picture declared for x .
Throughout mathematics, we find function notation. Function notation is a way to write functions that is easy to read and understand. Functions have dependent and independent variables, and when we use function notation the independent variable is commonly x, and the dependent variable is F(x).
To quote chromatic's excellent recent blog post on the topic at Modern Perl blog: "To avoid bareword parsing ambiguity."
To illustrate why such syntax is useful, here's an example evolved from your sample:
package a;
our $fh;
use IO::File;
sub s {
return $fh = IO::File->new();
}
package a::s;
sub binmode {
print "BINMODE\n";
}
package main;
a::s->binmode; # does that mean a::s()->binmode ?
# calling sub "s()" from package a;
# and then executing sub "open" of the returned object?
# In other words, equivalent to $obj = a::s(); $obj->binmode();
# Meaning, set the binmode on a newly created IO::File object?
a::s->binmode; # OR, does that mean "a::s"->binmode() ?
# calling sub "binmode()" from package a::s;
# Meaning, print "BINMODE"
a::s::->binmode; # Not ambiguous - we KNOW it's the latter option - print "BINMODE"
a::
is a string literal that produces the string a
. All the same:
a->func() # Only if a doesn't exist as a function.
"a"->func()
'a'->func()
a::->func()
v97->func()
chr(97)->func()
etc
>perl -E"say('a', a, a::, v97, chr(97))"
aaaaa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With