From: Greg Menke
Subject: Fun with eval
Date: 
Message-ID: <m3k7v9q1en.fsf@europa.pienet>
I'm consolidating some Lisp & shell script stuff we use to feed logic
analyzer data to gnuplot, moving everything into Lisp.  Particularly,
I want to put the gnuplot script into Lisp, so I can keep its
definition alongside the code that generates the data- makes tweaking
things easier.  I came up with the following


(let ((gpscript '("set format y  \"%5.0f\""
                  "set format y2 \"%5.0f\""
		  "#set yrange  [9800:10150]"
		  "set y2range [100:1800]"
                  (format nil "set xtics ~A" (floor (/ numdatapoints 20)))
		  "set xtics nomirror"
		  "set ytics nomirror"
		  "set y2tics nomirror"
		  "set grid y"
		  "set title \"Mongoose V RTEMS Interrupt Distributions\""
		  "set xlabel \"Sample Number\""
		  "set ylabel  \"Int Interval(us)\""
		  "set y2label \"Int Duration(us)\""
		  "set key box"
		  "plot 'intdistro-cooked.txt' using 1:3 axes x1y1 title \"Interval\" with linespoints, \\"
		  "'intdistro-cooked.txt' using 1:2 axes x1y2 title \"Duration\" with linespoints pt 3"
		  "quit")))

    (with-open-stream (gpstr (sys:open-pipe "/usr/bin/gnuplot -geometry 1200x768 -persist" :direction :io :buffered nil))
       (mapc #'(lambda (s) 
		 (format gpstr "~A~%" (eval s))) gpscript) ))


The gnuplot datafile was generated prior to this code snippet, as was
the value in numdatapoints.  As you can see, this is a fairly
uninspired way of arranging things, but it should serve well enough.
The problem is the (eval) within mapc down at the bottom.  It works
well enough for the string literals, but because eval uses the "null
lexical environment", numdatapoints- which is a variable defined by a
surrounding let- could not be found.

I nosed around (apply) and (funcall), but they don't seem to be doing
the right kinds of things- what I think I really want is an
"eval-like" function which uses the local lexical environment.

I added '(declare (special numdatapoints))' just after the let where
numdatapoints was defined, which seems to have made (eval) happy.  Is
this reasonable- or at least not too horrible way to approach this
problem?

Thanks,

Greg Menke

From: Barry Margolin
Subject: Re: Fun with eval
Date: 
Message-ID: <A0pW7.13$Mv6.32432@burlma1-snr2>
In article <··············@europa.pienet>,
Greg Menke  <··········@mindspring.com> wrote:
>
>I'm consolidating some Lisp & shell script stuff we use to feed logic
>analyzer data to gnuplot, moving everything into Lisp.  Particularly,
>I want to put the gnuplot script into Lisp, so I can keep its
>definition alongside the code that generates the data- makes tweaking
>things easier.  I came up with the following
>
>
>(let ((gpscript '("set format y  \"%5.0f\""
>                  "set format y2 \"%5.0f\""
>		  "#set yrange  [9800:10150]"
>		  "set y2range [100:1800]"
>                  (format nil "set xtics ~A" (floor (/ numdatapoints 20)))
>		  "set xtics nomirror"
>		  "set ytics nomirror"
>		  "set y2tics nomirror"
>		  "set grid y"
>		  "set title \"Mongoose V RTEMS Interrupt Distributions\""
>		  "set xlabel \"Sample Number\""
>		  "set ylabel  \"Int Interval(us)\""
>		  "set y2label \"Int Duration(us)\""
>		  "set key box"
>		  "plot 'intdistro-cooked.txt' using 1:3 axes x1y1 title \"Interval\"
>with linespoints, \\"
>		  "'intdistro-cooked.txt' using 1:2 axes x1y2 title \"Duration\" with
>linespoints pt 3"
>		  "quit")))
>
>    (with-open-stream (gpstr (sys:open-pipe "/usr/bin/gnuplot -geometry
>1200x768 -persist" :direction :io :buffered nil))
>       (mapc #'(lambda (s) 
>		 (format gpstr "~A~%" (eval s))) gpscript) ))
>
>
>The gnuplot datafile was generated prior to this code snippet, as was
>the value in numdatapoints.  As you can see, this is a fairly
>uninspired way of arranging things, but it should serve well enough.
>The problem is the (eval) within mapc down at the bottom.  It works
>well enough for the string literals, but because eval uses the "null
>lexical environment", numdatapoints- which is a variable defined by a
>surrounding let- could not be found.
>
>I nosed around (apply) and (funcall), but they don't seem to be doing
>the right kinds of things- what I think I really want is an
>"eval-like" function which uses the local lexical environment.
>
>I added '(declare (special numdatapoints))' just after the let where
>numdatapoints was defined, which seems to have made (eval) happy.  Is
>this reasonable- or at least not too horrible way to approach this
>problem?

Why do you need to use EVAL at all?  Why don't you use the value of
NUMDATAPOINTS when you're building the gpscript list in the first place:

(let ((gpscript `("set format y \"%5.0f\""
                  ...
                  ,(format nil "set xtics ~A" (floor (/ numdatapoints 20)))
                  ...)))
  (with-open-stream (gpstr ...)
    (mapc #'(lambda (s)
              (format gpstr "~A~%" s)) gpscript)))



-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Greg Menke
Subject: Re: Fun with eval
Date: 
Message-ID: <m3ellhen7n.fsf@europa.pienet>
> 
> Why do you need to use EVAL at all?  Why don't you use the value of
> NUMDATAPOINTS when you're building the gpscript list in the first place:
> 
> (let ((gpscript `("set format y \"%5.0f\""
>                   ...
>                   ,(format nil "set xtics ~A" (floor (/ numdatapoints 20)))
>                   ...)))
>   (with-open-stream (gpstr ...)
>     (mapc #'(lambda (s)
>               (format gpstr "~A~%" s)) gpscript)))
> 

I don't.  I forgot about backquote and ,

Thanks,

Gregm
From: Barry Margolin
Subject: Re: Fun with eval
Date: 
Message-ID: <N%rW7.18$Mv6.29140@burlma1-snr2>
In article <··············@europa.pienet>,
Greg Menke  <··········@mindspring.com> wrote:
>> 
>> Why do you need to use EVAL at all?  Why don't you use the value of
>> NUMDATAPOINTS when you're building the gpscript list in the first place:
>> 
>> (let ((gpscript `("set format y \"%5.0f\""
>>                   ...
>>                   ,(format nil "set xtics ~A" (floor (/ numdatapoints 20)))
>>                   ...)))
>>   (with-open-stream (gpstr ...)
>>     (mapc #'(lambda (s)
>>               (format gpstr "~A~%" s)) gpscript)))
>> 
>
>I don't.  I forgot about backquote and ,

Backquote is just a shorthand.  Even without it you could write:

(list "set format y \"%5.0f\""
      (format nil "set xtics ~A" ...))

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Greg Menke
Subject: Re: Fun with eval
Date: 
Message-ID: <m3zo45uzp5.fsf@europa.pienet>
> >> 
> >> Why do you need to use EVAL at all?  Why don't you use the value of
> >> NUMDATAPOINTS when you're building the gpscript list in the first place:
> >> 
> >> (let ((gpscript `("set format y \"%5.0f\""
> >>                   ...
> >>                   ,(format nil "set xtics ~A" (floor (/ numdatapoints 20)))
> >>                   ...)))
> >>   (with-open-stream (gpstr ...)
> >>     (mapc #'(lambda (s)
> >>               (format gpstr "~A~%" s)) gpscript)))
> >> 
> >
> >I don't.  I forgot about backquote and ,
> 
> Backquote is just a shorthand.  Even without it you could write:
> 
> (list "set format y \"%5.0f\""
>       (format nil "set xtics ~A" ...))

Of course!  I knew I was missing something obvious.

Thanks,

Gregm
From: Paolo Amoroso
Subject: Re: Fun with eval
Date: 
Message-ID: <Z=oqPM45QRxgb==5iHOGzFStVFmo@4ax.com>
On 26 Dec 2001 13:30:56 -0500, Greg Menke <··········@mindspring.com>
wrote:

> I'm consolidating some Lisp & shell script stuff we use to feed logic
> analyzer data to gnuplot, moving everything into Lisp.  Particularly,

In case you are interested, `cllib', which is part of CLOCC (Common Lisp
Open Code Collection), includes a gnuplot interface:

  http://clocc.sourceforge.net


Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://web.mclink.it/amoroso/ency/README
[http://cvs2.cons.org:8000/cmucl/doc/EncyCMUCLopedia/]
From: Greg Menke
Subject: Re: Fun with eval
Date: 
Message-ID: <m3666r7a3f.fsf@europa.pienet>
Paolo Amoroso <·······@mclink.it> writes:

> 
> > I'm consolidating some Lisp & shell script stuff we use to feed logic
> > analyzer data to gnuplot, moving everything into Lisp.  Particularly,
> 
> In case you are interested, `cllib', which is part of CLOCC (Common Lisp
> Open Code Collection), includes a gnuplot interface:
> 
>   http://clocc.sourceforge.net


I looked at it, but didn't need anything that fancy.  If there were
any sort of variability in how I generate the graphs I'd probably use
it.

Gregm
From: ········@acm.org
Subject: Re: Fun with eval
Date: 
Message-ID: <ie1X7.16920$u93.3106278@news20.bellglobal.com>
Paolo Amoroso <·······@mclink.it> writes:
> On 26 Dec 2001 13:30:56 -0500, Greg Menke <··········@mindspring.com>
> wrote:
> 
> > I'm consolidating some Lisp & shell script stuff we use to feed logic
> > analyzer data to gnuplot, moving everything into Lisp.  Particularly,
> 
> In case you are interested, `cllib', which is part of CLOCC (Common Lisp
> Open Code Collection), includes a gnuplot interface:
> 
>   http://clocc.sourceforge.net

I have tried installing this with _zero_ success thus far.  There seem
to be a number of actions that need to be taken to get it installed
that are not documented in the documentation.  (Notably, how is it
supposed to locate $(TOP)/bin/run-lisp?)

The library looks to have interesting stuff in it, but installing it
is a challenge...
-- 
(concatenate 'string "cbbrowne" ·@sympatico.ca")
http://www.ntlug.org/~cbbrowne/spiritual.html
Rules of the Evil Overlord #217. "If I'm wearing the key to the hero's
shackles around  my neck and  his former girlfriend now  volunteers to
become my mistress and we are all alone in my bedchamber on my bed and
she offers  me a goblet of  wine, I will politely  decline the offer."
<http://www.eviloverlord.com/>