William James
12/1/2015 11:19:00 PM
WJ wrote:
> Barry Margolin wrote:
>
> > The Generators and Collectors macros described in Appendix B
> > of CLtL2 also provide this convenience and are much more
> > Lisp-like. It's too bad they weren't around when LOOP was
> > gaining popularity, and I think they're a better way to go.
> > But LOOP is what I got used to, and its popularity is why it
> > got elevated into the ANSI standard.
>
> CLtL2, appendix B:
>
> > (let ((x (generator (scan '(1 2 3 4)))))
> > (with-output-to-string (s)
> > (loop (prin1 (next-in x (return)) s)
> > (prin1 (next-in x (return)) s)
> > (princ "," s))))
> > => "12,34,"
Ocaml:
open Printf;;
let buf = Buffer.create 99 and
x = Stream.of_list [1;2;3;4;-5] in
(try
while true do
bprintf buf "%+d" (Stream.next x) ;
bprintf buf "%+d" (Stream.next x) ;
Buffer.add_string buf ", "
done
with Stream.Failure -> ()) ;
Buffer.contents buf ;;
"+1+2, +3+4, -5"
--
In the latter case, arrests are made, not so much for what has been done, as
for what probably would be done. The latter is more for the preventive, and
less for the vindictive, than the former. --- A. Lincoln, Letter to Erastus
Corning, June 12, 1863