[Top][All Lists]

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

Re: return value of `string-set!'

From: William ML Leslie
Subject: Re: return value of `string-set!'
Date: Thu, 15 Aug 2013 15:29:24 +1000

On 15 August 2013 08:33, Alexandru Cojocaru <address@hidden> wrote:
> Hi,
> currently `string-set!' returns an unspecified value. What about making it
> return `str' instead?

Functions whose specific purpose is to mutate the provided value
usually don't return the value because that is a common source of bugs
- this a common pattern in the string code and generally, too.

> Here is an example of its use:
> ; make a copy of `str' and replace its first character with `#\a'
> (define (make-copy str)
>  (string-set! (string-copy str) 0 #\a))
> instead of:
> (define (make-copy str)
>  (let ((s (string-copy str)))
>   (begin
>     (string-set! s 0 #\a)
>     s)))
> or perhaps I am doing something wrong?
> PS: the documentation of `list-set!' doesn't say what's its return value.

Thanks for pointing that out!  Curiously, it returns the value that
was set.  I wonder if this was intentional.

> Best regards,
> Alexandru Cojocaru

William Leslie

Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely may reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to deny you those rights would be illegal without
prior contractual agreement.

reply via email to

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