Cloje types and data conversion (meta issue)
This issue is for discussing and coordinating the implementation of Cloje types, and APIs for converting Cloje types to and from host types.
Blog posts
There have been some blog posts exploring Cloje types and data conversion.
They are long and rambling, so what follows is a summary of their conclusions ("the plan").
Summary
Cloje will provide new data structures for immutable lists, vectors, hash maps, and strings. At first these will be wrappers around the existing host type (to prevent mutation), but in the future they may be reimplemented as Clojure-style persistent immutable data structures.
Cloje will provide functions to convert from a Cloje type to the corresponding host type, and vice versa (e.g. cloje-vector->host-vector
and host-vector->cloje-vector
).
Any Cloje functions that operates on lists or strings, will accept host lists or host strings, but implicitly convert them to Cloje lists or Cloje strings before doing any work. (This does not apply to functions which treat their arguments as opaque values; e.g. (vector "foo")
would not convert the argument to a Cloje string.) These types are a special case, because it is not feasible to implement reader syntax for Cloje lists or Cloje strings.
Host vectors and host hash tables must be explicitly converted before being passed to Cloje functions. E.g. passing a host vector to a function expecting a Cloje vector would cause a type error.
Cloje will provide type predicate functions specifically to detect and distinguish between a Cloje type and the corresponding host type (e.g. cloje-vector?
and host-vector?
). Other type predicates (e.g. vector?
, list?
, string?
) will return true if the given object is the corresponding Cloje type or can be implicitly converted to that type. So, vector?
returns false for host vectors because host vectors are not implicitly converted. But list?
returns true for both Cloje lists and host lists, because host lists are implicitly converted.
Certain other types will be exactly the same as in the host language: functions, numbers, symbols, keywords (when available). No conversion will be necessary for these types.
Sub-issues
- #51: Immutable string type
-
#52: Placeholder immutable list type
- To be followed eventually by #15: Persistent immutable lists
-
#49: Placeholder immutable vector type
- To be followed eventually by #16: Persistent immutable vectors
-
#50: Placeholder immutable map type
- To be followed eventually by #17: Persistent immutable hash-maps