Subject: [Cbor] Use of cuts in maps

From: Jim Schaad <[email-masked]>
Date: Wed, 7 Aug 2019 14:45:33 -0700

One of the issues that I have always had with the way that cuts are
specified in CDDL is that they don't behave the way that I think they should
in terms of going from the most specific to the most general.  I think that
I have found a way around this problem and want to verify that it would
work.

Start I start with

map-example = {
   ? "optional-key" : int,
   map-example-extensions,
   * tstr => any
}

map-example-extensions = ()

The next document comes along and does

map-example-extensions /= (
   "another-optional-key" : tstr,
  "and a third": bstr
)

If I compile the two modules together, do you believe that this would be a
match or not?
 
{ "and a third" : 15 }

Jim

---

From: Carsten Bormann <[email-masked]>
Date: Thu, 8 Aug 2019 06:40:53 +0200

Hi Jim,

> On Aug 7, 2019, at 23:45, Jim Schaad <[email-masked]> wrote:
> 

This would need to be a »//=«.

>  “and a third": bstr

And these would need a »?« each to be independently optional; right now you are saying they need to be both there.

> { “and a third" : 15 }

With the above changes, this would match the »”and a third”:« and then fail on the bstr post-cut, so the whole map would not match.

I would probably restructure this to:

map-example = {
  ? optional-key : int,
  * map-example-extension,
  * tstr => any
}

map-example-extension = ()

map-example-extension //= (another-optional-key : tstr,)
map-example-extension //= (“and a third”: bstr,)

so further additions can be made without excluding the ones already made.

Grüße, Carsten

---

From: Jim Schaad <[email-masked]>
Date: Wed, 7 Aug 2019 21:53:49 -0700

Carsten,

Thanks.  I was really more worried about the conceptual idea than I was about the exact syntax.

I would suggest that this idea become part of the idiom wiki as this solves the major problem that I had with the entire idea of how cuts have been implemented in the language.  

It should probably have two expansion points, one for values and one for types, that is "foo": int is separated from int: int.  

Jim

-----Original Message-----
From: Carsten Bormann <[email-masked]> 
Sent: Wednesday, August 7, 2019 9:41 PM
To: Jim Schaad <[email-masked]>
Cc: [email-masked]
Subject: Re: Use of cuts in maps

Hi Jim,

> specified in CDDL is that they don't behave the way that I think they 
> should in terms of going from the most specific to the most general.  
> I think that I have found a way around this problem and want to verify 
> that it would work.
> 
> 
> Start I start with
> 
> map-example = {
>   ? "optional-key" : int,
>   map-example-extensions,
>   * tstr => any
> }
> 

> 
> If I compile the two modules together, do you believe that this would 
> be a match or not?
> 
> { “and a third" : 15 }

map-example = {
  ? optional-key : int,
  * map-example-extension,
  * tstr => any
}

map-example-extension //= (another-optional-key : tstr,) map-example-extension //= (“and a third”: bstr,)

Grüße, Carsten