Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re (tilly) 1: Context-Sensitive Subroutine Dispatch

by tilly (Archbishop)
on Dec 16, 2001 at 03:29 UTC ( [id://132270]=note: print w/replies, xml ) Need Help??


in reply to Context-Sensitive Subroutine Dispatch

While I think this is a fun exercise, I would not want to use it. Why? Because what a function does should be similar enough in different contexts that there should be tremendous code duplication. Enough that I would discourage the unnecessary propagation of context, or the rewriting of essentially the same subroutine.

But that philosophical issue aside, if you do put this on CPAN, I strongly suggest doing validation of the passed information. If someone accidentally types lsit instead of list, the import should catch that...

  • Comment on Re (tilly) 1: Context-Sensitive Subroutine Dispatch

Replies are listed 'Best First'.
Re: Re (tilly) 1: Context-Sensitive Subroutine Dispatch
by chromatic (Archbishop) on Dec 16, 2001 at 12:13 UTC
    I see the point you are making, and agree in many cases. On the other hand, I think it's interesting to play with the idea of context-sensitive polymorphism (in a sense). It's not a language feature available outside the core and magic variables, but it's emulatable. As thpfft points out, this idea lends itself to several things. This fills a slightly different niche than Want, though they could certainly be used together. Perhaps version 0.03?

    As a practical matter, I can see where it would be useful to disallow certain (expensive) functions to be called in void context, or to avoid certain operations. Maybe it's just the functional programmer in me. In most cases, it's certainly not necessary. When has that stopped us from doing something interesting?

    The point about verifying parameters is well taken, and I'll definitely add that. Thanks for the comments.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://132270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found