Skip to content
This repository has been archived by the owner on Aug 29, 2022. It is now read-only.

Term representation in JavaScript inspired by JPL #4

Open
rla opened this issue Jul 16, 2018 · 2 comments
Open

Term representation in JavaScript inspired by JPL #4

rla opened this issue Jul 16, 2018 · 2 comments
Assignees

Comments

@rla
Copy link
Collaborator

rla commented Jul 16, 2018

This representation provides higher-level interface than C functions in the SWI-Prolog Foreign Language Interface (FLI).

All currently created demos use FLI.

JPL is an language bridge between SWI-Prolog and Java. It uses Java objects to represent terms. Link to code: https://github.com/SWI-Prolog/packages-jpl/tree/master/src/java/org/jpl7. The representation of terms can be modelled by it.

It should be tried to make this lazy so that a potentially large term is not converted into an object tree at once. Support for cyclic terms needs some research.

Another JavaScript interface is used by Node-SWI bridge, it already has JPL-like interface:
https://github.com/rla/node-swipl#output-term-representation but has some questionable choices like string "[]" for empty lists.

Support for dicts should be provided. They could be mapped directly to objects. Tag can be represented using a Symbol (not a normal property). FLI lacks dict support right now and dicts cannot be directly accessed.

Support for blobs should be provided. They could be converted into Typed Arrays or a similar thing that is backed directly by WebAssembly memory.

Atoms and strings must support unicode. wchar_t should be converted into UCS-2/UTF16 directly without going through UTF8. wchar_t is a compiler-specific 4-byte character type.

@rla rla self-assigned this Jul 16, 2018
@rla
Copy link
Collaborator Author

rla commented Aug 10, 2018

I have looked at the JPL term representation and it has excessive (imho) wrapping of atoms and numbers, possibly as a requirement by the Java type system to represent term arguments (cannot mix Java primitives and objects) inside a same array.

I am not convinced that we need such wrapping in JavaScript.

Other API examples (Python and other JS libs, more suited for a dynamic language):

I did not find information on term representation of YieldProlog.

I like PySwip representation of logical variables (reassign on next answer). Prolog-in-JS implementations seem to use the term structures as a part of internal implementation and contain otherwise unnecessary properties.

Pengines simply map terms to JSON: http://www.swi-prolog.org/pldoc/man?section=prolog-canonical-json.

Also for reference, table of SWI-Prolog datatypes: http://www.swi-prolog.org/datatypes.html.

@rla
Copy link
Collaborator Author

rla commented Aug 10, 2018

Reference to the Tau-Prolog's relevant issue: https://github.com/jariazavalverde/tau-prolog/issues/46.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant