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.Variable
instance where the identifier is a unique number of each unique variable. - Integer
- Translate to a JavaScript
Number
when possible orBigInt
otherwise. Currently JavaScriptNumber
can represent integers upto 2^53 precisely. - Rational
- Translate to a JavaScript
Prolog.Rational
instance. - Float
- Translate to a JavaScript
Number
. - Atom
- Translate to a JavaScript
String
. - String
- Translate to a JavaScript
Prolog.String
instance. - List
- When a proper list create a JavaScript
Array
, otherwise create a JavaScriptProlog.List
instance. - Compound term
- Create a JavaScript
Prolog.Compound
instance. - Dict
- Create a plain JavaScript
Object
with the same keys. If the dict has a non-var tag, add a$tag
property.