lilypond-user
[Top][All Lists]
Advanced

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

Re: Defining new Scheme predicates


From: David Kastrup
Subject: Re: Defining new Scheme predicates
Date: Mon, 07 Nov 2016 11:20:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Urs Liska <address@hidden> writes:

> Am 07.11.2016 um 09:57 schrieb Richard Shann:
>> On Mon, 2016-11-07 at 06:45 +0100, Urs Liska wrote:
>>> Am 7. November 2016 01:20:23 MEZ, schrieb Andrew Bernard
>>> <address@hidden>:
>>>> Hi Simon,
>>>>
>>>> Thanks! Exactly perfect. Sometimes the completely obvious escapes me.
>>>> Better
>>>> have another coffee.
>>>>
>>>> Most appreciated.
>>>>
>>>> I suppose of course that to make it a predicate without the preliminary
>>>> let
>>>> block (not that I have any objection to that) one would have to modify
>>>> lilypond internals, which would not be desirable.
>>> Not at all!
>>>
>>> Just define your predicate with
>>>
>>> #(define (side? obj)
>>>   (if (or (eq? obj 'left)
>>>           (eq? obj 'right))
>>>       #t #f))
>> more succinctly
>>
>> #(define (side? obj)
>>    (or (eq? obj 'left)
>>        (eq? obj 'right)))
>
> No. This will return either 'left or 'right if successful.

Nonsense.

> But a predicate is to return #t or #f.

Not even that.  Conditions are #f, and anything else.  There is a
convention that functions with a name ending in ? return only #t and #f.
For a quite local function in your own code, conventions are not much of
a worry.

>>> and use it like any other procedure. The ? at the end is just a
>>> convention, predicates are nothing else
>>> than procedures taking one argument and returning #t or #f.
>> #t or any other value that is not #f - the value #t is rather rarely
>> used in conventional Scheme code; great use is made of the convenience
>> that all expressions are true except #f which is false.

See above.  ? at the end of a function name pretty much implies that the
function returns only #f and #t .  memq (and its ilk) is very often used
as a predicate in conditions but still its function name reflects that
it does not return #t for a true condition.

-- 
David Kastrup



reply via email to

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