Alexander Serebrenik
Alexander Serebrenik

Reputation: 3577

Using foreign language APIs in Rascal?

Is there a way to invoke a foreign language API in Rascal? In particular, I've been thinking about the Stanford Core NLP that has a Java API.

Upvotes: 2

Views: 92

Answers (1)

Paul Klint
Paul Klint

Reputation: 1406

Rascal has an excellent Java API. Essentially, a foreign function is defined as an ordinary Rascal function prefixed with the keyword java and an attribute javaClass that defines the class where the function is implemented.

Take the size function on Lists as an example. In Rascal's List module size is defined as follows:

@javaClass{org.rascalmpl.library.Prelude}
public java int size(list[&T] lst);

In the java class org.rascalmpl.library.Prelude, the method size is implemented like this:

public IValue size(IList lst)
{
   return values.integer(lst.length());
}

Note that all Rascal values are implemented as (immutable) IValues and that some marshaling is unavoidable.

Final note: interfacing with an NLP library is very interesting (and is actually on our bucket list) but be aware to preserve Rascal's spirit of immutable data and mostly functional solutions. This has to be taken into account when designing the Rascal API for such a library.

Upvotes: 2

Related Questions