What programming languages ​​will allow me to manipulate the sequence of instructions in a method?

I have an upcoming project in which the main requirement will be to change the way the method works at run time. Please note that I am not talking about a higher level OO concept, such as the “shadow method with another”, although the practical effect will be similar.

The key properties that I use are the following:

  • I should be able to modify the method so that I can add new expressions, delete existing expressions or modify any expressions that occur in it.

  • After changing the method, subsequent calls to this method will invoke a new sequence of operations. (Or, if the language binds methods rather than evaluating each time, provide me with a way to undo / undo a new method.)

  • Ideally, I would like to manipulate the atomic units of the language (for example, "invoke method fooon object bar"), and not the assembly directly (for example, "push these three parameters on the stack"). In other words, I would like to have high confidence that the operations I perform are semantically significant in the language. But I will take what I can get.

If you are not sure whether the candidate’s language meets the specified criteria, perform a simple litmus test:

Can you write another method called cleanthat:

  • accepts a method mas input

  • m2, , m

  • m2 m, print-to-standard-out (puts, System.Console.WriteLn, println ...)?

, . , , , . , - , - , .

? , , , ?


: , , , , . , , . (, .))

+3
5

, .NET Expression . , , , , ..

+1

, ( , Lisps) .

, ? , , , , . , ( - , , , ).

+1

, Groovy .

class Foo {
   void bar() {
      println "foobar"
   }
}

Foo.metaClass.bar = {->
    prinltn "barfoo"
}

foo

fooInstance.metaClass.bar = {->
    println "instance barfoo"
}

, , , . Groovy metaClass.

+1

java - java- , ASM.

BCEL .

0

/, - , Common Lisp, Smalltalk, Forth. , , . , ( ) OO .

0

Source: https://habr.com/ru/post/1791246/


All Articles