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?
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
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
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
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
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.
····@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
···@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__
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?
"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>
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.
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...).
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.
····@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
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.
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
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
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__
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 :-)