Re: [netmod] false() vs 'false' in 'when' statements
Andy Bierman <andy@yumaworks.com> Wed, 08 August 2018 16:03 UTC
Return-Path: <andy@yumaworks.com>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4086F130E6B for <netmod@ietfa.amsl.com>; Wed, 8 Aug 2018 09:03:15 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.91
X-Spam-Level:
X-Spam-Status: No, score=-1.91 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_DKIMWL_WL_MED=-0.01] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=yumaworks-com.20150623.gappssmtp.com
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Z87lH_5FH-_7 for <netmod@ietfa.amsl.com>; Wed, 8 Aug 2018 09:03:11 -0700 (PDT)
Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 69940130E5A for <netmod@ietf.org>; Wed, 8 Aug 2018 09:03:10 -0700 (PDT)
Received: by mail-lj1-x244.google.com with SMTP id w16-v6so2115434ljh.12 for <netmod@ietf.org>; Wed, 08 Aug 2018 09:03:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yumaworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rO0QpwW9agGSCDo/U/r5fBwXUgNIuOe45cg2+IaLwpQ=; b=z6xHEqWML/zGBPUmi/PO6u6sh3Cyekly/vierSqVz5mfAzDAC80ISAIP8N4e0p6ReG s4fzlvhy0j9EF+PVuzziCf9IY8ODl8fG+JOT/YRlReYrMYAdW+nnLYgHrmMR+JpnmX0k /taOlTyl23oeRQSjVkgj4YA8JP3BZGZ4MYnFHjX+mdr5LFYJawg1ZlLv8cVcHwEg3uep fkyIxWnxAWO79of6+IvnWge/Y+pBCssbqS1qf1eC9NMTZQ+Cs8GaNbpeHwBmn4MsqBFf 7Rya8CZ639RNcEeqjWz+08bV5cYYkZyeMknb5yw0GDz7gk7tUdpxBqjii+hzpxLuTPhL 8fLg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rO0QpwW9agGSCDo/U/r5fBwXUgNIuOe45cg2+IaLwpQ=; b=AtFwwdhcuEItgVFpc7roCnacbc4Fqm8HPut1Hj/gdQcsokqoiUYDPWRt3ewB8wrKmR 7x7g5Ar9GbHn4suOfIqCunA5Jk02mk/HndzzXTEOSdiqu9fH76AFXrcuFXuh5gTjTuKw cfYi/cruYKGGtgr3bjumn3q3SRpVtdqrPFgZ0Mceq3BejhcbQRmkN7rOffP/DUUjJL4v xRX2Lz5YI+CGik83kaXCwyN2Y+/o8h7RPuiHLb18dyEDlASSANnPRsEk/ZfsrRyvumMw EDHXTVBC2wn8ANR8NiPFIFwbA8Dz54m7rSHIuKtwRMrAchXwWuC4aemfSfktyd2znL00 pwLg==
X-Gm-Message-State: AOUpUlEIRNhFDAejoJH5/+AjJIm61i+7edkcLwQEcv5oMCH42YLkz3dC 8mD3DqckBqM2b6dOU8HDDpOkGmUd8/tbTEG+SrtuHoxjX4U=
X-Google-Smtp-Source: AA+uWPyIAUaUzFUuJv+YEdEYfww6vSXLT2VXvNpEZTTzubzuLcRUivC1z+3W/xGf+xLO9bXgV/raMdjge6//TOuel0o=
X-Received: by 2002:a2e:1dc8:: with SMTP id w69-v6mr2662989lje.110.1533743823730; Wed, 08 Aug 2018 08:57:03 -0700 (PDT)
MIME-Version: 1.0
Received: by 2002:a19:aa46:0:0:0:0:0 with HTTP; Wed, 8 Aug 2018 08:57:02 -0700 (PDT)
In-Reply-To: <20180808.174403.1373198576462216929.mbj@tail-f.com>
References: <VI1PR07MB39813DB16C1AF2314EBD14EE9B260@VI1PR07MB3981.eurprd07.prod.outlook.com> <20180808.155048.1116801606990172501.mbj@tail-f.com> <CABCOCHTUEedds_164G7cF=T6=9-Jd4HJG=bc7JyBGTpKf0-4Mg@mail.gmail.com> <20180808.174403.1373198576462216929.mbj@tail-f.com>
From: Andy Bierman <andy@yumaworks.com>
Date: Wed, 08 Aug 2018 08:57:02 -0700
Message-ID: <CABCOCHQp3DbryGcGk1+orgoNnv3Aw+ujG-v8JA+DASr++icFsQ@mail.gmail.com>
To: Martin Bjorklund <mbj@tail-f.com>
Cc: "Sterne, Jason (Nokia - CA)" <jason.sterne@nokia.com>, NetMod WG <netmod@ietf.org>
Content-Type: multipart/alternative; boundary="000000000000ca4f280572ee8f38"
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/2SDYkAZqxDSmw38uVZ-SZ6uARXM>
Subject: Re: [netmod] false() vs 'false' in 'when' statements
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.27
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 08 Aug 2018 16:03:15 -0000
On Wed, Aug 8, 2018 at 8:44 AM, Martin Bjorklund <mbj@tail-f.com> wrote: > Andy Bierman <andy@yumaworks.com> wrote: > > On Wed, Aug 8, 2018 at 6:50 AM, Martin Bjorklund <mbj@tail-f.com> wrote: > > > > > Hi, > > > > > > "Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> wrote: > > > > Thanks William. > > > > Please see below. > > > > Regards, > > > > Jason > > > > > > > > > -----Original Message----- > > > > > From: Ivory, William <william.ivory@intl.att.com> > > > > > Sent: Wednesday, August 8, 2018 3:27 AM > > > > > To: Sterne, Jason (Nokia - CA/Ottawa) <jason.sterne@nokia.com>; > > > > > netmod@ietf.org > > > > > Subject: Re: [netmod] false() vs 'false' in 'when' statements > > > > > > > > > > On 07/08/18 18:37, Sterne, Jason (Nokia - CA/Ottawa) wrote: > > > > > Hi all, > > > > > > > > > > When comparing the value of a boolean leaf in a 'when' statement > (or a > > > > > 'must' > > > > > statement), is an equality comparison to 'true' or 'false' the > same as > > > > > a check > > > > > against true() or false() ? > > > > > > > > > > For example: > > > > > > > > > > leaf a { > > > > > type boolean; > > > > > } > > > > > leaf b { > > > > > type uint32; > > > > > when ".../a = 'true'"; > > > > > } > > > > > leaf c { > > > > > type uint32; > > > > > when ".../a = 'false'"; > > > > > } > > > > > (note that neither b nor c can be configured if leaf a isn't > > > > > explicitly configured > > > > > with a value since there is no default) > > > > > > > > > > If I replace the two 'when' statements above with the following > > > > > instead, is the > > > > > behavior the same ? > > > > > ... > > > > > when ".../a = true()"; > > > > > ... > > > > > when ".../a = false()"; > > > > > ... > > > > > > > > > > Or does "../a = true()" behave as an existence check on leaf a and > > > > > would be > > > > > enabled whether a is configured as true or false ? > > > > > > > > > > Regards, > > > > > Jason > > > > > > > > > > > > > > > > > > > > See https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans > > > > > > > > > > (a) "../a = 'true'" > > > > > > > > > > Compares 'string-value' (same as value of node if a leaf, rather > more > > > > > interesting if a list / container!) of each node in nodeset > generated > > > > > by '../a' and > > > > > if any node in the nodeset matches 'true', expression is true. > > > > > > > > [>>JTS: ] In my specific example, leaf a is a single Boolean leaf. > In > > > > that case, are these equivalent ? > > > > when ".../a = 'true'"; > > > > when ".../a = true()"; > > > > > > No... > > > > > > > and are these also equivalent ? > > > > when ".../a = 'false'"; > > > > when ".../a = false()"; > > > > > > .... and no. > > > > > > What you probably want is ".../a = 'true'" (or 'false'). > > > > > > The expression: > > > > > > ".../a = true()"; > > > > > > will first take the string value of ".../a", which e.g. is "false". > > > This string value is then converted to a boolean, resulting in the > > > boolean value True (b/c the string is non-empty). > > > > > > This means that if "a" is set at all (to true or false), the > > > expression ".../a = true()" returns true. The expression ".../a = > > > false()" will only return true if "a" is unset. > > > > > > > > > > I suggest reading the XPath definition of boolean comparisons: > > https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans > > > > It is a bit complicated, but generally, a node-set is converted > > to a boolean (==false for empty, ==true for not empty) when > > compared to a boolean for equality/inequality. > > You're right. But the result is the same in the example above; i.e., > "../a = true()" is true iff a exists. > > > > false is a boolean > > There are no boolean literals in XPath 1.0. So false would refer to a > node with the name "false". > But there is the string() function is 4.2: - The boolean false value is converted to the string false. The boolean true value is converted to the string true. > > 'false' is a string > > false() is a function that return a boolean > > > compare node-set to boolean will not work correctly. It tests existence. ../a = false If one object to be compared is a node-set and the other is a boolean, then the comparison will be true if and only if the result of performing the comparison on the boolean and on the result of converting the node-set to a boolean using the *boolean <https://www.w3.org/TR/1999/REC-xpath-19991116/#function-boolean>* function is true. compare node-set to string will work as expected ../a = 'false' If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value <https://www.w3.org/TR/1999/REC-xpath-19991116/#dt-string-value> of the node and the other string is true. > /martin > > > Andy > > > > > > Andy > > > > > > > (sorry if I'm being dense here, but I'm not 100% positive if I'm > > > > interpreting your explanations correctly and getting the right > > > > conclusion. I've never seen must or when statements that use = > > > > false() or = true()). > > > > > > > > [>>JTS: ] Are the strings 'true' and 'false' the "string-value" (that > > > > you mention above) for a Boolean leaf ? > > > > > > Yes, according to 9.5.1 in RFC 7950. > > > > > > > 'a' is a single Boolean leaf so the nodeset is that single leaf and > > > > the value is 'true' or 'false'. > > > > > > > > > > > > > > (b) "../a = true()" > > > > > > > > > > Similar to above but after getting the string-value, this is > converted > > > > > to a > > > > > boolean before comparing with the boolean true. > > > > > > > > [>>JTS: ] I'm a bit confused here. Are you saying that the > > > > string-value of leaf a is converted to a Boolean ? > > > > Do the string-values of a convert to something that is equal to > true() > > > > or false() ? > > > > > > See above. > > > > > > > > > /martin > > > > > > > > > > > > > > > > > > > > (c) '../a' > > > > > > > > > > True if the nodeset generated by this expression is not empty. > > > > > > > > > > --- > > > > > > > > > > Caveats alluded to above are that if '../a' matches multiple nodes, > > > > > then only > > > > > one of these nodes needs to pass the test for the test to be true. > > > > > Separately, if > > > > > any of the nodes are not leaves, the 'string-value' is a > concatenated > > > > > string of > > > > > the values of the node's child / grandchild leaves. > > > > > > > > > > Hope that helps. You wouldn't believe the number of unit tests I > have > > > > > to make > > > > > sure we get this logic right! Using '!=' when comparing a nodeset > > > > > with >1 node > > > > > with other values is very likely not to give the answer you expect > (-: > > > > > > > > > > Regards, > > > > > > > > > > William > > > > > > > > > > > > > _______________________________________________ > > > > netmod mailing list > > > > netmod@ietf.org > > > > https://www.ietf.org/mailman/listinfo/netmod > > > > > > > > > > _______________________________________________ > > > netmod mailing list > > > netmod@ietf.org > > > https://www.ietf.org/mailman/listinfo/netmod > > > >
- [netmod] false() vs 'false' in 'when' statements Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Ivory, William
- Re: [netmod] false() vs 'false' in 'when' stateme… Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund
- Re: [netmod] false() vs 'false' in 'when' stateme… Andy Bierman
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund
- Re: [netmod] false() vs 'false' in 'when' stateme… Andy Bierman
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund