Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Why does eof have a prototype?

by LanX (Sage)
on Aug 07, 2022 at 20:21 UTC ( #11146005=note: print w/replies, xml ) Need Help??


in reply to Re: Why does eof have a prototype?
in thread Why does eof have a prototype?

> IMHO the first sentence doesn't apply here because eof's syntax can be expressed by a prototype

Depends how you define "syntax can be expressed by a prototype".

A "can be parsed without errors" criteria is not enough for me.

eof(); and eof; are (magically) different syntax for eof, and this difference can't be expressed with prototypes.

In the past the prototype symbol set was extended with *, + or _ in order to add prototypes to other built-ins.

This criteria isn't met here.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Why does eof have a prototype?
by haukex (Archbishop) on Aug 07, 2022 at 21:33 UTC
    eof(); and eof; are (magically) different syntax for eof, and this difference can't be expressed with prototypes.

    I'm not sure this is a job for prototypes. Every Perl function can be called with and without parens (given the compiler knows about it), it's always valid syntax. The trick would be to detect inside a hypothetical sub myeof whether the parens are there are not - how would one do this with prototypes? Seems more like a job for something like caller. It's also worth noting that AFAIK eof is the only function in Perl that behaves this way... the exception that confirms the rule ;-)

    Interesting side note: see eof in perltie.

    A "can be parsed without errors" criteria is not enough for me.

    I don't think that's the criteria. It's more like: "Every variation of the builtin's syntax can be expressed by prototypes" - look at threads like Prototype like sort()? where everyone's implementations got close to the original, but noone was able to replicate all of sort's syntax. All of eof's syntax can be replicated, but not its functionality. That's where the difference is.

    I do understand how you are interpreting that piece of documentation, but I think you should cut the authors some slack :-) eof is a unique case, and knowing this, I don't think that passage is inaccurate.

      > It's also worth noting that AFAIK eof is the only function in Perl that behaves this way... the exception that confirms the rule ;-)

      well yes, each magic exception is different, look at chop (LIST) , which has no prototype.

      > look at threads like Prototype like sort()?

      But sort has no prototype, that's my point.

      > All of eof's syntax can be replicated, but not its functionality.

      well your link to tie made me thinking ...

      I remember that overriding say or print was only possible by tieing the connected file-handles, so maybe eof IS fully overridable in the end, thanks to that extra magic.

      I'll try tomorrow.

      > but I think you should cut the authors some slack :-)

      One of the reasons why Perl is now so unpopular in academia are surprising and frustrating exceptions. Clarifying and rectifying such things would help to make Perl more orthogonal and acceptable.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2023-02-07 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?