error in let function

Q&A's, tips, howto's
Locked
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

error in let function

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post 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]

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The bug has been fixed! I forgot to mention that in the changes file.

Lutz

Locked