William James
10/30/2015 4:06:00 PM
WJ wrote:
> Frank Buss wrote:
>
> > Just a simple example. If I want to create a square, I could write it like
> > this:
> >
> > (iterate 4
>
>
> CL does not have "iterate".
>
>
> > (iterate 4 (princ "*"))
> > (terpri))
> >
> > and the output:
> >
> > ****
> > ****
> > ****
> > ****
> >
> > If you want to specify the expression for outputting a character and for
> > newline, but you don't want to write every time the nested structure, it
> > would be a good idea to implement it as a macro:
> >
> > (defmacro square (n one-element newline)
> > `(iterate ,n
> > (iterate ,n ,one-element)
> > ,newline))
> >
> > Then you can use it like this:
> >
> > CL-USER > (square 3 (princ "x") (format t "~%"))
> > xxx
> > xxx
> > xxx
>
> Gauche Scheme:
>
> (define (square n display-element newline)
> (dotimes (n)
> (dotimes (n) (display-element))
> (newline)))
>
> gosh> (square 4 (cut display #\*) newline)
> ****
> ****
> ****
> ****
MatzLisp (Ruby):
def square n, display_element, newline
n.times{ n.times{ display_element.call}; send newline}
end
square 5, proc{print :*}, :puts
*****
*****
*****
*****
*****
--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot