Re: [eclipse-users] sprintf?

From: Warwick Harvey <wh_at_...2...>
Date: Mon, 27 Aug 2007 08:18:14 +0100
Hi Kish,

This seems to come up often enough that I think it's worth putting into
ECLiPSe.  Is there any reason why it shouldn't go in, other than the fact
that I'll then have to remove its definition from half-a-dozen projects I've
worked on?  ;)

Here's the (obvious) definition I use:

sprintf(String, Format, Args) :-
	open(string(""), write, Stream),
	printf(Stream, Format, Args),
	get_stream_info(Stream, name, String),
	close(Stream).

Cheers,
Warwick

On Mon, Aug 27, 2007 at 07:04:14AM +0100, Kish Shen wrote:
> Hi Malcolm,
> 
> Malcolm Ryan wrote:
> > Is there an equivalent to 'sprintf' in eclipse? That is, a version of  
> > printf/3 which writes its output to a string variable rather than to  
> > a stream?
> >
> > Malcolm
> >
> >   
> You can do what you want by using a stream device that is a string 
> (string stream) or a memory
> buffer (queue stream) -- these are (pseudo-)I/O devices that you can 
> specify when you open
> the stream. Here is an example with  string streams:
> 
> [eclipse 8]: open(string(""), write, S),
>                 printf(S, "Hello there %d", [1]),
>         get_stream_info(S, name, String), close(S).
> 
> 
> S = 7
> String = "Hello there 1"
> 
> The `trick' here is the `name' of the stream is irs content - hence the 
> use of get_stream_info/3.
> 
> Cheers,
> 
> Kish
> > --
> > Many clever men like you have trusted to civilisation.
> > Many clever Babylonians, many clever Egyptians,
> > Many clever men at the end of Rome.
> >                                - G.K.Chesterton, The Napoleon of  
> > Notting Hill
> >
> >
> >
> >
> > _______________________________________________
> > ECLiPSe-Users mailing list
> > ECLiPSe-Users@...2...
> > http://www.crosscoreop.com/mailman/options/eclipse-users
> >   
> 
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users@...2...
> http://www.crosscoreop.com/mailman/options/eclipse-users

-- 
!umop apisdn papuadsns w,I - aW dlaH aseald
Received on Mon Aug 27 2007 - 08:35:03 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST