Page 1 of 1

error in let function

Posted: Fri Nov 14, 2003 7:00 pm
by eddier
I'm pulling from a comma separated file.

"L" looks like '("\"AR335-A\"","\"3.00\"","\"Sur.Art Hist./Appre.\"","\"8:00\"","\"8:50\"","\"M W F\"","\"A\"","\"35\"","\"DOWDY\"")

Code: Select all

(define (get-period L)
  (let ((l (append (trim (nth 3 L) {"}) "-" (trim (nth 4 L) {"}))))
    l))
gives a segmentation fault

Code: Select all

(define (get-period L , l)
  (setq l (append (trim (nth 3 L) {"}) "-" (trim (nth 4 L) {"}))))
works fine. I wonder if there is a problem in the "let" function. However, I have several "let"s through out the program that are giving any problem.

Eddie

Posted: Fri Nov 14, 2003 8:14 pm
by Lutz
I cannot repeat the crash, instead I am getting the following error on both functions.

string expected : (nth 3 L)
called from user defined function get-period

Because the third element of L is a comma, not a string

(on version 7.3.1)

Lutz

Posted: Fri Nov 14, 2003 8:41 pm
by eddier
I made the mistake of copying and pasting the csv record without deleting the commas.

Should be no commas in the list.

Eddie

Posted: Sat Nov 15, 2003 2:00 pm
by Lutz
Thanks Eddie for catching this. It happened when returning from 'let' one of it's local vars. This is fixed and will be in the development release on this weekend.

This bug was in there since 'let's introduction 3 years ago, and nobody else seems to have run into it :-)

Actually you could have just returned the result of 'append'

(define (get-period L)
(append (trim (nth 3 L) {"}) "-" (trim (nth 4 L) {"})))

perhaps this was just a snippet from a bigger portion of code.

Lutz

Posted: Mon Nov 17, 2003 4:43 pm
by eddier
perhaps this was just a snippet from a bigger portion of code.
Yes. I needed a local variable to keep up with the time a period began and ended. I'm going to use the local variable in a case statement.

I've used a bunch of let statements before without this kind of error. Subtle bug!

Eddie[/quote]

Posted: Tue Nov 18, 2003 12:37 am
by Lutz
The bug has been fixed! I forgot to mention that in the changes file.

Lutz