Reputation: 3577
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
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 List
s 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) IValue
s 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