🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2056

Re: converting ascii character lists to functors

#2056
From: David Bowen
Date: Tue, 23 Apr 1991 22:19
31 lines
1625 bytes
A more efficient way to do this is with library(charsio):

| ?- use_module(library(charsio)).

| ?- with_output_to_chars(
         portray_clause(loves(John,Mary,John)), L),
     with_input_from_chars(
         read(Term), L).

John = _6327,
Mary = _6346,
L = [108,111,118,101,115,40,65,44,66,44,65,41,46,10],
Term = loves(_6768,_6785,_6768)

with_output_to_chars(+Goal, -Chars) executes Goal with current output
effectively being directed to the character list Chars.  

with_input_from_chars(+Goal, +Chars) executes Goal with current input
effectively being directed to Chars.

(portray_clause is a built-in predicate which writes clauses the way that
listing does.  In particular it takes care of putting the period and newline
at the end.)

Implementationally, with_output_to_chars creates a stream which writes to a
buffer in C.  (The buffer is expanded as necessary.)  Then it executes the
goal which is its first argument with the current output set to that stream.
Finally it reads the characters in the buffer and creates a list.  No real
I/O is involved, so this will be much faster than writing to an intermediate
file.
Technical Details
Message-ID: <1511@quintus.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!sun-barr!newstop!sun!quintus!dave
References: <EIVERSON.91Apr19200202@aigyptos.nmsu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!sun-barr!newstop!sun!quintus!dave
From: dave@quintus.UUCP (David Bowen)
Newsgroups: comp.lang.prolog
Subject: Re: converting ascii character lists to functors
Message-ID: <1511@quintus.UUCP>
Date: 23 Apr 91 22:19:13 GMT
References: <EIVERSON.91Apr19200202@aigyptos.nmsu.edu>
Reply-To: dave@quintus.UUCP (David Bowen)
Distribution: comp
Organization: Quintus Corporation
Lines: 31