Class FunHelper


  • public class FunHelper
    extends Object
    A helper for funs.
    • Method Detail

      • compile

        public <T> T compile​(Locale locale,
                             String programName,
                             String programText,
                             Function<? super FunVal,​? extends T> onSucc,
                             Function3<? super String,​? super Integer,​? super Integer,​? extends T> onError)
        Compiles a program text to a top level fun.

        If the program text is successfully compiled to a top level fun, onSucc is called with the fun.

        If the program text cannot be compiled and causes a compile error, onError is called with (msg, startPos, endPos) where msg is an error message, startPos is a position index of the start of the error, and endPos is the position index of the end of the error.

        Type Parameters:
        T - the type of the result.
        Parameters:
        locale - the locale to generate compile error messages.
        programName - the name of the program.
        programText - the program text.
        onSucc - the function which is called when the program is successfully compiled.
        onError - the function which is called when the program causes a compile error.
        Returns:
        the result of onSucc or onError.
      • make

        public HostFunBuilder make​(String desc)
        Returns a builder of a host fun, with the description of the fun.

        See org.kink_lang.kink.hostfun for detail.

        Parameters:
        desc - the description of the fun, which is used in arity error messages.
        Returns:
        a builder.
      • constant

        public FunVal constant​(Val val)
        Returns a constant fun: which is a 0-ary fun returning the val constantly.
        Parameters:
        val - the constant val.
        Returns:
        a constant fun.