C++ and dynamic programming

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Directive

    C++ and dynamic programming

    Does C++ support dynamic programming? I hope I'm using the correct
    term. I want to write code that can dynamically rewrite itself! I want
    to dynamically create functions and call them and etc. If not, are
    there any plans to add support for it in the future? What other
    popular programming languages support dynamic programming? [Email me
    privately for the last question so that people will not complain that
    it's out of context.]

    --The Directive
  • John Carson

    #2
    Re: C++ and dynamic programming

    "The Directive" <the_directive@ hotmail.com> wrote in message
    news:8477bc58.0 401162120.12f49 515@posting.goo gle.com[color=blue]
    > Does C++ support dynamic programming? I hope I'm using the correct
    > term. I want to write code that can dynamically rewrite itself! I want
    > to dynamically create functions and call them and etc. If not, are
    > there any plans to add support for it in the future? What other
    > popular programming languages support dynamic programming? [Email me
    > privately for the last question so that people will not complain that
    > it's out of context.]
    >[/color]

    If you mean does C++ allow you to generate functions on the fly that are
    identical to those produced at compile time, then the answer is no. C++ can,
    however, be used to create an interpreter, i.e., a program that will allow
    you to type in functions at runtime and will store and execute those
    functions. Writing such a program involves some work, however (how much work
    depends on the range of possible functions you wish to support).

    Any function that you might write will be built up from basic operations
    (built in operators like + as well as predefined functions like sin and
    cos). Accordingly, an interpreter basically consists of a pre-written
    all-purpose function that calls basic operations as needed by the function
    that the user specifies at run-time (in the simplest case, it may involve a
    switch statement that executes different operations depending on which
    operation has been specified at run-time). For a simple illustration of how
    this is done, look at the calculator program in Ch 6 (including exercise 20)
    of Stroustrup's TC++PL.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)

    Comment

    • Sharad Kala

      #3
      Re: C++ and dynamic programming


      "John Carson" <donaldquixote@ datafast.net.au > wrote in message
      news:4008d9b5$1 @usenet.per.par adox.net.au...[color=blue]
      > "The Directive" <the_directive@ hotmail.com> wrote in message
      > news:8477bc58.0 401162120.12f49 515@posting.goo gle.com[color=green]
      > > Does C++ support dynamic programming? I hope I'm using the correct
      > > term. I want to write code that can dynamically rewrite itself! I want
      > > to dynamically create functions and call them and etc. If not, are
      > > there any plans to add support for it in the future? What other
      > > popular programming languages support dynamic programming? [Email me
      > > privately for the last question so that people will not complain that
      > > it's out of context.]
      > >[/color]
      >
      > If you mean does C++ allow you to generate functions on the fly that are
      > identical to those produced at compile time, then the answer is no. C++ can,
      > however, be used to create an interpreter, i.e., a program that will allow
      > you to type in functions at runtime and will store and execute those
      > functions. Writing such a program involves some work, however (how much work
      > depends on the range of possible functions you wish to support).
      >[/color]

      Well , C++ can generate class hierarchies on the fly.
      That means you can make the compiler generate it for you.
      This involves using templates.
      Take a look at Andrei Alexandrescu's "Modern C++ design" where he shows in
      chapter 4 how to
      generate linear and scattered class hierarchies at compile time.

      Best wishes,
      Sharad


      Comment

      • Jacques Labuschagne

        #4
        Re: C++ and dynamic programming

        Sharad Kala wrote:[color=blue]
        > Take a look at Andrei Alexandrescu's "Modern C++ design" where he shows in
        > chapter 4 how to
        > generate linear and scattered class hierarchies at compile time.[/color]
        ^^^^^^^^^^^^^^^
        "Compile time" may or may not meet your definition of dynamic
        programming, because it involves a compile/execute/modify-source loop.
        It doesn't happen on what most people consider to be "the fly".

        Jacques.

        Comment

        • Sharad Kala

          #5
          Re: C++ and dynamic programming


          "Jacques Labuschagne" <jacques@clawsh rimp.com> wrote in message
          news:ss5Ob.1765 9$ws.2125216@ne ws02.tsnz.net.. .[color=blue]
          > Sharad Kala wrote:[color=green]
          > > Take a look at Andrei Alexandrescu's "Modern C++ design" where he shows in
          > > chapter 4 how to
          > > generate linear and scattered class hierarchies at compile time.[/color]
          > ^^^^^^^^^^^^^^^
          > "Compile time" may or may not meet your definition of dynamic
          > programming, because it involves a compile/execute/modify-source loop.
          > It doesn't happen on what most people consider to be "the fly".[/color]

          Yes..actually I do agree with you that it isn't exactly what people would say
          dynamic programming.
          In fact it uses static polymorphism.
          My point was that you can make C++ to write code for you. This is unlike virtual
          functions where the branch of execution to be selected
          is dynamic, but the code for execution has already been hand-written by someone.

          Best wishes,
          Sharad


          Comment

          • peter

            #6
            Re: C++ and dynamic programming

            The Directive wrote:[color=blue]
            > Does C++ support dynamic programming? I hope I'm using the correct
            > term. I want to write code that can dynamically rewrite itself! I want
            > to dynamically create functions and call them and etc. If not, are
            > there any plans to add support for it in the future? What other
            > popular programming languages support dynamic programming? [Email me[/color]

            your problem might be resolved using embeddable C/C++ interpreter Ch. It
            allows you to generate C/C++ code source code/functions on the fly and
            be called by your C/C++ binary application, or call back your binary
            C/C++ functions.

            you can take a look at
            http://www.softintegra tion.com/solution/embedded/
            http://www.softintegra tion.com/products/sdk/embedded_ch/

            [color=blue]
            > privately for the last question so that people will not complain that
            > it's out of context.]
            >
            > --The Directive[/color]


            Comment

            Working...