From: Nandan
Subject: homework help
Date: 
Message-ID: <Pine.GSO.4.40.0504241616530.17643-100000@omicron.cse.ohio-state.edu>
Hi all, this isn't really *lisp homework*, rather a project I'm trying to implement in lisp.
OTOH the deadline is close ;-) and I'm stuck.

I get the error
  Backtrace:
  0: ("DEFUN GETF" :FILE :FILE)[:OPTIONAL]
  1: (READDATA #<Stream for file "lisp.out">)
 --more--

On evaluating
 (readdata (open "lisp.out"))

Where

(defun readdata (from)
  (with-open-file (s from)
    (dolist (line (read s))
      (print line)
      (let ((fname    (getf line :FILE))
	    (size     (getf line :SIZE))
	    (topics   (getf line :TOPICS))
	    (numtok   (getf line :TOKENS))
	    (places   (getf line :PLACES))
	    (trainp   (getf line :TRAIN))
	    (pairslis (read s))
	    (fobj nil))

	(setf fobj (gethash fname N))
	(setf fobj (make-file-info :name fname :numtoks numtok :topics topics
				   :places places :trainp trainp
				   :hshtok (make-hash-table :size size)))
	(setf (gethash fname N) fobj)
	(let ((wi))

	  (dolist (tok pairslis)
	    (setf wi (make-token-info :count (cdr tok)))
	    (setf (gethash (car tok) (file-info-hshtok fobj)) wi)
	    (notemaxpair tok))
	  (setf (file-info-maxpair fobj) (getmaxpair)))))))


lisp.out is a perl generated file like so:

(:FILE article1 :TOKENS 8 :TOPICS () :PLACES () :TRAIN nil )
((financial 1)(cent 1)(dividend 1)(cityfed 2)(says 1)(qtrly 1)(brief 1)(financi 1))

That is, one plist of file information, and one list of (word count) pairs.

Somehow the error seems to be the same as if I'd asked for (getf :FILE :FILE), so
I wrote the following to test what was happening..

If I use the following:

	(getf (tst "lisp.out" ) :FILE)

with

(defun tst (name)
  (with-open-file (s name)
    (read s)))

I get ARTICLE1 as expected. What am I doing wrong?

TIA.

-- 
Nandan Bagchee

 So I think people who are mature and experienced, with a business background,
 may be overrated. We used to call these guys 'newscasters', because they had
 neat hair and spoke in deep, confident voices, and generally didn't know much
 more than they read on the teleprompter.

		-- Paul Graham

From: Nandan
Subject: Re: homework help
Date: 
Message-ID: <Pine.GSO.4.40.0504241634250.17643-100000@omicron.cse.ohio-state.edu>
Duh! dolist binds line to each elem of (read s).
I guess I need some other iter form.

Thanks for being there :-)

On Sun, 24 Apr 2005, Nandan wrote:

