Article View: comp.lang.prolog
Article #2044converting ascii character lists to functors
From: Eric Iverson
Date: Sat, 20 Apr 1991 02:02
Date: Sat, 20 Apr 1991 02:02
52 lines
2318 bytes
2318 bytes
The following is a letter I just wrote to Quintus:
To: teksup@quintus.com
Subject: converting ascii character lists to functors
--text follows this line--
I called today about converting ascii character lists into functors
which could be unified with other functors. I need to do this because
I need to use a character based read function for my file I/O. Here's
what I came up with:
functor_chars(Functor,Chars):-
atom_chars(Char1,Chars),
tell('functor_chars'),
format('~w.~n',Char1),
see('functor_chars'),
read(Functor),
close('functor_chars'),
unix(system('rm functor_chars')).
Here's a demo:
Quintus Prolog Release 3.0 (Sun-4, SunOS 4.1)
Copyright (C) 1990, Quintus Computer Systems, Inc. All rights reserved.
1310 Villa Street, Mountain View, California U.S.A. (415) 965-7700
| ?- % compiling file /tmp_mnt/home/thrinakia1/eiverson/prolog/functor_chars.pl
% functor_chars.pl compiled in module user, 0.067 sec 516 bytes
yes
| ?- name('loves(John,Mary,John)',X),functor_chars(F,X).
X = [108,111,118,101,115,40,74,111,104,110,44,77,97,114,121,44,74,111,104,110,41],
F = loves(_3569,_3590,_3569) ;
no
| ?-
Can you think of a way to do this which does not involve writing to,
reading from, and then removing a file? The current routine is rather
slow. Is there some way that I could just open up a stream, write
things to it, and then read from it? In other words, how can I read
from buffers in Quintus Prolog? Any help would be appreciated.
--
------------------------------------------------------------------------
Eric Iverson Internet: eiverson@nmsu.edu
Computing Research Lab
Box 30001/3CRL Life is something to do when
New Mexico State University you can't get to sleep.
Las Cruces, NM 88003-0001 -Fran Lebowitz
VOICE: (505) 646-5711
FAX: (505) 646-6218
Technical Details
Message-ID:
<EIVERSON.91Apr19200202@aigyptos.nmsu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!ariel.unm.edu!nmsu!opus!eiversonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!cs.umn.edu!ariel.unm.edu!nmsu!opus!eiverson From: eiverson@nmsu.edu (Eric Iverson) Newsgroups: comp.lang.prolog Subject: converting ascii character lists to functors Message-ID: <EIVERSON.91Apr19200202@aigyptos.nmsu.edu> Date: 20 Apr 91 02:02:02 GMT Sender: news@NMSU.Edu Distribution: comp Organization: Computing Research Lab Lines: 52