Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: I love anonymous functions!

by Hanamaki (Chaplain)
on Jun 29, 2004 at 16:39 UTC ( #370541=note: print w/ replies, xml ) Need Help??


in reply to I love anonymous functions!

Did you have a look at function pointers and vectored execution in C? ... Its not the same, but probably a way which gives a similiar feeling and if well done some major speed gain compared to "if" statements etc.


Comment on Re: I love anonymous functions!
Re^2: I love anonymous functions!
by dragonchild (Archbishop) on Jun 29, 2004 at 16:57 UTC
    I am using funcp's, as I said in the original post. The issue is that I want to define those funcp's at runtime. Otherwise, I'm stuck with a kitchen-sink of small functions that have different signatures, which means I'm stuck with one of a few undesirable options:
    1. I create a catchall signature, which is ugly, but manageable
    2. I use void* pointers in my data structure, forcing me to cast all my funcp's. (Would this even work??)
    3. I don't use the same data structure, instead using void* and casting the templated nodes in my array. (Would this even work??)
    4. Use a signature that has varargs in it. But, that's ugly and bypasses a lot of the benefits of using a stronglystatically-typed language. (Would this even work??)

    Nope. Give me funcp's every time.

    Update:Fixed error as per hardburn's reply.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      This is where you mix OO and functional constructs. It's staring you in the face. Do it.

      . . . bypasses a lot of the benefits of using a strongly-typed language

      C is not a strongly-typed langauge. Its type system is only useful for hints to the compiler. There are too many ways to subvert it to be anything more. Further, its type errors are just as likely to be annoyances as they are real problems. Rather, C is statically typed, i.e. its types are determined at compile time. Static != strong.

      Perl is more strongly typed than C is. Perl's scalars and lists are very seperate types, and are not so trivial to convert into each other. In fact, it doesn't make sense for there to be a generalized solution for doing list -> scalar.

      Try OcaML. There's a real type system.

      ----
      send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-09-19 06:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (132 votes), past polls