unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: Python syntax in Lisp and Scheme
@ 2012-12-02  9:37 WJ
  0 siblings, 0 replies; only message in thread
From: WJ @ 2012-12-02  9:37 UTC (permalink / raw)
  To: help-gnu-emacs

Re: Python syntax in Lisp and Scheme

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.

Racket:

(define vec (vector 2 3 4 5))
(vector-fill! vec 0)
vec
==> '#(0 0 0 0)

(vector-set*! vec  3 'a  2 'b)
vec
==> '#(0 0 b a)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-12-02  9:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-02  9:37 Python syntax in Lisp and Scheme WJ

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).