>Hi all, this isn't really *lisp homework*, rather a project I'm trying to implement in lisp.
>OTOH the deadline is close ;-) and I'm stuck.
>
>I get the error
>  Backtrace:
>  0: ("DEFUN GETF" :FILE :FILE)[:OPTIONAL]
>  1: (READDATA #<Stream for file "lisp.out">)
> --more--
>
>On evaluating
> (readdata (open "lisp.out"))
>
>Where
>
>(defun readdata (from)
>  (with-open-file (s from)
>    (dolist (line (read s))
>      (print line)
>      (let ((fname    (getf line :FILE))
>	    (size     (getf line :SIZE))
>	    (topics   (getf line :TOPICS))
>	    (numtok   (getf line :TOKENS))
>	    (places   (getf line :PLACES))
>	    (trainp   (getf line :TRAIN))
>	    (pairslis (read s))
>	    (fobj nil))
>
>	(setf fobj (gethash fname N))
>	(setf fobj (make-file-info :name fname :numtoks numtok :topics topics
>				   :places places :trainp trainp
>				   :hshtok (make-hash-table :size size)))
>	(setf (gethash fname N) fobj)
>	(let ((wi))
>
>	  (dolist (tok pairslis)
>	    (setf wi (make-token-info :count (cdr tok)))
>	    (setf (gethash (car tok) (file-info-hshtok fobj)) wi)
>	    (notemaxpair tok))
>	  (setf (file-info-maxpair fobj) (getmaxpair)))))))
>
>
>lisp.out is a perl generated file like so:
>
>(:FILE article1 :TOKENS 8 :TOPICS () :PLACES () :TRAIN nil )
>((financial 1)(cent 1)(dividend 1)(cityfed 2)(says 1)(qtrly 1)(brief 1)(financi 1))
>
>That is, one plist of file information, and one list of (word count) pairs.
>
>Somehow the error seems to be the same as if I'd asked for (getf :FILE :FILE), so
>I wrote the following to test what was happening..
>
>If I use the following:
>
>	(getf (tst "lisp.out" ) :FILE)
>
>with
>
>(defun tst (name)
>  (with-open-file (s name)
>    (read s)))
>
>I get ARTICLE1 as expected. What am I doing wrong?
>
>TIA.
>
>

-- 
Nandan Bagchee

 So I think people who are mature and experienced, with a business background,
 may be overrated. We used to call these guys 'newscasters', because they had
 neat hair and spoke in deep, confident voices, and generally didn't know much
 more than they read on the teleprompter.

		-- Paul Graham
From: Kent M Pitman
Subject: Re: homework help
Date: 
Message-ID: <uwtqr5244.fsf@nhplace.com>
Nandan <·······@cse.ohio-state.edu> writes:

> Somehow the error seems to be the same as if I'd asked for (getf :FILE :FILE), ...

I don't have time to debug this in detail, but you're not helping your
situation by bad variable naming.

Unrelated to the problem, (DOLIST (LINE (READ S)) ...) has the problem that it hints
that you think READ reads a "line" of data, when in fact it reads an expression. 
Were the file to contain
 (FOO) (BAR) (BAZ)
it would read three expressions from one line as three separate iterations of the
DOLIST form.  If there were one expression like
 (FOO
  BAR)
it would read one expression off of two lines in a single iteration of the DOLIST form.

More closely related, perhaps is your recycling a variable (fobj)
instead of making a new one when it apparently holds several different
and unrelated kinds of data.  I'd make a new variable if I were you.
There's no real cost to more variables in modern compiled code; in
fact, in some compilers that have a hard time doing good data flow
analysis, you may be helping the compiler by making more variables
with shorter lifetimes.

In some implementations, there's a debugger command that will take 
you to the point of execution in your errant stack frame.  But if there
isn't in what you're using, I recommend inserting some PRINT statements
in the code and/or using TRACE to narrow in on the point of the error:
e.g.,

 (PRINT `(POINT 1 FOBJ = ,FOBJ N = ,N) *TRACE-OUTPUT*)

allows you to see that code reached a certain point and what the value of
a variable is.
From: Wade Humeniuk
Subject: Re: homework help
Date: 
Message-ID: <ApUae.89922$7Q4.12551@clgrps13>
Nandan wrote:

> (:FILE article1 :TOKENS 8 :TOPICS () :PLACES () :TRAIN nil )
> ((financial 1)(cent 1)(dividend 1)(cityfed 2)(says 1)(qtrly 1)(brief 1)(financi 1))
> 
> That is, one plist of file information, and one list of (word count) pairs.
> 

Modify your perl to output lines like ---

#s(file-info :name article :numtoks 8 :topics nil :places nil :trainp nil
              :token-info
              ((financial 1)
                (cent 1)
                (dividend 1)
                (cityfed 2)
                (says 1)
                (qtrly 1)
                (brief 1)
                (financi 1)))

Then redefine your file-info defstruct to match.  Then do a simple looping
read and inserting into a hash-table.  Forget about the hshtok field being
a hash table in the struct and just store the token-info as an association list.

Wade