Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • how are callbacks different from first class functions?
    or are they exactly the same thing?
    • by xsawyerx (8978) on 2009.01.13 10:36 (#66816) Journal
      I haven't heard the expression first class functions till now. From what I checked on Wikipedia, it seems like the exact same thing.

      You store code to be run in a data structure and execute it only when accessing that data structure.
      That data structure could be any variable (as an item in a list, as a scalar or as the entry inside a rather elaborate hash structure) and the code you're storing is strictly not code, but a reference to code. When it's accessed, it executes the code in that reference.

      For example, consider the following:

      my $code_ref = sub { print "hi\n"; };
      print "My code reference is $code_ref\n"
      . "But when I execute it, it says ";
      $code_ref->(); # possible variables too