develooper Front page | perl.perl5.porters | Postings from February 2003

Re: [perl #20463] I want prototype() to modify the prototype of a function

Thread Previous | Thread Next
From:
hv
Date:
February 10, 2003 17:58
Subject:
Re: [perl #20463] I want prototype() to modify the prototype of a function
Message ID:
200302110156.h1B1uVv17883@crypt.compulink.co.uk
Mark-Jason Dominus (via RT) <perlbug-followup@perl.org> wrote:
:The currnt prototype() builtin function returns the prototype of some
:other function.  For example
:
:        sub bleh ($) { return $_[0] }
:        print prototype('bleh');
:
:This prints '$'.
:
:But there is no convenient way to modify the prototype of an existing
:function.
[...]
:It seems to me that allowing
:
:        prototype(FUNCTION, '$$;$')
:
:would be straightforward and would not break any old code.  

I think the need for this is pretty rare, so it may be that Rafael's
suggested Inline/C code is sufficient.

Note that you can currently write this, which we should maybe class as
a bug:
  crypt% perl -wle 'sub a ($) { 1 } print prototype(1, \&a)'
  $
  crypt% 
.. though at least prototype(\&a, '$$;$') would give a:
  Useless use of reference constructor in void context
.. and return undef.

I worry also what happens to code calling the function that got
compiled before the prototype changed. Not sure if they would cause
problems.

If we were to consider changing the meaning of core prototype(),
we should maybe also consider allowing this usage only when
C< no strict 'prototypes' >.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About