From: Michael Shea
Subject: Lisp code porting problem
Date: 
Message-ID: <339khf$lse@obsidian.math.arizona.edu>
	I am trying to port a bit of code from KCL to Clisp on the
Amiga. When I try to load the code, the following line gives me
trouble.


(peek-char nil stream nil #\^D))

	Clisp says there is no character with name ^D.  The code was
written for Unix and the ^D (ie Control-D) is for end-of-file.  On the
Amiga, the end-of-file control character is ^\. How can a modify this
to work?

 
	

-- 
                     _    __
|\/|o _ |_  _. _ |  |_   (_ |_  _  _.   INTERNET: ·····@math.arizona.edu
|  ||(_ | |(_|(/_|  |_o  __)| |(/_(_|   Compuserve: 76665,3360
 

From: Christopher C Stacy
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <CuxLx1.6no@world.std.com>
Common Lisp doesn't have an "end of file" character, but you could 
rewrite that as #\control-D or control-\\ I guess.
From: Michael Shea
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <33b0k9$oje@obsidian.math.arizona.edu>
In article <··········@world.std.com>,
Christopher C Stacy <······@spacy.Boston.MA.US> wrote:
>Common Lisp doesn't have an "end of file" character, but you could 
>rewrite that as #\control-D or control-\\ I guess.


	Thanks alot. #\Control-\\ seems to work (ie the file will load
now with no errors). I have not had time to test it yet though.



-- 
                     _    __
|\/|o _ |_  _. _ |  |_   (_ |_  _  _.   INTERNET: ·····@math.arizona.edu
|  ||(_ | |(_|(/_|  |_o  __)| |(/_(_|   Compuserve: 76665,3360
 
From: Marco Antoniotti
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <MARCOXA.94Aug22093421@graphics.cs.nyu.edu>
In article <··········@world.std.com> ······@world.std.com (Christopher C Stacy) writes:

   Newsgroups: comp.lang.lisp
   From: ······@world.std.com (Christopher C Stacy)
   Reply-To: ······@spacy.Boston.MA.US
   Organization: The World @ Software Tool & Die
   References: <··········@obsidian.math.arizona.edu>
   Date: Mon, 22 Aug 1994 10:17:24 GMT
   Lines: 2

   Common Lisp doesn't have an "end of file" character, but you could 
   rewrite that as #\control-D or control-\\ I guess.

In fact the original writer of the code needed to read CLtL with a
little more attention.

--
Marco Antoniotti - Resistente Umano
-------------------------------------------------------------------------------
Robotics Lab		| room: 1220 - tel. #: (212) 998 3370
Courant Institute NYU	| e-mail: ·······@cs.nyu.edu

...e` la semplicita` che e` difficile a farsi.
...it is simplicity that is difficult to make.
				Bertholdt Brecht
From: Thomas A. Russ
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <TAR.94Aug22113952@grover.ISI.EDU>
In article <...> ·····@math.arizona.edu (Michael Shea) writes:
 > 
 > 	I am trying to port a bit of code from KCL to Clisp on the
 > Amiga. When I try to load the code, the following line gives me
 > trouble.
 > 
 > 
 > (peek-char nil stream nil #\^D))
 > 
 > 	Clisp says there is no character with name ^D.  The code was
 > written for Unix and the ^D (ie Control-D) is for end-of-file.  On the
 > Amiga, the end-of-file control character is ^\. How can a modify this
 > to work?

The fourth argument to PEEK-CHAR is the value that the function call
returns when an end-of-file is returned.  There is no requirement that
this value be any particular character.  It doesn't even have to be a
character.  (I typically use the keyword symbol :eof in my code).

You then just have to modify the test in the code that looks for the
end of file character and substitute whatever you specified as the end
of file value.


--
________________________________________________________________________
Thomas A. Russ,  Senior Research Scientist                   ···@isi.edu    
USC/Information Sciences Institute                  WWW:  http://isi.edu
4676 Admiralty Way, Marina del Rey, CA 90292          (310) 822-1511x775
From: Chris Riesbeck
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <33d263$mjh@anaxagoras.ils.nwu.edu>
In article <·················@grover.ISI.EDU>, ···@ISI.EDU (Thomas A. Russ) writes:
> In article <...> ·····@math.arizona.edu (Michael Shea) writes:
>  > 
>  > (peek-char nil stream nil #\^D))
> 
> The fourth argument to PEEK-CHAR is the value that the function call
> returns when an end-of-file is returned.  There is no requirement that
> this value be any particular character.  It doesn't even have to be a
> character.  (I typically use the keyword symbol :eof in my code).

In fact, for READ-CHAR and PEEK-CHAR, it should *not* be a character,
since, as others have pointed out, character's are not end of file
markers, and may in fact appear in the middle of the file.

For READ, even :EOF is not safe, since that might be in the file.
Safer to use 

   (let ((eof-flag (list nil)))
     ...
     (let ((x (read stream nil eof-flag)))
      (if (eq x eof-flag)     ;end of file

     ...
From: Richard A. O'Keefe
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <33ck84$50q@goanna.cs.rmit.oz.au>
·····@math.arizona.edu (Michael Shea) writes:
>	I am trying to port a bit of code from KCL to Clisp on the
>Amiga. When I try to load the code, the following line gives me
>trouble.

>(peek-char nil stream nil #\^D))

>	Clisp says there is no character with name ^D.  The code was
>written for Unix and the ^D (ie Control-D) is for end-of-file.  On the
>Amiga, the end-of-file control character is ^\. How can a modify this
>to work?

You have more of a porting problem than you think.  Control-D has no
special meaning in UNIX, and any program that tests for it is very likely
broken.  I have been using Control-Z as my end-of-file character ever since
TOPS-10 days, and see no reason to change.  I am sick of broken programs
that can Control-D wired in.  The right thing to do in UNIX, if you want
to refer to the user's current choice of end-of-file character is to use
the termios functions to _find_ _out_ what it is; and if that's hard, run
the 'stty' command to display the character mappings.

At the very least, in a Lisp program, you should have

    (defparameter *user-EOF-character*
	#+unix  (code-char  4)		; Control-D
	#+amiga (code-char 28)		; Control-Backslash
	"Keyboard end-of-file character")

And of course, you should design your program so that it is usable when
there is NO keyboard end of file character (one system I used you had to
type "?END" to get that effect).

-- 
30 million of Australia's 140 million sheep
suffer from some form of baldness.  -- Weekly Times.
From: Oliver Laumann
Subject: Re: Lisp code porting problem
Date: 
Message-ID: <33cru7$r1l@news.cs.tu-berlin.de>
> >	Clisp says there is no character with name ^D.  The code was
> >written for Unix and the ^D (ie Control-D) is for end-of-file.  On the
> >Amiga, the end-of-file control character is ^\. How can a modify this
> >to work?
> 
> You have more of a porting problem than you think.  Control-D has no
> special meaning in UNIX, and any program that tests for it is very likely
> broken.  I have been using Control-Z as my end-of-file character ever since
> TOPS-10 days, and see no reason to change.  I am sick of broken programs
> that can Control-D wired in.

Moreover, a program in UNIX does not actually *read* Control-D (or
Control-Z or whatever the EOF-character has been set to) when
end-of-file has been reached.  This is a common misconception.

Actually, there is no EOF-character in UNIX, just an EOF-condition.

The condition can be triggered on a terminal (or a comparable device)
by typing a special character (usually Control-D) at the beginning
of an input line.  The condition is signaled to a program that
reads input by having the read() system call return zero.  If the
getchar() standard I/O C function is used, the condition is signaled
by a return value of EOF.  EOF is *not* Control-D, though; there is no
relationship between what an input function (such as getchar) returns
and what the user has typed to trigger the EOF condition.

Whenever I see C code like

   c = read_next_char();
   if (c == '\004')      /* test for EOF */
      ...

I know that I better check the rest of the program very carefully.