Sujet : Re: Python syntax in Lisp and Scheme
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 09. Jul 2025, 16:51:45
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104m36f$abo5$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Frode Vatvedt Fjeld wrote:
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.
Why would any human want to match Python?
Gauche Scheme
(vector-fill! vec 99)
(vector-map! (constantly 88) vec)
Multiply each element by 2:
(vector-map! (cut * 2 <>) vec)
Sum the elements in the vector.
(use scheme.vector)
(vector-fold + 0 vec)
Another way to sum.
(use gauche.sequence)
(fold + 0 vec)
Make a list containing the positive numbers in the vector.
(use gauche.sequence)
(filter positive? vec)
Find location of first negative number.
(use scheme.vector)
(vector-index negative? vec)