Article View: comp.lang.prolog
Article #1551Re: a question about read
From: Richard A. O'Keefe
Date: Tue, 06 Oct 1992 04:42
Date: Tue, 06 Oct 1992 04:42
60 lines
2659 bytes
2659 bytes
In article <brady-300992144101@brady.cs.tcd.ie>, brady@cs.tcd.ie (Michael Brady) writes: > My memory, which could easily be wrong, was that if for read(Term), it read > in the first term it came across, and failed if that term wasn't unifiable > with Term. It would also report syntax errors... > For get0(Char), it read in a character, and if the character didn't unify > with Char, it would advance to the next character and try again, ad > infinitum until the right character was read. > Is my memory playing tricks on me? Yes. All the input commands in DEC-10 Prolog had the same behaviour: guessing wrong about the output argument does not affect which side effects take place, only whether the query succeeds or fails. In a mix of Prolog and C: get0(Char) :- ( feof(current_input) -> error ; Char is getc(current_input), ). get(Char) :- ( feof(current_input) -> error ; Temp is getc(current_input), ( Temp =:= EOF -> Char is 26 % in DEC-10 Prolog Char is -1 % in just about every other Prolog since ; isspace(Temp) -> get(Char) ; Char is Temp ) ). skip(Char) :- C is Char, % Char may be an expression repeat, % repeat/0 is needed because get0(C), % get0(C) WON'T skip !. read(Term) :- repeat, get_tokens(Tokens), parse(Tokens, Result), !, Term = Result. > The real question is what is the most desirable action in these cases. I > agree with Lee about read/1, but how about get0/1 and get/1? They should be compatible with DEC-10 Prolog, C Prolog, PDP-11 Prolog, Prolog-X, SICStus Prolog, NU Prolog, Quintus Prolog, &c. It would be best if the default behaviour was to return -1 for EOF, but a DEC-10 compatibility mode would be of use as at least once PC implementation still uses 26 for EOF (because CP/M did, basically). -- RMIT policy requires the use of Gender Inclusive Language in all publications and in all information conveyed to students, staff, and potential job applicants. Lapses into English are the sole responsibility of the author. The Constitution of Australia does _not_ guarantee Freedom of Speech.
Technical Details
Message-ID:
<14904@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!mips2!news.bbn.com!olivea!spool.mu.edu!sgiblab!munnari.oz.au!bruce.cs.monash.edu.au!goanna!okReferences:
<10468@uqcspe.cs.uq.oz.au> <14755@goanna.cs.rmit.oz.au> <brady-300992144101@brady.cs.tcd.ie>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!mips2!news.bbn.com!olivea!spool.mu.edu!sgiblab!munnari.oz.au!bruce.cs.monash.edu.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: a question about read Message-ID: <14904@goanna.cs.rmit.oz.au> Date: 6 Oct 92 04:42:02 GMT References: <10468@uqcspe.cs.uq.oz.au> <14755@goanna.cs.rmit.oz.au> <brady-300992144101@brady.cs.tcd.ie> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 60