From: Andreas Holz
Subject: How to stop echoing to stdout while assigning values in code
Date: 
Message-ID: <1795018.0306270036.5e70fce5@posting.google.com>
Hello,

after approx. 15 years I would like to get in closer contact to LISP
again!

I've the following problem - please look at the code first (This is a
code-snippet from "band-inspector.lisp" from the misc directory of the
e3-project):


(defvar the-band nil "holds the contents of the load-band") 

(defun read-band (bandname) 
  "read in the load-band" 
  (with-open-file (in bandname :direction :input  
                   :if-does-not-exist :error 
                   :element-type '(unsigned-byte 32)) 
    (let ((buf (make-array (file-length in)  
                           :element-type '(unsigned-byte 32)))) 
      (read-sequence buf in) 
      (setq the-band buf))))

This is working almost as expected in cmucl18e (and lispworks 4.2
personal). My problem ist, that after reading the file "bandname", the
setq statement echoes the contents of "buf" (or "the-band") to stdout.
While reading files with a size of several megabytes, this behaviour
is not as expected (or bestter: desired).

How to suppress this echoing?

Andreas

From: Simon Katz
Subject: Re: How to stop echoing to stdout while assigning values in code
Date: 
Message-ID: <bdh23p$t01mg$1@ID-131024.news.dfncis.de>
"Andreas Holz" <······@topinform.com> wrote in message
································@posting.google.com...
>
> (defvar the-band nil "holds the contents of the load-band")
>
> (defun read-band (bandname)
>   "read in the load-band"
>   (with-open-file (in bandname :direction :input
>                    :if-does-not-exist :error
>                    :element-type '(unsigned-byte 32))
>     (let ((buf (make-array (file-length in)
>                            :element-type '(unsigned-byte 32))))
>       (read-sequence buf in)
>       (setq the-band buf))))
>
> This is working almost as expected in cmucl18e (and lispworks 4.2
> personal). My problem ist, that after reading the file "bandname",
> the
> setq statement echoes the contents of "buf" (or "the-band") to
> stdout.
> While reading files with a size of several megabytes, this behaviour
> is not as expected (or bestter: desired).
>
> How to suppress this echoing?
>
> Andreas

Is it that the result of READ-BAND is being printed? (SETQ returns the
value that it assigns.)

Try adding NIL or (VALUES) as the last form in READ-BAND.


BTW, you should rename THE-BAND as *THE-BAND*. DEFVAR defines
so-called special variables (look it up). The convention of wrapping
the names of specials in asterisks avoids the possibility of
accidentally creating a local variable with the same name in some
other function, which can give rise to obscure bugs.
From: Espen Vestre
Subject: Re: How to stop echoing to stdout while assigning values in code
Date: 
Message-ID: <kwsmpv28vo.fsf@merced.netfonds.no>
······@topinform.com (Andreas Holz) writes:

> This is working almost as expected in cmucl18e (and lispworks 4.2
> personal). My problem ist, that after reading the file "bandname", the
> setq statement echoes the contents of "buf" (or "the-band") to stdout.
> While reading files with a size of several megabytes, this behaviour
> is not as expected (or bestter: desired).
> 
> How to suppress this echoing?

Since READ-BAND is used for its side-effects, you may want it
to return something else than THE-BAND, for instance the return
value of read-sequence:

(defun read-band (bandname) 
  "read in the load-band" 
  (with-open-file (in bandname :direction :input  
                   :if-does-not-exist :error 
                   :element-type '(unsigned-byte 32)) 
    (let ((buf (make-array (file-length in)  
                           :element-type '(unsigned-byte 32)))) 
      (prog1
        (read-sequence buf in) 
        (setq the-band buf)))))

If you want it to return the buffer, you should just make sure you
limit the amount of data printed when you call it interactively,
either by adjusting print variables (see the hyperspec), or e.g.  by
calling it inside a progn: (progn (read-band "gazonk") nil)

A style hint: Use "starred" names for variables, i.e. use *the-band*!
-- 
  (espen)
From: Marco Antoniotti
Subject: Re: How to stop echoing to stdout while assigning values in code
Date: 
Message-ID: <3EFC644D.1040902@cs.nyu.edu>
Seems like you have a misconception problem here.

The question to ask is "who is printing out the result of my function?"
The answer is: "the interaction loop, AKA the READ-EVAL-PRINT loop."

This raises the following question.  What is the value that should be 
returned by the function?

If you want the buffer you read, then you cannot help getting it 
printed, unless you make provisions to avoid it.  Like

cl-prompt> (progn (read-band "the-band") t)
T ; Assuming no errors.

Otherwise, you need to change the return value of your function.

Cheers

Marco Antoniotti



Andreas Holz wrote:
> Hello,
> 
> after approx. 15 years I would like to get in closer contact to LISP
> again!
> 
> I've the following problem - please look at the code first (This is a
> code-snippet from "band-inspector.lisp" from the misc directory of the
> e3-project):
> 
> 
> (defvar the-band nil "holds the contents of the load-band") 
> 
> (defun read-band (bandname) 
>   "read in the load-band" 
>   (with-open-file (in bandname :direction :input  
>                    :if-does-not-exist :error 
>                    :element-type '(unsigned-byte 32)) 
>     (let ((buf (make-array (file-length in)  
>                            :element-type '(unsigned-byte 32)))) 
>       (read-sequence buf in) 
>       (setq the-band buf))))
> 
> This is working almost as expected in cmucl18e (and lispworks 4.2
> personal). My problem ist, that after reading the file "bandname", the
> setq statement echoes the contents of "buf" (or "the-band") to stdout.
> While reading files with a size of several megabytes, this behaviour
> is not as expected (or bestter: desired).
> 
> How to suppress this echoing?
> 
> Andreas
From: Christopher C. Stacy
Subject: Re: How to stop echoing to stdout while assigning values in code
Date: 
Message-ID: <uadc3usrf.fsf@dtpq.com>
>>>>> On 27 Jun 2003 01:36:37 -0700, Andreas Holz ("Andreas") writes:
 Andreas> I've the following problem - please look at the code first
 Andreas> (This is a code-snippet from "band-inspector.lisp" from the
 Andreas> misc directory of the e3-project):
 >
 > (defvar the-band nil "holds the contents of the load-band") 
 >
 > (defun read-band (bandname) 
 >   "read in the load-band" 
 >   (with-open-file (in bandname :direction :input  
 >                    :if-does-not-exist :error 
 >                    :element-type '(unsigned-byte 32)) 
 >     (let ((buf (make-array (file-length in)  
 >                            :element-type '(unsigned-byte 32)))) 
 >       (read-sequence buf in) 
 >       (setq the-band buf))))

 Andreas> This is working almost as expected in cmucl18e (and lispworks 4.2
 Andreas> personal). My problem ist, that after reading the file "bandname",
 Andreas> "the setq statement echoes the contents of "buf" (or "the-band")
 Andreas> to stdout.  While reading files with a size of several megabytes, 
 Andreas> this behaviour is not as expected (or bestter: desired).

 Andreas> How to suppress this echoing?

SETQ does not perform any output operations.
The "echoing" that you are seeing is coming from the Lisp 
development environment, not from your READ-BAND function.

The minimal development that most Lisp implementations provide is a
simple console program that allows you to use the keyboard to enter
Lisp expressions and view the results.  This interface is usually 
called a "listener" or a "READ-EVAL-PRINT loop".

You entered a Lisp expression that calls READ-BAND.  Lisp functions
return a value: the last value that the function computes.
The last thing that your READ-BAND function does is a SETQ.
SETQ returns the value of the thing that it set; therefore your
READ-BAND function returning the value of THE-BAND.
The listener prints out that value for you to see.

Since your program is storing the band in a gloabal variable, 
you don't need to return it as the value of READ-BAND.
So just change READ-BAND to return something else.

Perhaps a useful thing would be for READ-BAND to return would be an
indication of what it accomplished.  If it fails to sucessfully read
in the band data and update the global variable, it could return NIL.
When it works properly, it could perhaps return the pathname that it
read the data from, or its truename, or the number of bytes it read.

I would change the name of your global variable from THE-BAND 
to *THE-BAND*.  This convention will visually indicate to other 
Lisp programmers that you are referencing a global variable.