Basically, newLISP claims that two strings, that are identical, are not.
Given this input file named "test.csv":
Code: Select all
Date, Type, Net,
"11/22/2008","Web Accept Payment Received","15.00",
Code: Select all
'Web Accept Payment Received' vs 'Web Accept Payment Received'
data-type=Web Accept Payment Received, filter-type=Web Accept Payment Received
(!= date-type filter-type)=true
0 27
When printing the contents of those variables, they appear identical. I even iterated over each character and verified they were the same ASCII value. However, when asking for the length, newLISP claims data-type is 0 characters in length, and when checking equality (as shown above), it fails.
Here is the script so far (it's not complete), see the part where it says "BUG HERE":
Code: Select all
#!/usr/bin/newlisp
; =============
; = configure =
; =============
(set 'csv-delimiter ",")
(set 'header-date "Date")
(set 'header-amount "Net")
(set 'header-type "Type")
; filters
(set 'filter-type "Web Accept Payment Received")
(set 'filter-min-amount 15)
(set 'filter-max-amount 20)
; ============
; = end conf =
; ============
; --------------
(context 'DataStore)
(context MAIN)
; --------------
(define (fail) (apply println (args)) (exit 1))
(define-macro (fail-on-nil) (doargs (arg) (if (nil? (eval arg)) (fail arg " is nil"))))
(define-macro (paras)
(join (map (lambda (x)
(string x "=" (eval x))
) (args)) ", ")
)
(set 'csv-input-file (main-args 2))
(if-not csv-input-file (fail "usage: ./" (main-args 1) " <paypal>"))
(if-not (file? csv-input-file) (fail "no such file: " csv-input-file))
(if-not (regex "(.*)\.csv" csv-input-file) (fail "not a csv file: " csv-input-file))
(set 'csv-output-file (append $1 "-out.csv"))
(set 'fin (open csv-input-file "r"))
(set 'fout (open csv-output-file "w"))
(set 'header-list (map trim (parse (read-line fin) csv-delimiter)))
; set the indexes
(set 'index-date (find header-date header-list))
(set 'index-amount (find header-amount header-list))
(set 'index-type (find header-type header-list))
(fail-on-nil index-type index-amount index-date)
; write the header
(write-line fout (append "Date" csv-delimiter " Copies Sold" csv-delimiter " "))
(while (read-line fin)
(set 'data-list (map (fn (x) (trim x "\"")) (parse (current-line) csv-delimiter)))
(set 'data-date (data-list index-date))
(set 'data-type (data-list index-type))
(set 'data-amount (float (data-list index-amount)))
(fail-on-nil data-date data-amount data-type)
;; BUG HERE
(println "'" data-type "' vs '" filter-type "'")
(println (paras data-type filter-type))
(println (paras (!= date-type filter-type)))
(println (length date-type) " " (length filter-type))
; (dostring (c data-type) (println c " - " (char c)))
; (println)
; (dostring (c filter-type) (println c " - " (char c)))
(exit)
;; END BUG
(if (and (= (length date-type) (length filter-type)) (>= data-amount filter-min-amount) (<= data-amount filter-max-amount))
(begin
(println data-date " " data-amount)
(DataStore data-date (+ (if $it $it 0) 1))
)
(println "skipping " data-date " $" data-amount)
)
)
(println "result: " (DataStore))
(close fin)
(close fout)
(exit)