@dallaylaen/ski-interpreter
    Preparing search index...

    Class SKI

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    addContext: boolean
    allow: Set<string>
    annotate: boolean
    hasLambdas: boolean
    hasNumbers: boolean
    known: Record<string, Named>
    B: Native = native.B
    C: Native = native.C
    classes: {
        Alias: typeof Alias;
        App: typeof App;
        Church: typeof Church;
        Expr: typeof Expr;
        FreeVar: typeof FreeVar;
        Lambda: typeof Lambda;
        Named: typeof Named;
        Native: typeof Native;
    } = classes
    control: {
        descend: <T>(value?: T) => TraverseControl<T>;
        prune: <T>(value?: T) => TraverseControl<T>;
        redo: <T>(value?: T) => TraverseControl<T>;
        stop: <T>(value?: T) => TraverseControl<T>;
    } = control
    extras: {
        checkFormatOptions: (
            raw: unknown,
        ) => { value: FormatOptions } | { error: Record<string, string> };
        declare: (expr: Expr, env?: Record<string, Named>) => string;
        deepFormat: (obj: any, options?: FormatOptions) => any;
        equiv: (e1: Expr, e2: Expr, options?: {}) => EquivResult;
        search: (
            seed: Expr[],
            options: SearchOptions,
            predicate: SearchCallback,
        ) => SearchResult;
        toposort: (
            options: {
                allow?: Record<string, Named>;
                env?: Record<string, Named>;
                list?: Expr | Expr[];
            },
        ) => ToposortResult;
    } = extras

    Type Declaration

    I: Native = native.I
    K: Native = native.K
    native: Record<string, Native> = native
    Quest: typeof Quest = Quest
    S: Native = native.S
    W: Native = native.W

    Methods

    • Declare a new term If the first argument is an Alias, it is added as is. Otherwise, a new Alias or Native term (depending on impl type) is created. If note is not provided and this.annotate is true, an automatic note is generated.

      If impl is a function, it should have signature (Expr) => ... => Expr (see typedef Partial at top of expr.js)

      Parameters

      • term: string | Alias
      • Optionalimpl: string | Expr | ((arg: Expr) => Invocation)
      • Optionaloptions: string | AddOptions
        • string
        • AddOptions
          • Optionalarity?: number
          • Optionalcanonize?: boolean
          • Optionalfancy?: string
          • Optionalnote?: string

      Returns this

      chainable

      ski.add('T', 'S(K(SI))K', 'swap combinator')
      
      ski.add( ski.parse('T = S(K(SI))K') ) // ditto but one-arg form
      
      ski.add('T', x => y => y.apply(x), 'swap combinator') // heavy artillery
      
      ski.add('Y', function (f) { return f.apply(this.apply(f)); }, 'Y combinator')
      
    • Declare and remove multiple terms at once term=impl adds term term= removes term

      Parameters

      • list: string[]

      Returns this

      chainable

    • Export term declarations for use in bulkAdd(). Currently only Alias terms are serialized.

      Returns string[]

    • Experimental

      Declare a new term if it is not known, otherwise just allow it. Currently only used by quests. Use with caution, this function may change its signature, behavior, or even be removed in the future.

      Parameters

      Returns this

    • Parameters

      • source: string
      • Optionaloptions: ParseOptions = {}
        • Optionalallow?: string
        • Optionalcanonize?: boolean
        • Optionalenv?: { [key: string]: Expr }
        • Optionallambdas?: boolean
        • Optionalnumbers?: boolean
        • Optionalscope?: object

      Returns Expr

    • Parse a single line of source code, without splitting it into declarations. Internal, always use parse() instead.

      Parameters

      • source: string

        S(KI)I

      • env: { [key: string]: Expr } = {}
      • Optionaloptions: ParseOptions = {}
        • Optionalallow?: string
        • Optionalcanonize?: boolean
        • Optionalenv?: { [key: string]: Expr }
        • Optionallambdas?: boolean
        • Optionalnumbers?: boolean
        • Optionalscope?: object

      Returns Expr

      parsed expression

    • Restrict the interpreter to given terms. Terms prepended with '+' will be added and terms preceeded with '-' will be removed.

      Parameters

      • spec: string

      Returns this

      chainable

      ski.restrict('SK') // use the basis
      
      ski.restrict('+I') // allow I now
      
      ski.restrict('-SKI +BCKW' ); // switch basis
      
      ski.restrict('-foo -bar'); // forbid some user functions
      
    • Returns {
          allow: string;
          annotate: boolean;
          lambdas: boolean;
          numbers: boolean;
          terms: string[];
          version: string;
      }

    • Create a proxy object that generates variables on demand, with names corresponding to the property accessed. Different invocations will return distinct variables, even if with the same name.

      Parameters

      • scope: object = {}

      Returns { [key: string]: FreeVar }

      const {x, y, z} = SKI.vars();
      x.name; // 'x'
      x instanceof FreeVar; // true
      x.apply(y).apply(z); // x(y)(z)