円を作ってみた

(define (make-circle radius)
  (let rows ((r 0) (row '()))
    (if (= r (+ (* 2 radius) 1))
	(reverse row)
	(rows (+ r 1)
	      (cons
	       (let columns ((c 0) (col '()))
		 (if (= c (+ (* 2 radius) 1))
		     (reverse col)
		     (columns (+ c 1)
			      (cons
			       (if (>
				    (magnitude
				     (make-rectangular
				      (- r radius)
				      (- c radius)))
				    radius)
				   #\space #\+) col)))) row)))))

(define (print-circle circle)
  (for-each (lambda (row) (print (list->string row))) circle))

gosh> (print-circle (make-circle 10))

実行例


+
+++++++++
+++++++++++++
+++++++++++++++
+++++++++++++++++
+++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++

                                        1. +

+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++
+++++++++++++++++
+++++++++++++++
+++++++++++++
+++++++++
+

追記

Rubyワンライナーにしてみた(ぉ

puts lambda{|r|(-r..r).map{|x|(-r..r).map{|y|(x*x+y*y>r*r)?" ":"+"}.join + "\n"}}[10]

さらに追記

上のワンライナーと同じ発想でSchemeでも

(use srfi-1)
(define (printcircle r)
  (let ((range (iota (+ (* 2 r) 1) (- r) 1)))
    (for-each
     (lambda (x)
       (for-each
	(lambda (y)
	  (display
	   (if (> (+ (* x x) (* y y)) (* r r)) #\space #\+))) range)
       (newline)) range)))