MVEL

MVEL
DevelopersMike Brock and Various Contributors
Stable release
2.3.0 / June 15, 2016 (2016-06-15)
Written inJava
Operating systemCross-platform
TypeExpression Language (EL)
LicenseApache License
Websitegithub.com/mvel/mvel
Repository

MVFLEX Expression Language (MVEL) is a hybrid dynamic/statically typed, embeddable Expression Language and runtime for the Java Platform. Originally started as a utility language for an application framework, the project is now developed completely independently.

MVEL is typically used for exposing basic logic to end-users and programmers through configuration such as XML files or annotations. It may also be used to parse simple JavaBean expressions.

The runtime allows MVEL expressions to be executed either interpretively, or through a pre-compilation process with support for runtime bytecode generation to remove overhead.

Since MVEL is meant to augment Java-based software, it borrows most of its syntax directly from the Java programming language with some minor differences and additional capabilities. For example: as a side effect of MVEL's typing model, which treats class and method references as regular variables, it is possible to use both class and function pointers (but only for static methods).

millis = System.currentTimeMillis;

// Get milliseconds
time = millis();

MVEL also allows collections to be represented as folds (or projections) in a Lisp-like syntax.

namesOfParents = (parent.name in (children in employees));

Hello world example

System.out.println("Hello, world!");

MVEL relies on Java namespaces and classes, but does not possess the ability to declare namespaces or classes.

Quicksort example

Here is an example of the Quicksort algorithm implemented in MVEL 2.0, demonstrating the scripting capabilities of the language.

import java.util.*;

// The main quicksort algorithm
def quicksort(list) {
    if (list.size() <= 1) {
         list;
    }
    else {
         pivot = list[0];
         concat(quicksort(($ in list if $ < pivot)), pivot, quicksort(($ in list if $ > pivot)));
    }
}

// Define method to concatenate lists.
def concat(list1, pivot, list2) {
    concatList = new ArrayList(list1);
    concatList.add(pivot);
    concatList.addAll(list2);
    concatList;
}

// Create a list to sort
list = [5,2,4,1,18,10,15,1,0];

// Sort it!
quicksort(list);

See also


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.