From: Buddy Smith
Subject: redirect output (newbie q)
Date: 
Message-ID: <7nlb1d$rqj$1@news-int.gatech.edu>
Hi!

Let's suppose I need to run a function, such as:

(:tag-analysis:tag-string "Hello my friend")

Is it possible to redirect the output of this function to a text file?

This function is provided by a lisp program I've already compiled and loaded.

Thanks!

--Clifford Smith

From: Kent M Pitman
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <sfw1zdtg0jo.fsf@world.std.com>
Buddy Smith <·····@tpac.iac.gatech.edu> writes:

> Hi!
> 
> Let's suppose I need to run a function, such as:
> 
> (:tag-analysis:tag-string "Hello my friend")

This probably has a typo in it.  Multiple [separated] colons in the same
token are undefined in CL.  You probably mean tag-analysis:tag-string
with no initial colon.
 
> Is it possible to redirect the output of this function to a text file?

(with-open-file (*standard-output* "foo.text" 
                    :direction :output
                    :if-exists :supersede  ;or :error, to be more cautious
		)
  (tag-analysis:tag-string "Hello my friend"))

That is, all output defaultly goes to *standard-output*.

WITH-OPEN-FILE binds a stream variable to an open file object.

Purists might do this in two steps to emphasize the separate nature
of the activities [(a) opening a file and (b) redirecting standard
output to that file], as in:

 (with-open-file (outstream "foo.text" 
                    :direction :output
                    :if-exists :supersede)
   (let ((*standard-output* outstream))
     ...whatever you want to do with standard output redirected...))

The other way to do this is to change TAG-ANALYSIS:TAG-STRING to take a
stream argument, and to pass OUTSTREAM as an explicit argument, but that
would require rewriting and recompiling the function, which the solution
I've provided here does not require.

> This function is provided by a lisp program I've already compiled and loaded.

That turns out not to matter.
 
From: Buddy Smith
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <7nlm8n$5mo$1@news-int.gatech.edu>
Kent M Pitman <······@world.std.com> wrote:

>> (:tag-analysis:tag-string "Hello my friend")

> This probably has a typo in it.  Multiple [separated] colons in the same
> token are undefined in CL.  You probably mean tag-analysis:tag-string
> with no initial colon.
yes it did. my bad :)
>  
>> Is it possible to redirect the output of this function to a text file?

> (with-open-file (*standard-output* "foo.text" 
>                     :direction :output
>                     :if-exists :supersede  ;or :error, to be more cautious
> 		)
>   (tag-analysis:tag-string "Hello my friend"))

> That is, all output defaultly goes to *standard-output*.

> WITH-OPEN-FILE binds a stream variable to an open file object.

does this mean i need to have the file open already? if so, how do i do
this?

> The other way to do this is to change TAG-ANALYSIS:TAG-STRING to take a
> stream argument, and to pass OUTSTREAM as an explicit argument, but that
> would require rewriting and recompiling the function, which the solution
> I've provided here does not require.

this would require my learning more about lisp, which is not my goal here
:) (my goal is to simply be able to use this lisp program)


>> This function is provided by a lisp program I've already compiled and loaded.

> That turns out not to matter.
>  

didn't think it would, but hey it can't hurt :)

Thanks again!

--Clifford Smith
From: Kent M Pitman
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <sfwu2qpo7ji.fsf@world.std.com>
Buddy Smith <·····@tpac.iac.gatech.edu> writes:

> > WITH-OPEN-FILE binds a stream variable to an open file object.
> 
> does this mean i need to have the file open already? if so, how do i do
> this?

You can look it up in the HyperSpec
 http://www.harlequin.com/education/books/HyperSpec/FrontMatter/
click on Symbol Index and then W and then WITH-OPEN-FILE.

However, I'll tell you what you will find is that WITH-OPEN-FILE
peforms the service of opening the file, and binding the stream variable
to a stream to the open file.  It will close the file automatically when
you exit the context of the body of the expression, even if by error.
So no, no call to OPEN or CLOSE is needed if you use that construct.

