txr-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Txr-users] New to TXR questions


From: Kaz Kylheku
Subject: Re: [Txr-users] New to TXR questions
Date: Sat, 07 Apr 2012 12:46:23 -0700
User-agent: Roundcube Webmail/0.4

On Sat, 7 Apr 2012 12:35:51 +0100, Tristan Williams
<address@hidden> wrote:
> Hello,
> 
> I am new to TXR but am very hopeful that it will allow me to write
> (easily) some form letters from data in a CSV file. I really like that
> the @(output) allows me to write almost unhindered in the format
> language of my choice (Lout) but with the addition of the populated
> form fields from the CSV file.  
> 
> My questions are 
> 
> 1. Is there a date function exposed so that I can us it in the
> @(output) section?
> 
> 2. Is there a shell function exposed?

You now something, I was just thinking about those exact functions, a
few weeks
ago, and even started looking at various possibilities: how to provide
time.

And then I got distracted by this generational garbage collector. :)

There isn't a shell function, but there are pipes. In
the pattern language you can open a pipe using the next directive,
and scrape its output:

    @(next "!date")
    @date

That doesn't work inside output.

But the TXR Lisp dialect you can call open-pipe to open a pipe stream
to send input to a process or read output.

See what you can make out of this example:

    $ txr -c '@(bind x @(let ((s (open-pipe "echo foo" "r")))
                                (get-line s)))'
    x="foo"

A defun function to scrape a date out of the date command
and return some value could be cobbed together as a workaround.

More complete example:

@(do
   (defun get-date-hack ()
     (let ((p (open-pipe "date" "r")))
       (get-line p))))
@(output)
the date is: @(get-date-hack)
@(end)

There is a way for TXR Lisp to re-enter back into the pattern
language (via the match-fun function) so get-date-hack could
do the pattern scraping over the output of date. 

I haven't experimented with that at all, nor documented it.

Cheers ...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]