I ended up making the code less pretty. Looks like the suffix ".0" must
only be added if the number is not already in floating point format.


(setq J

 (pipe

   (in '("sh" "-c" "curl -s
https://api.iextrading.com/1.0/stock/aapl/chart/3m";)

     (while

      (case (echo "close" "volume" "unadjustedVolume")

        (("close" "volume" "unadjustedVolume")

          (prin @)

          (prin (echo "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))

          (setq Sfx ".0")

          (while (member (peek) (list "0" "1" "2" "3" "4" "5" "6" "7" "8"
"9" "."))

            (if (= "." (peek)) (setq Sfx ""))

            (prin (char)))

          (prin Sfx)

          T)

       )))


I am sure there must a better way to do the lengthy "0"..."9" that I've
done :)


Regards,

Kashyap

On Tue, May 7, 2019 at 9:33 AM <andr...@itship.ch> wrote:

> > You would also include "[" in the 'echo' arguments, then check it with
> >
> >    (use S
> >       (while
> >          (prin
> >             (setq S
> >                (echo "[" "volume" "unadjustedVolume") ) )
> >          (if (= "[" S)
> >             (... step through the elements ...)
> >             (echo ",")
> >             (prin ".0,") ) )
> >
>
> I usually use
>   (case (echo "[" "volume" "unadjustedVolume")
>      ("["
>         ...)
>      (("volume" "unadjustedVolume")
>         (echo ",")
>         (prin ".0,") )
>      (NIL
>         ... handle error case, if you like ...)
>      (T
>          ... general else case ) )
>
> No additional variable needed, and one can have readable code even when
> handling many cases.
> Easy to additionally handle NIL returned from (echo) - probably doesn't
> matter (too unlikely) when processing a file, but probably handy when
> processing a input stream from network (e.g. curl).
>
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to