Thread: Lambda functions in C?

  1. #1
    Registered User
    Join Date
    Aug 2009

    Lambda functions in C?

    I need to be able to pass in mathematical equations to a program, have the program parse them, and use those equations as lambda/anonymous functions. I know higher level languages are able to do this, but I would prefer the lowest level language due to the computational intensity of this algorithm.

    Just as an example:

    intialize x, y, z
    y = 2
    z = 3
    lambda function here (parse string parameter)
    print x
    where if 'x = y + z' as passed as a parameter, it would print 5, and if 'x = y + 2*z' was passed as a parameter, it would print 8

    If this isn't possible in C, what's the next fastest language that is able to implement this?
    Last edited by black0ut; 08-12-2009 at 11:57 AM.

  2. #2
    Registered User
    Join Date
    Jun 2009
    That's not going to be pretty in C - you'll have to pass your equations as string, and write some code to parse them using strtok().

  3. #3
    Registered User
    Join Date
    Apr 2006
    You're best off using a scripting language. Without one, you'd basically be wrting a mini scripting language parser yourself anyway.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM