Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: I love anonymous functions!

by Hanamaki (Chaplain)
on Jun 29, 2004 at 16:39 UTC ( [id://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.

Replies are listed 'Best First'.
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

      . . . 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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-23 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found