On Nov 13, 2005, at 11:07 PM, joel wrote:

So, if one were implementing, say, FORTH, in Perl, intending to allow the user to compile subroutines of her own, can it be done with dispatch tables? Can you add entries to dispatch tables at run- time?

Sure - compiling code at run-time is what string eval() is for.

You could compile an anonymous sub to get a code ref:

  my $coderef = eval "sub { $string_full_of_code }";

You could then store the coderef in a dispatch table:

  $dispatch_table{$function_name} = $coderef;

Or, you could add it directly to Perl's symbol table:

  no strict 'refs';
  *{ $package.'::'.$function_name } = $coderef;

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Reply via email to