From: Bob Felts
Subject: Stupid? format question
Date: 
Message-ID: <1itzpxg.301reu24fm20N%wrf3@stablecross.com>
I want to output tabbed data for later input to Excel or FileMaker or...

I can obviously do that with
   (format t "~a---tab goes here---~a~%" field1 field2)

In E-macs I can type C-q Tab to insert a tab.

But I miss the C-style ability to backquote special characters and I
haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
overlooked it?

 

From: Marco Antoniotti
Subject: Re: Stupid? format question
Date: 
Message-ID: <b54532d0-ad62-465a-afff-0921edc0727e@v5g2000pre.googlegroups.com>
On Jan 23, 4:08 pm, ····@stablecross.com (Bob Felts) wrote:
> I want to output tabbed data for later input to Excel or FileMaker or...
>
> I can obviously do that with
>    (format t "~a---tab goes here---~a~%" field1 field2)
>
> In E-macs I can type C-q Tab to insert a tab.
>
> But I miss the C-style ability to backquote special characters and I
> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
> overlooked it?

    (format t "|~C|~%" #\Tab)

outputs a single tab.  Have also a look at the ~T directive.

Cheers
--
Marco
From: Alberto Riva
Subject: Re: Stupid? format question
Date: 
Message-ID: <glcsb6$dc4e$1@usenet.osg.ufl.edu>
Marco Antoniotti wrote on 01/23/2009 11:00 AM:
> On Jan 23, 4:08 pm, ····@stablecross.com (Bob Felts) wrote:
>> I want to output tabbed data for later input to Excel or FileMaker or...
>>
>> I can obviously do that with
>>    (format t "~a---tab goes here---~a~%" field1 field2)
>>
>> In E-macs I can type C-q Tab to insert a tab.
>>
>> But I miss the C-style ability to backquote special characters and I
>> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
>> overlooked it?
> 
>     (format t "|~C|~%" #\Tab)
> 
> outputs a single tab.  Have also a look at the ~T directive.

And if you have multiple fields you want to print with tabs between them 
you can do the following:

   (let ((fmt (format nil "~~{~~a~~^~a~~}" #\tab)))
     (format nil fmt (list field1 field2 field3 ...))

Alberto
From: William James
Subject: Re: Stupid? format question
Date: 
Message-ID: <gldu2b019u5@enews5.newsguy.com>
Alberto Riva wrote:

> Marco Antoniotti wrote on 01/23/2009 11:00 AM:
> > On Jan 23, 4:08 pm, ····@stablecross.com (Bob Felts) wrote:
> > > I want to output tabbed data for later input to Excel or
> > > FileMaker or...
> > > 
> > > I can obviously do that with
> >>   (format t "~a---tab goes here---~a~%" field1 field2)
> > > 
> > > In E-macs I can type C-q Tab to insert a tab.
> > > 
> > > But I miss the C-style ability to backquote special characters
> > > and I haven't found any equivalent in Lisp.  ~t outputs spaces.
> > > Have I just overlooked it?
> > 
> >    (format t "|~C|~%" #\Tab)
> > 
> > outputs a single tab.  Have also a look at the ~T directive.
> 
> And if you have multiple fields you want to print with tabs between
> them you can do the following:
> 
>   (let ((fmt (format nil "~~{~~a~~^~a~~}" #\tab)))
>     (format nil fmt (list field1 field2 field3 ...))
> 
> Alberto

Ruby:

puts ["foo","bar","barely"].join "\t"
foo     bar     barely
    ==>nil
From: Marco Antoniotti
Subject: Re: Stupid? format question
Date: 
Message-ID: <8a814515-5cd3-426e-b8bc-e9ac93fb51f4@z28g2000prd.googlegroups.com>
On Jan 24, 3:23 am, "William James" <·········@yahoo.com> wrote:
> Alberto Riva wrote:
> > Marco Antoniotti wrote on 01/23/2009 11:00 AM:
> > > On Jan 23, 4:08 pm, ····@stablecross.com (Bob Felts) wrote:
> > > > I want to output tabbed data for later input to Excel or
> > > > FileMaker or...
>
> > > > I can obviously do that with
> > >>   (format t "~a---tab goes here---~a~%" field1 field2)
>
> > > > In E-macs I can type C-q Tab to insert a tab.
>
> > > > But I miss the C-style ability to backquote special characters
> > > > and I haven't found any equivalent in Lisp.  ~t outputs spaces.
> > > > Have I just overlooked it?
>
> > >    (format t "|~C|~%" #\Tab)
>
> > > outputs a single tab.  Have also a look at the ~T directive.
>
> > And if you have multiple fields you want to print with tabs between
> > them you can do the following:
>
> >   (let ((fmt (format nil "~~{~~a~~^~a~~}" #\tab)))
> >     (format nil fmt (list field1 field2 field3 ...))
>
> > Alberto
>
> Ruby:
>
> puts ["foo","bar","barely"].join "\t"
> foo     bar     barely
>     ==>nil

Not the same as Alberto's...  Besides the shortest CL program is

cl-prompt> (tabify '("foo" "bar" "baz"))
foo     bar     baz


Cheers
--
Marco
www.european-lisp-symposium.org
From: Raffael Cavallaro
Subject: Re: Stupid? format question
Date: 
Message-ID: <2009012311213716807-raffaelcavallaro@pasespamsilvousplaitmaccom>
On 2009-01-23 10:08:00 -0500, ····@stablecross.com (Bob Felts) said:

> But I miss the C-style ability to backquote special characters and I
> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
> overlooked it?

(string #\TAB)   ?
-- 
Raffael Cavallaro, Ph.D.
From: Thomas A. Russ
Subject: Re: Stupid? format question
Date: 
Message-ID: <ymi63k5a9wh.fsf@blackcat.isi.edu>
····@stablecross.com (Bob Felts) writes:

> I want to output tabbed data for later input to Excel or FileMaker or...
...
> In E-macs I can type C-q Tab to insert a tab.
> 
> But I miss the C-style ability to backquote special characters and I
> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
> overlooked it?

Well, the main reason is that lisp strings take their characters
directly and don't really need quoting (except for the string delimiter
" and the escape characer \).  So there isn't any mechanism in Lisp for
quoting characters that don't actually need it.

I suspect that the major difference between lisp and the C-style
languages is that lisp allows you to have line breaks inside your
strings directly.  So for example

 "This is a long string that
 takes up all of three
 separate lines"

is a legal string constant in Lisp, but not in C, C++, Java or most
other languages that I can think of.  So in languages that don't allow
the line breaks into strings, there is a need to quote them.  And if you
are quoting \n and \r, it is only a small leap to add \t, especially for
cases where it might be indistinguishable visually from space.

But since lisp didn't need to have special character quotation in the
first place, it just wasn't added to the language.

(But I do agree that it would sometimes be convenient.)



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal J. Bourguignon
Subject: Re: Stupid? format question
Date: 
Message-ID: <87zlhhij7b.fsf@galatea.local>
···@sevak.isi.edu (Thomas A. Russ) writes:

> ····@stablecross.com (Bob Felts) writes:
>
>> I want to output tabbed data for later input to Excel or FileMaker or...
> ...
>> In E-macs I can type C-q Tab to insert a tab.
>> 
>> But I miss the C-style ability to backquote special characters and I
>> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
>> overlooked it?
>
> Well, the main reason is that lisp strings take their characters
> directly and don't really need quoting (except for the string delimiter
> " and the escape characer \).  So there isn't any mechanism in Lisp for
> quoting characters that don't actually need it.
>
> I suspect that the major difference between lisp and the C-style
> languages is that lisp allows you to have line breaks inside your
> strings directly.  So for example
>
>  "This is a long string that
>  takes up all of three
>  separate lines"
>
> is a legal string constant in Lisp, but not in C, C++, Java or most
> other languages that I can think of.  So in languages that don't allow
> the line breaks into strings, there is a need to quote them.  And if you
> are quoting \n and \r, it is only a small leap to add \t, especially for
> cases where it might be indistinguishable visually from space.
>
> But since lisp didn't need to have special character quotation in the
> first place, it just wasn't added to the language.
>
> (But I do agree that it would sometimes be convenient.)

And trivial to implement as a reader macro on #\" if you need it.
(Several examples have already been posted in cll).
-- 
__Pascal Bourguignon__
From: William James
Subject: Re: Stupid? format question
Date: 
Message-ID: <gldv3t01bdp@enews5.newsguy.com>
Thomas A. Russ wrote:

> ····@stablecross.com (Bob Felts) writes:
> 
> > I want to output tabbed data for later input to Excel or FileMaker
> > or...
> ...
> > In E-macs I can type C-q Tab to insert a tab.
> > 
> > But I miss the C-style ability to backquote special characters and I
> > haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I
> > just overlooked it?
> 
> Well, the main reason is that lisp strings take their characters
> directly and don't really need quoting (except for the string
> delimiter " and the escape characer \).  So there isn't any mechanism
> in Lisp for quoting characters that don't actually need it.
> 
> I suspect that the major difference between lisp and the C-style
> languages is that lisp allows you to have line breaks inside your
> strings directly.  So for example
> 
>  "This is a long string that
>  takes up all of three
>  separate lines"
> 
> is a legal string constant in Lisp, but not in C, C++, Java or most
> other languages that I can think of.

It's legal in Ruby and in OCaml, but they allow quoting.
Does this string contain a tab?

"mewler  lisper"

Does this string contain a tab?

"mewler\tlisper"

See the difference?
From: Pascal J. Bourguignon
Subject: Re: Stupid? format question
Date: 
Message-ID: <87r62tifef.fsf@galatea.local>
"William James" <·········@yahoo.com> writes:
> Does this string contain a tab?
>
> "mewler  lisper"
>
> Does this string contain a tab?
>
> "mewler\tlisper"
>
> See the difference?

TAB is not a character, it's a control code.  
It has nothing to do in text files or in strings.

You may write:

    (send-string  device "mewler")
    (send-control device 9)
    (send-string  device "lisper")

if you will.

-- 
__Pascal Bourguignon__
From: Alexander Lehmann
Subject: Re: Stupid? format question
Date: 
Message-ID: <glcmsu$lt4$1@online.de>
Hi Bob,

Bob Felts wrote:
> I want to output tabbed data for later input to Excel or FileMaker or...

does this help?

<http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/f104f29d379f3bf8>
From: Bob Felts
Subject: Re: Stupid? format question
Date: 
Message-ID: <1iu07rx.ob8gunrcxoxjN%wrf3@stablecross.com>
Alexander Lehmann <········@in.tum.de> wrote:

> Hi Bob,
> 
> Bob Felts wrote:
> > I want to output tabbed data for later input to Excel or FileMaker or...
> 
> does this help?
> 
> <http://groups.google.com/group/comp.lang.lisp/
>      browse_thread/thread/f104f29d379f3bf8>

Not really, for two reasons.  First, it's CSV and I want tab-delimited
fields.  Second, I've already written the code.  It was easy.

I'm just curious if Lisp has the ability to embed human-readable control
characters in a format string.  I can embed a tab character, but if I
have multiple sequential tabs, I can't tell in Emacs how many I have by
visual inspection.  That is, I have to eyeball a variable number of
spaces and convert them to the equivalent number of tabs, instead of
simply counting \t\t\t.

I can also use ~c along with an argument of #\Tab, but that puts a layer
of indirection between the format string and the output.

Alberto kindly provided this example:

   (let ((fmt (format nil "~~{~~a~~^~a~~}" #\tab)))
     (format nil fmt (list field1 field2 field3 ...))

It's informative and on the one hand I think it's an interesting
technique.  On the other hand, it offends my sense of aesthetics.

Absent something like C's \t (or \n, or \g, or ...), I was hoping that
perhaps there as a reader macro, or something, that could be used inside
of a string to specify a control character.
From: GP lisper
Subject: Re: Stupid? format question
Date: 
Message-ID: <slrngnkkaa.7l6.spambait@phoenix.clouddancer.com>
On Fri, 23 Jan 2009 16:21:55 -0500, <····@stablecross.com> wrote:
>
> I'm just curious if Lisp has the ability to embed human-readable control
> characters in a format string.  I can embed a tab character, but if I
> have multiple sequential tabs, I can't tell in Emacs how many I have by
> visual inspection.

Try hexl-mode

After 22 versions spanning a fair number of years, "can't" rarely
exists in Emacs (and if you give a hacker a hint...).
From: Bob Felts
Subject: Re: Stupid? format question
Date: 
Message-ID: <1iu0icm.k7nwvq1n2zx4wN%wrf3@stablecross.com>
GP lisper <········@CloudDancer.com> wrote:

> On Fri, 23 Jan 2009 16:21:55 -0500, <····@stablecross.com> wrote:
> >
> > I'm just curious if Lisp has the ability to embed human-readable control
> > characters in a format string.  I can embed a tab character, but if I
> > have multiple sequential tabs, I can't tell in Emacs how many I have by
> > visual inspection.
> 
> Try hexl-mode
> 
> After 22 versions spanning a fair number of years, "can't" rarely
> exists in Emacs (and if you give a hacker a hint...).

Thanks for the pointer.  I'll check it out.
From: Zach Beane
Subject: Re: Stupid? format question
Date: 
Message-ID: <m3eiytvhno.fsf@unnamed.xach.com>
····@stablecross.com (Bob Felts) writes:

> Absent something like C's \t (or \n, or \g, or ...), I was hoping that
> perhaps there as a reader macro, or something, that could be used inside
> of a string to specify a control character.

CL-INTERPOL does something like that.

Zach
From: Bob Felts
Subject: Re: Stupid? format question
Date: 
Message-ID: <1iu0ibg.1a7qac6cb8itkN%wrf3@stablecross.com>
Zach Beane <····@xach.com> wrote:

> ····@stablecross.com (Bob Felts) writes:
> 
> > Absent something like C's \t (or \n, or \g, or ...), I was hoping that
> > perhaps there as a reader macro, or something, that could be used inside
> > of a string to specify a control character.
> 
> CL-INTERPOL does something like that.
> 

When will I learn to go to Edi's site first?  ;-)
Thanks, Zach.
From: Mirko
Subject: Re: Stupid? format question
Date: 
Message-ID: <bbfc0d98-704c-4bc4-85bc-3258baec3dc2@r38g2000vbi.googlegroups.com>
On Jan 23, 10:08 am, ····@stablecross.com (Bob Felts) wrote:
> I want to output tabbed data for later input to Excel or FileMaker or...
>
> I can obviously do that with
>    (format t "~a---tab goes here---~a~%" field1 field2)
>
> In E-macs I can type C-q Tab to insert a tab.
>
> But I miss the C-style ability to backquote special characters and I
> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
> overlooked it?

Can I add my own stupid format question?  I will just assume the
answer is yes.  Here it goes:

How can I print "abc" (i.e. the string `abc' enclosed in quotes).
From this discussion I found one way:

(format t "~aabc~a~%" (string #\") (string #\"))

Any way of quoting `"' in the format string itself?

Thank you,

Mirko
From: Zach Beane
Subject: Re: Stupid? format question
Date: 
Message-ID: <m34ozour4s.fsf@unnamed.xach.com>
Mirko <·············@gmail.com> writes:

> On Jan 23, 10:08 am, ····@stablecross.com (Bob Felts) wrote:
>> I want to output tabbed data for later input to Excel or FileMaker or...
>>
>> I can obviously do that with
>>    (format t "~a---tab goes here---~a~%" field1 field2)
>>
>> In E-macs I can type C-q Tab to insert a tab.
>>
>> But I miss the C-style ability to backquote special characters and I
>> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
>> overlooked it?
>
> Can I add my own stupid format question?  I will just assume the
> answer is yes.  Here it goes:
>
> How can I print "abc" (i.e. the string `abc' enclosed in quotes).
> From this discussion I found one way:
>
> (format t "~aabc~a~%" (string #\") (string #\"))
>
> Any way of quoting `"' in the format string itself?

In a string, you can precede " with \ to include " in the string:

  (format t "\"abc\"")

You could also do this:

  (format t "~S" "abc")

That's a little different, though.

Zach
From: Pascal J. Bourguignon
Subject: Re: Stupid? format question
Date: 
Message-ID: <873af8428h.fsf@galatea.local>
Zach Beane <····@xach.com> writes:

> Mirko <·············@gmail.com> writes:
>
>> On Jan 23, 10:08�am, ····@stablecross.com (Bob Felts) wrote:
>>> I want to output tabbed data for later input to Excel or FileMaker or...
>>>
>>> I can obviously do that with
>>> � �(format t "~a---tab goes here---~a~%" field1 field2)
>>>
>>> In E-macs I can type C-q Tab to insert a tab.
>>>
>>> But I miss the C-style ability to backquote special characters and I
>>> haven't found any equivalent in Lisp. �~t outputs spaces. �Have I just
>>> overlooked it?
>>
>> Can I add my own stupid format question?  I will just assume the
>> answer is yes.  Here it goes:
>>
>> How can I print "abc" (i.e. the string `abc' enclosed in quotes).
>> From this discussion I found one way:
>>
>> (format t "~aabc~a~%" (string #\") (string #\"))
>>
>> Any way of quoting `"' in the format string itself?
>
> In a string, you can precede " with \ to include " in the string:
>
>   (format t "\"abc\"")
>
> You could also do this:
>
>   (format t "~S" "abc")
>
> That's a little different, though.

That's a little better I'd say:


C/USER[2]> (progn (format t "\"~A\"~%" "abc\"def")
                  (format t "~S~%" "abc\"def")
                  (values))
"abc"def"
"abc\"def"

C/USER[3]> 


-- 
__Pascal Bourguignon__
From: Mirko
Subject: Re: Stupid? format question
Date: 
Message-ID: <f066c79d-3538-480b-bf1d-d3548daab1e1@n10g2000yqm.googlegroups.com>
On Jan 24, 8:13 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Zach Beane <····@xach.com> writes:
> > Mirko <·············@gmail.com> writes:
>
> >> On Jan 23, 10:08 am, ····@stablecross.com (Bob Felts) wrote:
> >>> I want to output tabbed data for later input to Excel or FileMaker or...
>
> >>> I can obviously do that with
> >>>    (format t "~a---tab goes here---~a~%" field1 field2)
>
> >>> In E-macs I can type C-q Tab to insert a tab.
>
> >>> But I miss the C-style ability to backquote special characters and I
> >>> haven't found any equivalent in Lisp.  ~t outputs spaces.  Have I just
> >>> overlooked it?
>
> >> Can I add my own stupid format question?  I will just assume the
> >> answer is yes.  Here it goes:
>
> >> How can I print "abc" (i.e. the string `abc' enclosed in quotes).
> >> From this discussion I found one way:
>
> >> (format t "~aabc~a~%" (string #\") (string #\"))
>
> >> Any way of quoting `"' in the format string itself?
>
> > In a string, you can precede " with \ to include " in the string:
>
> >   (format t "\"abc\"")
>
> > You could also do this:
>
> >   (format t "~S" "abc")
>
> > That's a little different, though.
>
> That's a little better I'd say:
>
> C/USER[2]> (progn (format t "\"~A\"~%" "abc\"def")
>                   (format t "~S~%" "abc\"def")
>                   (values))
> "abc"def"
> "abc\"def"
>
> C/USER[3]>
>
> --
> __Pascal Bourguignon__

I am sure you two were composing this answer even before I hit the
`send' key.

Thanks :-)