Just wrap the indicated expression around the call you're doing and it
should create a new file.  If you use
 :IF-EXISTS :SUPERSEDE
it will write over an existing file if there is one.  If you use
 :IF-EXISTS :ERROR
it will (well, it *should*) tell you if you're about to clobber a file.
(Some implementations are sloppy and don't check this, so be careful.)
From: Marco Antoniotti
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <lwr9lt9qe9.fsf@copernico.parades.rm.cnr.it>
Buddy Smith <·····@tpac.iac.gatech.edu> writes:

> Kent M Pitman <······@world.std.com> wrote:
> 
> >> (:tag-analysis:tag-string "Hello my friend")
> 
> > This probably has a typo in it.  Multiple [separated] colons in the same
> > token are undefined in CL.  You probably mean tag-analysis:tag-string
> > with no initial colon.
> yes it did. my bad :)
> >  
> >> Is it possible to redirect the output of this function to a text file?
> 
> > (with-open-file (*standard-output* "foo.text" 
> >                     :direction :output
> >                     :if-exists :supersede  ;or :error, to be more cautious
> > 		)
> >   (tag-analysis:tag-string "Hello my friend"))
> 
> > That is, all output defaultly goes to *standard-output*.
> 
> > WITH-OPEN-FILE binds a stream variable to an open file object.
> 
> does this mean i need to have the file open already? if so, how do i do
> this?
> 
> > The other way to do this is to change TAG-ANALYSIS:TAG-STRING to take a
> > stream argument, and to pass OUTSTREAM as an explicit argument, but that
> > would require rewriting and recompiling the function, which the solution
> > I've provided here does not require.
> 
> this would require my learning more about lisp, which is not my goal here
> :) (my goal is to simply be able to use this lisp program)

DON'T!  Do not try to learn more about (Common) Lisp.  It may
contaminate you and then you'll end up reading C.L.L. every day!
Next, you may even end up trying to convince a manager to use
CL as the implementation language of choice.  But, wirst of all, you
may end up thinking that C/C++ or Perl are not the way to do things.

Not a nice outlook! :}

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Johan Kullstam
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <uiu74evy0.fsf@res.raytheon.com>
Marco Antoniotti <·······@copernico.parades.rm.cnr.it> writes:

> Buddy Smith <·····@tpac.iac.gatech.edu> writes:
> 
> > this would require my learning more about lisp, which is not my goal here
> > :) (my goal is to simply be able to use this lisp program)
> 
> DON'T!  Do not try to learn more about (Common) Lisp.  It may
> contaminate you and then you'll end up reading C.L.L. every day!
> Next, you may even end up trying to convince a manager to use
> CL as the implementation language of choice.  But, wirst of all, you
> may end up thinking that C/C++ or Perl are not the way to do things.
> 
> Not a nice outlook! :}

argh!  i fear it is too late for me now.  just leave me here.  save
yourselves before you too are trapped.

  ;; i want to run a list a functions on a single argument
  ;; is there an inverted mapcar?
  (dolist (step 12-step-program)
    (funcall step common-lisp))

-- 
johan kullstam
From: Vassil Nikolov
Subject: Re: redirect output (newbie q)
Date: 
Message-ID: <l03130305b3c3edcff319@195.138.129.105>
Buddy Smith wrote:                [1999-07-27 22:15 +0000]

  > Hi!
  > 
  > Let's suppose I need to run a function, such as:
  > 
  > (:tag-analysis:tag-string "Hello my friend")
  > 
  > Is it possible to redirect the output of this function to a text file?
  [...]

Depending on what you mean by `output of this function', you need
to consider either
(1) calling PRINT^1 on the result of the function with a second argument
to PRINT which is bound to a stream open to a file (see OPEN and
WITH-OPEN-FILE), or
(2) binding *STANDARD-OUTPUT* to a stream open to a file (e.g.
by WITH-OPEN-FILE) while the function is running.
__________
^1 or FORMAT (where the stream argument comes first, and then a
format string etc.)


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.