[Pdx-pm] Module downloads and brainstorming request

Ovid curtis_ovid_poe at yahoo.com
Thu Dec 11 11:12:29 CST 2003

As promised, here's where you can download the two modules that I
discussed at the meeting:


The first module, AI::NeuralNet::Simple, will probably go to the CPAN
as soon as I provide methods for a couple of its hard-coded properties.
 It's still usable though, and has a nifty example where you tell your
little AI character how healthy it is, what weapons it has, how many
enemies it sees and it will tell you what its response is (currently
limited to attack, run, hide, and wander).

It's called "simple" because it's a basic neural network with docs
aimed at people who have never used a neural network before.  (note: 
it requires Inline::C)

The second module, Sub::Attributes, will be renamed at some point. 
Suggestions welcome.  It allows you to assign attributes to subroutines
that alter their behavior depending upon the context in which they are
called.  All subroutines are expected to return an array or list, but
if you call them in scalar or void context, their behavior alters.  For
example, if you want to return an array, but return an array ref in
scalar context and die if called in void context, you might add the
following to the end of your subroutine:

  if (wantarray) {
    return @results;
  elsif (defined wantarray) {
    return \@results;
  die "Do not call me in void context!";

That's a lot of unecessary typing and it would be annoying to code that
for every subroutine.  With Sub::Attributes, you can just type this:

  sub do_stuph : Arrayref(NOVOID) { ... }

What if you wanted to create a param() method that functions like
CGI::param? (i.e., in scalar context it only returns the first item in
the array)

  sub param : First { ... }

You can also make that fatal if you specify NOVOID (I'll also add a
"WARN_VOID" function so that you get a "Useless use of *** in void
context" warning.

There are other attributes available for this, but I think you get the
idea.  Currently, there are a couple of things that I need before I
publish this to the CPAN.  If you have attributes that you would like
added (throwing exceptions if called in scalar context?), let me know. 
I also need a better name.  Attribute::Context or List::Context are two

I've also wondered if I should expand this to affect contexts outside
of subroutines.  The attribute would explain what happens when accessed
in list context and the argument to the attribute would be the behavior
when accessed in scalar context.

  my @array = qw(foo bar baz);
  my $arrayref : Expand(Count) = \@array;

  print $arrayref->[1];      # prints 'bar'
  my @new_array = $arrayref; # @new_array = qw(foo bar baz)
  my $count     = $arrayref; # $count == 3

I think this is a phenomenally bad idea, but I do wonder if there is
something interesting to be discovered here.


Silence is Evil            http://users.easystreet.com/ovid/philosophy/indexdecency.htm
Ovid                       http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/

More information about the Pdx-pm-list mailing list