guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: return value of `string-set!'


From: Taylan Ulrich B.
Subject: Re: return value of `string-set!'
Date: Thu, 15 Aug 2013 22:22:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)

Alexandru Cojocaru <address@hidden> writes:

> (define (make-copy str)
>  (let ((s (string-copy str)))
>   (begin
>     (string-set! s 0 #\a)
>     s)))

FYI the `begin' there is redundant.

(define (make-copy str)
  (let ((s (string-copy str)))
    (string-set! s 0 #\a)
    s))

This is idiomatic Scheme code; it makes it obvious that we're 1) getting
a value, 2) doing something to it, 3) returning it.  It is immediately
obvious code, in contrast to the one-liner that relies on a procedure
meant for mutating an object to also return that object (which is one
sensible choice for its return value, but not immediately obvious, or
the only choice, or inherently logical).  Of course this is all
subjective, and there could have been, for example, a convention that
all object-mutating procedures return the object they mutate, but that
is simply not the tradition/idiom; it's best to get used to the
established Scheme style. :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]