Skip to content

Commit

Permalink
functions are values
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaima committed Jun 13, 2020
1 parent bfccfbf commit b7ec581
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/APL/Scope.java
Expand Up @@ -344,8 +344,8 @@ private class Optimizer extends Builtin {
@Override
public Value call(Value w) {
String name = w.asString();
if (!(get(name) instanceof Value)) return Num.MINUS_ONE;
Value v = (Value) get(name);
if (!(Scope.this.get(name) instanceof Value)) return Num.MINUS_ONE;
Value v = (Value) Scope.this.get(name);
Value optimized = v.squeeze();
if (v == optimized) return Num.ZERO;
update(name, optimized);
Expand Down Expand Up @@ -553,7 +553,7 @@ private class NC extends Fun {
}

@Override public Value call(Value w) {
Obj obj = get(w.asString());
Obj obj = Scope.this.get(w.asString());
if (obj == null) return Num.ZERO;
if (obj instanceof Value) return Num.NUMS[2];
if (obj instanceof Fun ) return Num.NUMS[3];
Expand Down
7 changes: 6 additions & 1 deletion src/APL/types/Callable.java
@@ -1,10 +1,15 @@
package APL.types;

import APL.Scope;
import APL.types.arrs.*;

public abstract class Callable extends Obj {
public abstract class Callable extends Primitive {
final public Scope sc;
protected Callable(Scope sc) {
this.sc = sc;
}
public Value ofShape(int[] sh) {
if (sh.length==0) return this;
return new SingleItemArr(this, sh);
}
}
11 changes: 7 additions & 4 deletions src/APL/types/Fun.java
Expand Up @@ -566,6 +566,9 @@ else if ((a instanceof BigValue|an) & (w instanceof BigValue|wn))
}
}




@Override
public Type type() {
return Type.fn;
Expand All @@ -578,15 +581,15 @@ public Type type() {
return repr();
}

public Fun asFun() {
return this;
}

// functions are equal per-object basis
@Override public int hashCode() {
return actualHashCode();
}
@Override public boolean equals(Obj o) {
return this == o;
}

public Fun asFun() {
return this;
}
}
9 changes: 5 additions & 4 deletions src/APL/types/functions/Dop.java
Expand Up @@ -65,15 +65,16 @@ protected Fun isFn(Obj o, char c) {
return (Fun) o;
}


public Fun asFun() {
throw new Error("can't do");
}

// functions are equal per-object basis
@Override public int hashCode() {
return actualHashCode();
}
@Override public boolean equals(Obj o) {
return this == o;
}

public Fun asFun() {
throw new Error("can't do");
}
}
9 changes: 5 additions & 4 deletions src/APL/types/functions/Mop.java
Expand Up @@ -65,15 +65,16 @@ protected Fun isFn(Obj o) {
return (Fun) o;
}


public Fun asFun() {
throw new Error("can't do");
}

// functions are equal per-object basis
@Override public int hashCode() {
return actualHashCode();
}
@Override public boolean equals(Obj o) {
return this == o;
}

public Fun asFun() {
throw new Error("can't do");
}
}

0 comments on commit b7ec581

Please sign in to comment.