Hi,
While working on the json library I had to write a string to float
function. In a list of characters when I encounter a digit, I'd like to go
over the rest of the list and consume all the digits (and possibly a
period) that form a number. I'd appreciate some feedback from a Lispiness
and PicoLispiness point of view :)
On a related note - Is chopping a reasonable way to break an input file
into characters while parsing? I mean, would each character now occupy one
cell?


(de isNum (n) (or (= "." n) (num? (format n))))


(de read-num (n lst)

 (let (c 0 # count of digits found

       p F # period found?

       ds (pack n

               (make

                (while (isNum (car lst))

                 (ifn p (setq p (= "." (car lst))))

                 (setq c (inc c))

                 (link (pop lst))

                (setq lst (cdr lst)))))

        result  (if p ds (pack ds ".0"))) # if a period was not present
then add a ".0"

        (list c result)))



(println (read-num 1 (chop "234.45abc"))) => (6 "1234.45")




Regards,

Kashyap

Reply via email to