Closed Jean-Luc-Picard-2021 closed 5 months ago
For reference: SICStus Prolog and Scryer Prolog provide read_from_chars/2
in their respective library(charsio)
to provide this functionality.
See also https://github.com/mthom/scryer-prolog/issues/1423#issuecomment-1100652091 for more information.
A library charsio does not anymore exist in SICStus Prolog 4.7.1:
| :- use_module(library(charsio)).
! Existence error in argument 1 of use_module/1
! file library(charsio) does not exist
! goal: use_module(user:library(charsio))
Oh the irony, I did find a library codesio:
| ?- use_module(library(codesio)).
% loading d:/software/logic/sics/library/codesio.po...
% module codesio imported into user
% loading d:/software/logic/sics/library/types.po...
% module types imported into codesio
% loaded d:/software/logic/sics/library/types.po in module types, 0 msec 6432 bytes
% loading foreign resource d:/software/logic/sics/library/x86_64-win32-nt-4/codesio.dll in module codesio
% loaded d:/software/logic/sics/library/codesio.po in module codesio, 0 msec 64768 bytes
yes
| ?- read_from_codes("X+Y.", T).
T = _A+_B ?
Meanwhile these two issues got closed:
https://github.com/mthom/scryer-prolog/issues/1423
https://github.com/trealla-prolog/trealla/issues/554
Any priorization for this feature request?
read_from_chars/2
would also help solve a recent question about Tau Prolog on Stackoverflow:
https://stackoverflow.com/questions/72292279/how-convert-an-atom-to-a-term-in-tau-prolog
This does something:
// term_atom/2
"term_atom/2": function(thread, point, atom) {
let term = atom.args[0];
let atom1 = atom.args[1];
if (pl.type.is_atom(atom1)) {
let tokenizer = new Tokenizer( thread );
tokenizer.new_text( atom1.id );
let tokens = tokenizer.get_tokens();
if( tokens === null ) {
thread.throw_error(pl.error.type("term", atom1, atom.indicator));
return;
}
let expr = parseExpr(thread, tokens, 0, thread.__get_max_priority(), false);
if( expr.len !== tokens.length ) {
thread.throw_error(pl.error.type("term", atom1, atom.indicator));
return;
}
let eq = new Term( "=", [term, expr.value] );
thread.prepend( [new State( point.goal.replace( eq ), point.substitution, point )] );
} else {
thread.throw_error( pl.error.type( "atom", atom1, atom.indicator ) );
}
},
But I am not happy with the syntax error, its only a type error.
In GNU Prolog I find:
Is there something similar in Tau Prolog?