Earlier quoted context omitted.
Hmm. In many walks of life, popular != best. In fashion, cars, investing, and to some extent cooking, for example, the top performing adherent is doing things differently than the crowd. Lisp code can be very readable, but it takes a few years to learn how to write it that way. I spent many years in Perl 5 myself, and I found Common Lisp tricky at first but ultimately very satisfying. Two jedi mind tricks for the beg…
>This is what you might code, which I humbly submit to you is very readable: It's not, if that's a real life example. There is no context for what the data is, like a variable names.
You could use a struct or a class which would give you accessor functions, and would be better for a real program.
You setup a struct:
(defstruct bar date open high low close vol)
And this would be a one-time conversion of the data: (mapcar (lambda (b)
(apply 'make-bar
(mapcan 'list '(:date :open :high :low :close :vol) b)))
cl-user::*spy2006*)
Then you can access the elements with nicer names: (bar-date bar)
(bar-high bar)
...etc...
(If you use DEFCLASS you can do a few more things.)That would make the revised COMBINE-BARS look like the following, which has more context, and would yield a BAR struct back.
(defun combine-bars (bars)
"Summarize a sequence of BARS into one bar."
(let ((opening-bar (first bars))
(closing-bar (car (last bars))))
(series::let ((zbars (scan 'list bars)))
(make-bar :date (bar-date opening-bar)
:open (bar-open opening-bar)
:high (collect-max (map-fn 'float #'bar-high zbars))
:low (collect-min (map-fn 'float #'bar-low zbars))
:close (bar-close closing-bar)
:vol (collect-sum (map-fn 'integer #'bar-vol zbars))))))
(edit: added revised combine-bars)