Aaron Hill <lilyp...@hillvisions.com> writes:

> On 2019-04-08 2:48 am, Thomas Morley wrote:
>> foo =
>> #(let ((x (cons 1 0)))
>>   (define-scheme-function (arg)(symbol?)
>>     (case arg
>>       ((indent) (set! x (cons (car x) (1+ (cdr x)))))
>>       ((increase) (set! x (cons (1+ (car x)) 0)))
>>       ((reset) (set! x (cons 1 0))))
>>     (if (zero? (cdr x))
>>         (format #f "~a" (car x))
>>         (format #f "~a.~a" (car x) (cdr x)))))
>>
>> [ . . . ]
>>
>> I'm still not happy with those set-whatever!-thingies. I was beaten
>> too often. Maybe someone comes up with a better approach.
>
> Using set! is perfectly fine as long as you encapsulate things well.
> Your use of let to define a local variable minimizes the chance that
> folks would be able to interfere with or even care about such
> modification.  However, your usage means there is still a "global" x
> that is shared amongst all of the usage of foo.

There is no global variable x.  There is a binding, but the scope of the
binding ends with the let.  This binding is anonymous afterwards and has
no name.  You can call functions manipulating the global variable x from
inside of foo and their action is not related to having used the binding
x when defining foo.

-- 
David Kastrup

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to