Dynamic Programming Language
Dynamic Programming Language
This article has multiple issues. Please help improve it or discuss these issues on the talk
page. (Learn how and when to remove these template messages)
This article needs attention from an expert in Computing. (January 2015)
This article's factual accuracy is disputed. (March 2012)
This article may be confusing or unclear to readers. (October 2009)
Programming paradigms
Action
Agent-oriented
Array-oriented
Automata-based
Concurrent computing
o Relativistic programming
Data-driven
Declarative (contrast: Imperative)
o Functional
Functional logic
Purely functional
o Logic
Abductive logic
Answer set
Concurrent logic
Functional logic
Inductive logic
o Constraint
Constraint logic
Concurrent constraint logic
o Dataflow
Flow-based
Reactive
Functional reactive
o Ontology
Differentiable
Dynamic/scripting
Event-driven
Function-level (contrast: Value-level)
o Point-free style
Concatenative
Generic
Imperative (contrast: Declarative)
o Procedural
o Object-oriented
Polymorphic
Intentional
Language-oriented
o Domain-specific
Literate
Natural-language programming
Metaprogramming
o Automatic
Inductive programming
o Reflective
Attribute-oriented
o Macro
o Template
Non-structured (contrast: Structured)
o Array
Nondeterministic
Parallel computing
o Process-oriented
Probabilistic
Quantum
Set-theoretic
Stack-based
Structured (contrast: Non-structured)
o Block-structured
Structured concurrency
o Object-oriented
Actor-based
Class-based
Concurrent
Prototype-based
By separation of concerns:
Aspect-oriented
Role-oriented
Subject-oriented
o Recursive
Symbolic
Value-level (contrast: Function-level)
v
t
e
Most dynamic languages are also dynamically typed, but not all are. Dynamic languages are
frequently (but not always) referred to as scripting languages, although that term in its
narrowest sense refers to languages specific to a given run-time environment.
Contents
1 Implementation
o 1.1 Eval
o 1.2 Object runtime alteration
o 1.3 Reflection
o 1.4 Macros
2 Example code
o 2.1 Computation of code at runtime and late binding
o 2.2 Object runtime alteration
o 2.3 Assembling of code at runtime based on the class of instances
3 Examples
4 See also
5 References
6 Further reading
7 External links
Implementation
This section needs expansion. You can help by adding to it. (October 2009)
Eval
Some dynamic languages offer an eval function. This function takes a string parameter
containing code in the language and executes it. If this code stands for an expression, the
resulting value is returned. However, Erik Meijer and Peter Drayton suggests that
programmers "use eval as a poor man's substitute for higher-order functions."[1]
A type or object system can typically be modified during runtime in a dynamic language.
This can mean generating new objects from a runtime definition or based on mixins of
existing types or objects. This can also refer to changing the inheritance or type tree, and thus
altering the way that existing types behave (especially with respect to the invocation of
methods).
Reflection
Reflection is common in many dynamic languages, and typically involves analysis of the
types and metadata of generic or polymorphic data. It can, however, also include full
evaluation and modification of a program's code as data, such as the features that Lisp
provides in analyzing S-expressions.
Macros
A limited number of dynamic programming languages provide features which combine code
introspection (the ability to examine classes, functions, and keywords to know what they are,
what they do and what they know) and eval in a feature called macros. Most programmers
today who are aware of the term macro have encountered them in C or C++, where they are a
static feature which is built in a small subset of the language, and are capable only of string
substitutions on the text of the program. In dynamic languages, however, they provide access
to the inner workings of the compiler, and full access to the interpreter, virtual machine, or
runtime, allowing the definition of language-like constructs which can optimize code or
modify the syntax or grammar of the language.
Assembly, C, C++, early Java, and Fortran do not generally fit into this category.[clarification needed]
Example code
The following examples show dynamic features using the language Common Lisp and its
Common Lisp Object System (CLOS).
The example shows how a function can be modified at runtime from computed source code
; a function is created from the code and compiled at runtime, the function
is available under the name best-guess
CL-USER > (compile 'best-guess *best-guess-formula*)
#<Function 15 40600152F4>
; the next call will call the new function, a feature of late binding
CL-USER > (best-guess 10.3)
16.28573
This example shows how an existing instance can be changed to include a new slot when its
class changes and that an existing method can be replaced with a new version.
; the class person gets a second slot. It then has the slots name and age.
CL-USER > (defclass person () ((name :initarg :name) (age :initarg :age
:initform :unknown)))
#<STANDARD-CLASS PERSON 4220333E23>
; the existing object has now changed, it has an additional slot and a new
print method
CL-USER > *person-1*
#<PERSON Eva Luator age: UNKNOWN>
In the next example, the class person gets a new superclass. The print method gets redefined
such that it assembles several methods into the effective method. The effective method gets
assembled based on the class of the argument and the at runtime available and applicable
methods.
; a person instance
CL-USER > (defparameter *person-1* (make-instance 'person :name "Eva
Luator"))
*PERSON-1*
; the existing instance *person-1* now has a new slot and we set it to 42
CL-USER 242 > (setf (slot-value *person-1* 'id) 42)
42
Examples
Popular dynamic programming languages include JavaScript, Python, Ruby, PHP, Lua and
Perl. The following are generally considered dynamic languages:
ActionScript
BeanShell[2]
C# (using Reflection)
Clojure
CobolScript
ColdFusion Markup Language
Common Lisp and most other Lisps
Dylan
E
Elixir
Erlang
FORTH
Gambas
GDScript
Groovy[3]
Java (using Reflection)
JavaScript
Julia
Lua
MATLAB / Octave
Objective-C
Perl
PHP
PowerShell
Prolog
Python
R
Raku
Rebol
Ruby
Smalltalk
SuperCollider
Tcl
VBScript
Wolfram Language
See also
Comparison of programming languages
Name binding
Von Neumann architecture