[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] & Usage and Misc. ?'s



At 20.19 -0500 1998.11.03, Vicki Brown wrote:
>&function is the (old) way to call a named subroutine.  It's no longer
>necessary unless the call would otherwise be ambiguous so we didn't mention
>it.  (That is, foo() is unambiguously a function call, &foo is also
>unambiguous; foo is not unambiguous)

A Tangent Of Sorts.  Given a subroutine:

  sub foo ($) {shift || 1}

Call the subroutine:

  print foo();

Returns:

  # Not enough arguments for main::foo, near "()"
  File 'Untitled'; Line 3
  # Execution of Untitled aborted due to compilation errors.

But:

  print &foo();  # & bypasses prototypes!

Returns:

  1

All this just to say that & does have unique behavior apart from its
required usage when dealing with coderefs.

BTW, the above is part of what Tom Christiansen calls "cryptocontext".
Nathan Torkington has an article in TPJ #9 about it, and discusses why
given this:

  sub f($$);
  @a = (5,9);

These may not do the obvious:

  &f;
  &f();
  f();
  f;
  f(@a);
  f(@a[0,1]);
  f(@a, @a);
  &f(@a);
  &f(@a, @a);
  f(`ls /bin`, `ls /tmp`);
  &f(`ls /bin`, `ls /tmp`);

Scary, eh?  All THIS just to say you might want to stay away from prototypes.


>Next time.  And the errata for now.

Would you like to submit specific errata?  :)

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])