Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #168: le0: no carrier: transceiver cable problem?


comp / comp.lang.lisp / Re: Python syntax in Lisp and Scheme

SubjectAuthor
o Re: Python syntax in Lisp and SchemeB. Pym

1
Subject: Re: Python syntax in Lisp and Scheme
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 29 Jun 2024 04:25 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Python syntax in Lisp and Scheme
Date: Sat, 29 Jun 2024 04:25:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <v5o2ck$3p228$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 29 Jun 2024 06:25:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b5aa46dffd0f60f90c7603126cd696d3";
logging-data="3967048"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gkHEJS57BeDdOIkrvOYgL"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:sfcOWB8BCmkAoVWH1AmZnkJjWZs=
View all headers

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?

;; Racket
(define (vec-fill! v x)
(vector-map! (const x) v))

;; Gauche Scheme
(define (vec-fill! v x)
(vector-map! (lambda _ x) v))

(define vec (vector 2 3 4))

(vec-fill! vec 88)

vec
===>
#(88 88 88)

However, vector-fill! is already provided.

(vector-fill! vec 99)

vec
===>
#(99 99 99)

Multiply each element by 2:

(vector-map! (lambda(n) (* 2 n)) vec)

vec
===>
#(198 198 198)

1

rocksolid light 0.9.8
clearnet tor