I have been curious about dynamic languages, but I have never officially used dynamic features of dynamic languages. The most commonly used method is to use JavaScript as an imperative language to operate HTML Dom.
Today I saw a video about ironpython. I was shocked by the powerful dynamic language features. You can add methods/attributes or replace methods to a class at runtime.
The following is a command script that can be used in the ironpython console.
>>> Def Foo (Self): "" defines a method.
... Print 1
...
>>> Class ctest: "defines a class
... Def bar (Self ):
... Print 2
...
>>> T1 = ctest () "creates an instance of a class.
>>> T1.bar ()"""
2
>>> Ctest. Foo = foo "" adds a dynamic method for the class.
>>> T1.foo ()
1
>>> Def func1 (Self ):
... Self. Bar ()
...
>>> Ctest. func1 = func1
>>> T1.func1 ()
2
>>> T1.func1 ()
2
>>> T1.a = 1 "dynamically adds an attribute to an object.
>>> Def func2 (Self ):
... Print self.
...
>>> Ctest. func2 = func2
>>> T1.func2 ()
1
>>>