NEWBIE: bug in (count)?

Q&A's, tips, howto's
Locked
axtens
Posts: 28
Joined: Mon Apr 06, 2009 12:23 pm
Location: Perth, WA Australia
Contact:

NEWBIE: bug in (count)?

Post by axtens »

I've often thought it would be good to learn Lisp and so I'm trying newLISP (despite what some purists might argue).

I have problem already. In the following code I tests whether 'j' is a list, and if so I ask for a count of it and print the result. Every time I run it, it fails with a "ERR: list expected in function count : nil".

c:\temp\data is a text file containing crlf-delimited lines of two tab-delimited items.

Here's the code

Code: Select all

(dolist 
  (i 
    (parse 
      (read-file "c:\\temp\\data") "\r\n"
    )
  ) 
	(begin
		(set 'j (reverse (parse i "\t")))
		(print j "\n")
		(when (list? j) 
			(print (count j) "\n")
		)
		(set 'k (j 0))
		(set 'l (j 1))
	)
)
What is my non-Lisp mind not seeing?

Kind regards,
Bruce.

P.S. Is there a way of assigning (j 0) to k and (j 1) to l in one statement, i.e. does newLISP permit double (or more) assignment?

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Oops, answered the question here:

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2727

And you seems to want length instead of count (which takes 2 lists as arguments)

Code: Select all

(dolist
  (i
    (parse
      (read-file "C:\\Programme\\newlisp\\Test1.txt") "\r\n"
    )
  )
   (begin
      (set 'j (reverse (parse i "\t")))
      (print j "\n")
      (when (list? j)
         (print (length j) "\n")
      )
      (if (>(length j)0)(set 'k (j 0) 'l (j 1)))
   )
)
Hans-Peter

axtens
Posts: 28
Joined: Mon Apr 06, 2009 12:23 pm
Location: Perth, WA Australia
Contact:

Post by axtens »

HPW wrote:And you seems to want length instead of count (which takes 2 lists as arguments)
Umm ... er ... yes, I did want (length); finally read the friendly manual. Thanks.

Kind regards,
Bruce.

Locked