William James
11/27/2015 6:37:00 PM
WJ wrote:
> Kent M. Pitman wrote:
>
> > (defun write-list (elements)
> > (loop for comma? first nil then t
> > for element in elements
> > when comma?
> > do (write-string ", ")
> > do (write element)))
>
>
> Gauche Scheme:
>
> Using recursion:
>
> (define (write-list items)
> (let go ((sep ""))
> (when (pair? items)
> (display sep)
> (display (pop! items))
> (go ", "))))
>
> gosh> (write-list (iota 8))
> 0, 1, 2, 3, 4, 5, 6, 7#<undef>
>
>
> Using while:
>
> (define (write-list items)
> (while (pair? items)
> (display (pop! items))
> (when (pair? items) (display ", "))))
>
>
> Using pair-for-each:
>
> (use srfi-1 :only (pair-for-each))
>
> (define (write-list items)
> (pair-for-each
> (^x (display (car x)) (when (pair? (cdr x)) (display ", ")))
> items))
Ocaml:
let rec write_list print = function
[] -> ()
| x::(y::_ as rest) -> print x; print_string ", "; write_list print rest
| [x] -> print x ;;
write_list print_int [2;3;4];;
===>
2, 3, 4
--
[Jesse Jackson] would spit into the food of white patrons he hated and then
smilingly serve it to them. He did this, he said, "because it gave me
psychological gratification." -- Life Magazine, 1969-11-29