Re: read_from_chars/2
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 14 Sep 2006 19:59:12 GMT
On 2006-09-14, Mika <miky821@xxxxxxxx> wrote:
hello,
I do not succeed to find the predicate of SwiProlog equivalent to
predicate read_from_chars/2 of SicstusProlog. Someone can help me.
In most cases atom_to_term/3 will do the trick. If not, there is the
library memfile. Here is the code.
with_input_from_chars(Chars, Goal) :-
new_memory_file(MemFile),
open_memory_file(MemFile, write, Out),
format(Out, '~s', [Chars]),
close(Out),
open_memory_file(MemFile, read, In),
current_input(OldIn),
set_input(In),
call_cleanup(Goal,
( close(In),
set_input(OldIn),
free_memory_file(MemFile))).
1 ?- with_input_from_chars("hello. ", read(X)).
X = hello
Enjoy --- Jan
.
- References:
- read_from_chars/2
- From: Mika
- read_from_chars/2
- Prev by Date: read_from_chars/2
- Next by Date: Re: no backtrack
- Previous by thread: read_from_chars/2
- Index(es):