summaryrefslogtreecommitdiff
path: root/src/runtime/java/org/grammaticalframework
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/java/org/grammaticalframework')
-rw-r--r--src/runtime/java/org/grammaticalframework/pgf/Expr.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/runtime/java/org/grammaticalframework/pgf/Expr.java b/src/runtime/java/org/grammaticalframework/pgf/Expr.java
index 0195f8019..6541db140 100644
--- a/src/runtime/java/org/grammaticalframework/pgf/Expr.java
+++ b/src/runtime/java/org/grammaticalframework/pgf/Expr.java
@@ -44,10 +44,31 @@ public class Expr implements Serializable {
}
this.pool = new Pool();
- this.master = Arrays.copyOf(args, args.length);
+ this.master = args;
this.ref = initApp(fun, args, pool.ref);
}
+ /** Constructs an expression which is an application
+ * of the first expression to a list of arguments.
+ */
+ public static Expr apply(Expr fun, Expr... args) {
+ if (fun == null)
+ throw new IllegalArgumentException("fun == null");
+ for (int i = 0; i < args.length; i++) {
+ if (args[i] == null)
+ throw new IllegalArgumentException("the "+(i+1)+"th argument is null");
+ }
+
+ Object[] master = new Object[args.length+1];
+ master[0] = fun;
+ for (int i = 0; i < args.length; i++) {
+ master[i+1] = args[i].master;
+ }
+
+ Pool pool = new Pool();
+ return new Expr(pool, master, initApp(fun, args, pool.ref));
+ }
+
/** Returns the expression as a string in the GF syntax */
public String toString() {
return showExpr(ref);
@@ -64,6 +85,7 @@ public class Expr implements Serializable {
private static native String showExpr(long ref);
private static native long initStringLit(String s, long pool);
+ private static native long initApp(Expr fun, Expr[] args, long pool);
private static native long initApp(String fun, Expr[] args, long pool);
private void writeObject(ObjectOutputStream out) throws IOException {