This Prolog text provides reading and writing memory streams. The approach is to cooperate with the native garbage collection. The predicates open_input_atom_stream/2 and open_output_atom_stream/2 create memory streams, but there is no bureaucracy necessary to manually free them when they are not needed anymore.
As a convenience the predicate term_atom/[2,3] allows writing a Prolog term into a new atom. The binary predicate will use writeq/1, the ternary predicate will use write_term/2 and if quoting isn’t desired, one needs to opt-out. The predicate can also read Prolog terms from a given atom, whereas by default it will not require a terminating period.
The following compat predicates are provided: