13.2.2.2 Translating Prolog data to JavaScript
Most of the translation from Prolog data to JavaScript is the reverse
of the translation described in section
13.2.2.1. In some cases however reverse translation is ambiguous.
For example, both
42 and 42n (a JavaScript BigInt)
translate to a simple Prolog integer. The other way around, as
JavaScript
Number is a float, both Prolog 42 and 42.0
translate to 42 in JavaScript.
- Variable
- Translate to a JavaScript
Prolog.Variableinstance where the identifier is a unique number of each unique variable. - Integer
- Translate to a JavaScript
Numberwhen possible orBigIntotherwise. Currently JavaScriptNumbercan represent integers upto 2^53 precisely. - Rational
- Translate to a JavaScript
Prolog.Rationalinstance. - Float
- Translate to a JavaScript
Number. - Atom
- Translate to a JavaScript
String. - String
- Translate to a JavaScript
Prolog.Stringinstance. - List
- When a proper list create a JavaScript
Array, otherwise create a JavaScriptProlog.Listinstance. - Compound term
- Create a JavaScript
Prolog.Compoundinstance. - Dict
- Create a plain JavaScript
Objectwith the same keys. If the dict has a non-var tag, add a$tagproperty.