ski

ski is module for calculating SKI Combinator.

Basic usage

You can pretty calculate SKI Combinators with calculate proc.

import ski

echo "Sxyz".calculate(combinators)

See also

Types

Combinator = ref object
  name*: string                ## Name
  argsCount*: int              ## Argument count
  format*: string              ## Format of convertion. Format example is "{0}{1}"...
  
Definition of Combinator.

Lets

combinators = @[Combinator(name: "S", argsCount: 3, format: "{0}{2}({1}{2})"),
              Combinator(name: "K", argsCount: 2, format: "{0}"),
              Combinator(name: "I", argsCount: 1, format: "{0}"),
              Combinator(name: "B", argsCount: 3, format: "{0}({1}{2})"),
              Combinator(name: "C", argsCount: 3, format: "({0}{2}){1}"),
              Combinator(name: "T", argsCount: 0, format: "K"),
              Combinator(name: "F", argsCount: 0, format: "SK")]
Builtin Combinators.

Procs

proc calculate(code: string; cs: openArray[Combinator]; n: int = -1): string {...}{.raises: [],
    tags: [].}

Returns results of repeat calculation. Count of calculation is n. Calculate until code can not be calculated when n is -1.

Japanese:

計算不能になるまでコンビネータ文字列を計算して返す。 計算不能、とは計算前と計算後の結果が一致する場合、または 指定した計算回数(n)分計算をした場合を指す。

Examples:

doAssert "Sxyz".calculate(combinators) == "xz(yz)"
doAssert "KKaxyz".calculate(combinators) == "xz"
doAssert "KKaxyz".calculate(combinators, 1) == "Kxyz"
proc calculateSeq(code: string; cs: openArray[Combinator];
                 results: seq[string] = @[]; n: int = -1): seq[string] {...}{.raises: [],
    tags: [].}

Returns process and results of repeat calculation. Count of calculation is n. Calculate until code can not be calculated when n is -1.

Japanese:

計算不能になるまでコンビネータ文字列を計算して、計算過程とともに返す。 計算不能、とは計算前と計算後の結果が一致する場合、または 指定した計算回数(n)分計算をした場合を指す。

Examples:

doAssert "Sxyz".calculateSeq(combinators) == @["xz(yz)"]
doAssert "KKaxyz".calculateSeq(combinators) == @["Kxyz", "xz"]
doAssert "KKaxyz".calculateSeq(combinators, n = 1) == @["Kxyz"]

Iterators

iterator calculateIterator(code: string; cs: openArray[Combinator]; n: int = -1): string {...}{.
    raises: [], tags: [].}

Returns process and results of repeat calculation. Count of calculation is n. Calculate until code can not be calculated when n is -1.

Japanese:

計算不能になるまでコンビネータ文字列を計算して、計算過程とともに返す。 計算不能、とは計算前と計算後の結果が一致する場合、または 指定した計算回数(n)分計算をした場合を指す。

Examples:

var ret: seq[string]
for r in "SKISxyz".calculateIterator(combinators):
  ret.add r
doAssert ret == @["KS(IS)xyz", "Sxyz", "xz(yz)"]