lilypond-user
[Top][All Lists]
Advanced

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

Re: Predicate for a string representing an integer


From: Jan-Peter Voigt
Subject: Re: Predicate for a string representing an integer
Date: Tue, 30 May 2017 11:13:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

Hi Urs,

the functions used are built-in so I'd probably also do it (almost) that way. But I'd strongly recommend to test if obj is a string first:

#(define (integer-string? obj)
   (and (string? obj)(integer? (string->number obj))))

Otherwise the predicate fails with an error (not false) if the argument is something else ... for example an integer. I doubt that checking all characters in the string are in the range '0'-'9' is faster then string->number.

Jan-Peter

Am 30.05.2017 um 10:47 schrieb Urs Liska:
Hi all,

I've found this function in my code:

% Returns true if obj is a string representation of an integer
#(define (integer-string? obj)
    (integer? (string->number obj)))

and I have the impression there should be a better way with more
built-in functionality to do it.

Any suggestions, or should I simply leave it at that?

Urs






reply via email to

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