All Downloads are FREE. Search and download functionalities are using the official Maven repository.

convex.core.lang.AFn Maven / Gradle / Ivy

The newest version!
package convex.core.lang;

import convex.core.data.ACell;
import convex.core.data.IRefFunction;
import convex.core.data.Tag;
import convex.core.data.type.AType;
import convex.core.data.type.Types;

/**
 * Base class for functions expressed as values
 * 
 * "You know what's web-scale? The Web. And you know what it is? Dynamically
 * typed." - Stuart Halloway
 *
 * @param  Return type of functions.
 */
public abstract class AFn extends ACell implements IFn {
	
	@Override
	public abstract Context invoke(Context context, ACell[] args);
	
	@Override
	public abstract AFn updateRefs(IRefFunction func);
	
	@Override
	public final AType getType() {
		return Types.FUNCTION;
	}

	/**
	 * Tests if this function supports the given argument list
	 * 
	 * By default, checks if the function supports the given arity only.
	 * 
	 * TODO: intention is to override this to include dynamic type checks etc.
	 * @param args Array of arguments
	 * @return true if function supports the specified args array
	 */
	public boolean supportsArgs(ACell[] args) {
		return hasArity(args.length);
	}
	
	/**
	 * Tests if this function supports the given arity.
	 * @param arity Arity to check
	 * @return true if function supports the given arity, false otherwise
	 */
	public abstract boolean hasArity(int arity);
	
	@Override 
	public boolean isCVMValue() {
		return true;
	}
	
	@Override public final boolean isDataValue() {
		return true;
	}

	
	@Override
	public byte getTag() {
		return Tag.FN;
	}
	
	
	@Override
	public boolean equals(ACell o) {
		if (!(o instanceof AFn)) return false;
		return ACell.genericEquals(this, o);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy