From: GP lisper
Subject: Data as Code; help a newbie for New Years!
Date: 
Message-ID: <slrndrg1ae.sfv.spambait@phoenix.clouddancer.com>
[it's long, just like baseball]

Over the Christmas break, I was parsing some baseball statistics.  I ended up with a datafile containing:

((162 ("STL" 0.3888889) ("TB" 0.59876543) ("CWS" 0.58641976) ("HOU" 0.5802469)
  ("OAK" 0.5802469) ("KC" 0.5740741) ("ATL" 0.42592594) ("DET" 0.56790125)
  ("BAL" 0.5617284) ("TOR" 0.4382716) ("COL" 0.45061728) ("CLE" 0.5493827)
  ("SF" 0.5493827) ("SEA" 0.45679012) ("BOS" 0.4691358) ("MIL" 0.4691358)
  ("CHC" 0.5308642) ("TEX" 0.52469134) ("FLA" 0.47530866) ("LAD" 0.47530866)
  ("CIN" 0.5185185) ("SD" 0.5185185) ("PIT" 0.4814815) ("MIN" 0.5185185)
  ("NYY" 0.5185185) ("NYM" 0.5123457) ("WSH" 0.5123457) ("ARI" 0.48765433)
  ("LAA" 0.48765433) ("PHI" 0.5))
 (161 ("STL" 0.38509318) ("TB" 0.5962733) ("CWS" 0.5838509) ("HOU" 0.57763976)
  ("KC" 0.57763976) ("OAK" 0.57763976) ("ATL" 0.42236024) ("DET" 0.5652174)
  ("TOR" 0.4409938) ("BAL" 0.5590062) ("SF" 0.55279505) ("COL" 0.45341614)
  ("SEA" 0.45341614) ("CLE" 0.54658383) ("MIL" 0.46583852) ("BOS" 0.47204968)
  ("FLA" 0.47204968) ("CHC" 0.5279503) ("SD" 0.5217391) ("TEX" 0.5217391)
  ("LAD" 0.47826087) ("PIT" 0.47826087) ("NYY" 0.5217391) ("MIN" 0.51552796)
  ("NYM" 0.51552796) ("LAA" 0.48447204) ("CIN" 0.51552796) ("ARI" 0.49068323)
  ("WSH" 0.50931674) ("PHI" 0.49689442))
 (160 ("STL" 0.38125) ("TB" 0.59375) ("CWS" 0.58125) ("HOU" 0.58125)
  ("KC" 0.58125) ("OAK" 0.58125) ("ATL" 0.41875) ("DET" 0.5625) ("TOR" 0.44375)
  ("BAL" 0.55625) ("SF" 0.55) ("COL" 0.45) ("SEA" 0.45625) ("CLE" 0.54375)
  ("FLA" 0.46875) ("MIL" 0.46875) ("CHC" 0.53125) ("BOS" 0.475) ("NYY" 0.525)
...))

I wanted to plot this, and see the data as mere unordered X and
multi-Y pairs with Y labels. So simply read, parse and stream the X-Y
pairs into RTP [an old X real-time plotter].  I didn't need real-time,
and RTP is only a single line plotter so it requires extra help for
static multiline plots, so I needed to stick the parsed data into some
temporary arrays into order to feed RTP later.  The woods just don't
have Internet when you forget gnuplot on the laptop.  A new RTP would
be a great outcome of one of the new CL graphics packages.

So I thought that lisp could deal with just taking those strings,
e.g. "PIT", "TOR", "ATL", and coerce them into simple-vectors.  It
seemed like only a few lines to read in all the data, parse it up and
plot.  However the cmucl debugger kept showing me that "CHC" was being
turned into the simple-vector named \(#C#H#C\) [something of that
order from my memory] not the simple-vector named CHC shown in the
top-level stack.  That attempted code has passed on, I wanted results
and put in ugly CONDs which look like:

------------------------------------------------------------------

(with-open-stream (rtp (ext:process-input (ext:run-program "rtp" nil :wait nil :input :stream)))

; setup the plot box, Real-Time Plotting not needed here (gnuplot fill-in)
  (format rtp "~%~A ~A" 10 0)
  (format rtp "~%~A ~A" 10 1)
  (format rtp "~%~A ~A" 162 1)
  (format rtp "~%~A ~A" 162 0)
  (format rtp "~%~A ~A" 10 0)


(let ((data-set) (x)
      (ARI (make-array 170 :initial-element nil))
      (ATL (make-array 170 :initial-element nil))
------------------------------------------------------------------

ugh, I was wishing for an on-the-fly method here, even if it meant
global vars.  I suppose if I just created a lisp of array
names....hmm, a two pass flexible plotter....

------------------------------------------------------------------
      (TOR (make-array 170 :initial-element nil))
      (WSH (make-array 170 :initial-element nil)))

  (with-open-file (daters "/home/mlb/season.data" :direction :input)
    (setf data-set (read daters)))

  (dolist (node data-set) nil
	  (setf x (car node))
	  (dolist (point (rest node)) nil
		  (let ((sv (car point)))
		    (cond
		      ((string-equal sv "ARI") (setf (svref ARI x) (cadr point)))
		      ((string-equal sv "ATL") (setf (svref ATL x) (cadr point)))
		      ((string-equal sv "BAL") (setf (svref BAL x) (cadr point)))
------------------------------------------------------------------

now when I had tried here something similar to

(setf (svref (coerce sv 'simple-vector) x) (cadr point))

I never worked out the correct syntax, which can nicely be used
elsewhere in this program.


   So c.l.l.,  How Do You Do It?


------------------------------------------------------------------
		      ((string-equal sv "TEX") (setf (svref TEX x) (cadr point)))
		      ((string-equal sv "TOR") (setf (svref TOR x) (cadr point)))
		      ((string-equal sv "WSH") (setf (svref WSH x) (cadr point)))))))


; plot all data here

(dotimes (n 164)
  (let ((y (svref LAA n)))
    (when (floatp y) 
      (format rtp "~%~A ~A" n y))))
(format rtp "~%~A ~A" 162 0)
(format rtp "~%~A ~A" 10 0)

------------------------------------------------------------------
and in this last section, run over the various arrays and plot it all
up.

Since I'm home, have gnuplot in multicolor, I'd like to see a small
smart lisp plotter in action, before I'm back into conds forever.


TIA

-- 
email is a spam-trap, reply in c.l.l please

If you don't like LOOP, how do you feel about DOLIST ?

From: Carl Taylor
Subject: Re: Data as Code; help a newbie for New Years!
Date: 
Message-ID: <xyUtf.393396$zb5.198202@bgtnsc04-news.ops.worldnet.att.net>
"GP lisper" <········@CloudDancer.com> wrote in message 
····························@phoenix.clouddancer.com...
> [it's long, just like baseball]

[...]

> So I thought that lisp could deal with just taking those strings,
> e.g. "PIT", "TOR", "ATL", and coerce them into simple-vectors.  It
> seemed like only a few lines to read in all the data, parse it up and
> plot.  However the cmucl debugger kept showing me that "CHC" was being
> turned into the simple-vector named \(#C#H#C\) [something of that
> order from my memory] not the simple-vector named CHC shown in the
> top-level stack.

Note that a string like "PIT" *is* a vector of objects called characters 
that have the denotation #\x.

So are you saying you just want to get rid of the double quotes that denote 
a Lisp object of type string? And thereby transform "PIT" into the symbol 
PIT?  If so, here is a function to run your data through before passing it 
on to the plotter.  Or just build an <intern> or <read-from-string> into 
your existing code.

(defun tr-str-to-sym (in-list)
  (cond ((null in-list) nil)
           ((stringp in-list) (intern in-list))
           ((atom in-list) in-list)
           (t
            (cons (tr-str-to-sym (car in-list))
                     (tr-str-to-sym (cdr in-list))))))

Carl Taylor 
From: GP lisper
Subject: Re: Data as Code; help a newbie for New Years!
Date: 
Message-ID: <slrndrgft1.sfv.spambait@phoenix.clouddancer.com>
On Sun, 01 Jan 2006 17:45:01 GMT, <··········@att.net> wrote:
>
> Note that a string like "PIT" *is* a vector of objects called characters 
> that have the denotation #\x.

Ah, I probably read that once too, thanks for the reminder.


> So are you saying you just want to get rid of the double quotes that denote 
> a Lisp object of type string? And thereby transform "PIT" into the symbol 
> PIT?  If so, here is a function to run your data through before passing it 
> on to the plotter.  Or just build an <intern> or <read-from-string> into 
> your existing code.
>
> (intern in-list)

OK, this would create a symbol the first time [which I current do in
the LET], and perhaps read-from-string later would work out
recognizing the previously created symbol.  Thanks for the intern
pointer, Grahams ACL has a section about it that looks like it will
help me.  I'll try it out tomorrow and followup if I still don't get
it working.

-- 
If you don't like LOOP, how do you feel about DOLIST ?