Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Array Lib #3

Open
joshcox opened this issue Apr 8, 2019 · 0 comments
Open

New: Array Lib #3

joshcox opened this issue Apr 8, 2019 · 0 comments
Assignees

Comments

@joshcox
Copy link
Owner

joshcox commented Apr 8, 2019

Terms encompass the data type of values that can be used within the microKanren system. Here's what they are:

export type Term = boolean | undefined | null | number | string | symbol | Array<any>;

Note that the Array term type is congruous to the List (pairs, cons cells, etc) type used in classic microKanren implementations. However, the data pattern (how to construct/deconstruct) Arrays in JavaScript isn't congruous with List implementations; they're not cons cells. Consider the following implementation of pusho; intuitive structural composition doesn't work to unify an array and therefore extra information may need to be passed to unify so that we may represent subsets of an array as symbols.

const pusho = (arr: Term, item: Term, out: Term): Goal => {
    if (typeof arr === "symbol") {
        // return unify([arr, Symbol.for("spread-left"), item], out);
    }
    if (Array.isArray(arr)) return unify([...arr, item], out);

    return fail(`pusho :: rest term type (${typeof arr}) not supported`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant