From: Alberto Riva
Subject: Tilde-slash directive with no arguments?
Date: 
Message-ID: <g9pbs9$h81g$1@usenet.osg.ufl.edu>
Hello,

is it possible to invoke a user-supplied function through ~/.../ so that 
it does not consume any arguments? The answer seems to be no according 
to the spec, but I just wanted to be sure.

Basically I'm trying to use ~/.../ to call a function that writes a 
single #\tab character to the output stream, so that I can convert lists 
into rows of tab-delimited data easily. I'd like to be able to write 
something like the following:

   (format out "~{~a~^~/tb/~}~%" data)

where USER::TB is the name of my tab-printing function. But this doesn't 
work because ~/tb/ consumes one element from data at each iteration. I 
can "fake it" using ~:*, like this:

   (format out "~{~a~^~:*~/tb/~}~%" data)

This works, but it's perliness (or is it perlyness?) is a bit too high, 
I was looking for a more readable solution.

Thanks,

Alberto

From: Thomas A. Russ
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <ymivdxbock9.fsf@blackcat.isi.edu>
Alberto Riva <·····@nospam.ufl.edu> writes:

> Basically I'm trying to use ~/.../ to call a function that writes a
> single #\tab character to the output stream, so that I can convert lists
> into rows of tab-delimited data easily. I'd like to be able to write
> something like the following:
> 
>    (format out "~{~a~^~/tb/~}~%" data)

The simplest solution is to just put a tab into the string.  Unlike some
other languages, Lisp strings can contain any legal character, including
literal tabs, carriage returns, linefeeds, etc.  You do not need to
terminate a string on the same source file line that it starts on.

So just put a tab character directly into the format string:

  (format out "~{~a~^	~}~%" data)

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Barry Margolin
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <barmar-1ED5A8.21143804092008@newsgroups.comcast.net>
In article <···············@blackcat.isi.edu>,
 ···@sevak.isi.edu (Thomas A. Russ) wrote:

> Alberto Riva <·····@nospam.ufl.edu> writes:
> 
> > Basically I'm trying to use ~/.../ to call a function that writes a
> > single #\tab character to the output stream, so that I can convert lists
> > into rows of tab-delimited data easily. I'd like to be able to write
> > something like the following:
> > 
> >    (format out "~{~a~^~/tb/~}~%" data)
> 
> The simplest solution is to just put a tab into the string.  Unlike some
> other languages, Lisp strings can contain any legal character, including
> literal tabs, carriage returns, linefeeds, etc.  You do not need to
> terminate a string on the same source file line that it starts on.
> 
> So just put a tab character directly into the format string:
> 
>   (format out "~{~a~^	~}~%" data)

What people generally don't like about this approach is that you can't 
tell by looking at it that there's a TAB.  You also lose it if you ever 
do any screen-scraping, or post the code in something like PDF.

You can do that in C, too, but isn't \t more programmer-friendly?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Alberto Riva
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <g9rgpl$d80u$1@usenet.osg.ufl.edu>
Barry Margolin wrote:
> In article <···············@blackcat.isi.edu>,
>  ···@sevak.isi.edu (Thomas A. Russ) wrote:
> 
>> Alberto Riva <·····@nospam.ufl.edu> writes:
>>
>>> Basically I'm trying to use ~/.../ to call a function that writes a
>>> single #\tab character to the output stream, so that I can convert lists
>>> into rows of tab-delimited data easily. I'd like to be able to write
>>> something like the following:
>>>
>>>    (format out "~{~a~^~/tb/~}~%" data)
>> The simplest solution is to just put a tab into the string.  Unlike some
>> other languages, Lisp strings can contain any legal character, including
>> literal tabs, carriage returns, linefeeds, etc.  You do not need to
>> terminate a string on the same source file line that it starts on.
>>
>> So just put a tab character directly into the format string:
>>
>>   (format out "~{~a~^	~}~%" data)
> 
> What people generally don't like about this approach is that you can't 
> tell by looking at it that there's a TAB.  You also lose it if you ever 
> do any screen-scraping, or post the code in something like PDF.

Right. That's why in the solution I proposed in the end I create the 
format string with another FORMAT, so it's clear that there's a #\tab in 
there:

   (format nil "~~{~~a~~^~a~~}" #\tab)

Alberto
From: Pascal J. Bourguignon
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <87abenwv0f.fsf@hubble.informatimago.com>
Alberto Riva <·····@nospam.ufl.edu> writes:
> is it possible to invoke a user-supplied function through ~/.../ so
> that it does not consume any arguments? The answer seems to be no
> according to the spec, but I just wanted to be sure.

You may be sure.

I hoped that ~0/.../ would do the trick, but the function is specified
to take at least one argument in addition to the stream, at and colon.


> Basically I'm trying to use ~/.../ to call a function that writes a
> single #\tab character to the output stream, so that I can convert
> lists into rows of tab-delimited data easily. I'd like to be able to
> write something like the following:
>
>   (format out "~{~a~^~/tb/~}~%" data)
>
> where USER::TB is the name of my tab-printing function. But this
> doesn't work because ~/tb/ consumes one element from data at each
> iteration. I can "fake it" using ~:*, like this:
>
>   (format out "~{~a~^~:*~/tb/~}~%" data)
>
> This works, but it's perliness (or is it perlyness?) is a bit too
> high, I was looking for a more readable solution.

You can use ~T
or insert a literal tabulation in the literal string,
or (format out "~A" #\tab)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w--- 
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++ 
G e+++ h+ r-- z? 
------END GEEK CODE BLOCK------
From: Alberto Riva
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <g9plh7$es5m$1@usenet.osg.ufl.edu>
Pascal J. Bourguignon wrote:
> Alberto Riva <·····@nospam.ufl.edu> writes:
>> is it possible to invoke a user-supplied function through ~/.../ so
>> that it does not consume any arguments? The answer seems to be no
>> according to the spec, but I just wanted to be sure.
> 
> You may be sure.

Too bad :(

>> Basically I'm trying to use ~/.../ to call a function that writes a
>> single #\tab character to the output stream, so that I can convert
>> lists into rows of tab-delimited data easily. I'd like to be able to
>> write something like the following:
>>
>>   (format out "~{~a~^~/tb/~}~%" data)
>>
>> where USER::TB is the name of my tab-printing function. But this
>> doesn't work because ~/tb/ consumes one element from data at each
>> iteration. I can "fake it" using ~:*, like this:
>>
>>   (format out "~{~a~^~:*~/tb/~}~%" data)
>>
>> This works, but it's perliness (or is it perlyness?) is a bit too
>> high, I was looking for a more readable solution.
> 
> You can use ~T

But that inserts spaces, not a single tab character.

> or insert a literal tabulation in the literal string,
> or (format out "~A" #\tab)

Well, I don't know if this is what you meant, but I think you pointed me 
towards an alternative solution:

(let ((fs (format nil "~~{~~a~~^~a~~}" #\tab)))
   (format nil fs '(1 2 3)))

"1	2	3"

(the spaces between the numbers are actually tab characters).

Thanks!

Alberto
From: John Thingstad
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <op.ug0cvfjeut4oq5@pandora.alfanett.no>
P� Thu, 04 Sep 2008 21:13:40 +0200, skrev Alberto Riva  
<·····@nospam.ufl.edu>:

> Hello,
>
> is it possible to invoke a user-supplied function through ~/.../ so that  
> it does not consume any arguments? The answer seems to be no according  
> to the spec, but I just wanted to be sure.
>
> Basically I'm trying to use ~/.../ to call a function that writes a  
> single #\tab character to the output stream, so that I can convert lists  
> into rows of tab-delimited data easily. I'd like to be able to write  
> something like the following:
>
>    (format out "~{~a~^~/tb/~}~%" data)
>
> where USER::TB is the name of my tab-printing function. But this doesn't  
> work because ~/tb/ consumes one element from data at each iteration. I  
> can "fake it" using ~:*, like this:
>
>    (format out "~{~a~^~:*~/tb/~}~%" data)
>
> This works, but it's perliness (or is it perlyness?) is a bit too high,  
> I was looking for a more readable solution.
>
> Thanks,
>
> Alberto

Actually format has a tab directive ~T, but it doesn't work like that.
It seems to me you want it to work like printf, but format is more based  
on Fortran's format.
In format you dont look at the individual values you look at width of the  
entire field.
A field starts with ~< and ends with ~> and ~T only has meaning within  
this.
The syntax is ~col,col-incT. First it tries to go to column col. If at  
column col - go to col + col-inc.

example:

CL-USER 2 > (format *standard-output* "~<~{~A~^~8,8T~}~>" '(1 2 3 4 5))
1       2       3       4       5


--------------
John Thingstad
From: Marco Antoniotti
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <19afb846-d2db-47a2-8049-516b325bffd0@d77g2000hsb.googlegroups.com>
On Sep 5, 2:27 pm, "John Thingstad" <·······@online.no> wrote:
> På Thu, 04 Sep 2008 21:13:40 +0200, skrev Alberto Riva  
> <·····@nospam.ufl.edu>:
>
>
>
> > Hello,
>
> > is it possible to invoke a user-supplied function through ~/.../ so that  
> > it does not consume any arguments? The answer seems to be no according  
> > to the spec, but I just wanted to be sure.
>
> > Basically I'm trying to use ~/.../ to call a function that writes a  
> > single #\tab character to the output stream, so that I can convert lists  
> > into rows of tab-delimited data easily. I'd like to be able to write  
> > something like the following:
>
> >    (format out "~{~a~^~/tb/~}~%" data)
>
> > where USER::TB is the name of my tab-printing function. But this doesn't  
> > work because ~/tb/ consumes one element from data at each iteration. I  
> > can "fake it" using ~:*, like this:
>
> >    (format out "~{~a~^~:*~/tb/~}~%" data)
>
> > This works, but it's perliness (or is it perlyness?) is a bit too high,  
> > I was looking for a more readable solution.
>
> > Thanks,
>
> > Alberto
>
> Actually format has a tab directive ~T, but it doesn't work like that.
> It seems to me you want it to work like printf, but format is more based  
> on Fortran's format.
> In format you dont look at the individual values you look at width of the  
> entire field.
> A field starts with ~< and ends with ~> and ~T only has meaning within  
> this.

Not really.  ~T works also by itself.

> The syntax is ~col,col-incT. First it tries to go to column col. If at  
> column col - go to col + col-inc.
>
> example:
>
> CL-USER 2 > (format *standard-output* "~<~{~A~^~8,8T~}~>" '(1 2 3 4 5))
> 1       2       3       4       5
>

Yep.  It is the col and colinc parameters that do the trick.  See the
following.

CL-USER 1 > (dotimes (i 10) (format t "|~VT|~%" i))
| |
| |
| |
|  |
|   |
|    |
|     |
|      |
|       |
|        |
NIL

Cheers
--
Marco
From: Stephen Compall
Subject: Re: Tilde-slash directive with no arguments?
Date: 
Message-ID: <m2d4jixghd.fsf@nocandy.dyndns.org>
Alberto Riva <·····@nospam.ufl.edu> writes:
> Basically I'm trying to use ~/.../ to call a function that writes a
> single #\tab character to the output stream

(asdf:oos 'asdf:load-op '#:cl-interpol)
(cl-interpol:enable-interpol-syntax)
(format t #?"~A\t~A" 42 42)
⊣ 42	42

cl-interpol also includes interpolation features, which you /may/ like
to use rather than format.

-- 
I write stuff at blah blah...