Scheme
(define vector-fill!
(lambda (v x)
(let ((n (vector-length v)))
(do ((i 0 (+ i 1)))
((= i n))
(vector-set! v i x)))))
Python
def vector_fill(v, x):
for i in range(len(v)):
v[i] = x
To me the Python code is easier to read, and I can't possibly fathom
how somebody could think the Scheme code is easier to read. It truly boggles my mind. [..]
The scheme example can only have been written by someone who is on the
outset determined to demonstrate that sexp-syntax is complicated. This
is how I'd write it in Common Lisp:
(defun vector-fill (v x)
(dotimes (i (length v))
(setf (aref v i) x)))
As you can see, it matches the python example quite closely.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 21:07:09 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
11 files (21,026K bytes) |
| Messages: | 194,568 |