Open vlstill opened 2 months ago
I would generally like the first one.
If we have a real use case for 2 or 3, I suppose I could be convinced, but I suspect enums are better for anything that 2 might be used for and I have trouble imagining where I'd care to use 3.
This follows on #1297. It is also connected to p4lang/p4c#4837. Currently strings can only be literals and the
string
type can only be used to declare extern arguments. With #1297, the concatenation of strings will be allowed. I wonder if we should allow even more operations, turning strings into more "standard" types, although existing still only at compile time (likeint
!).Some things that could be allowed:
const string foo = "bar"
). Essentially this just gives P4 life to something that can be now done using preprocessor.==
,!=
).<
,<=
,>=
,>
) -- here I am not sure if there is a good use case for this and it comes with its own caveats (e.g. the byte-wise lexicographic ordering is different from e.g. UTF-8 lexicographic ordering which depends on local). So we might defer this to later.string[start:end]
) -- again, the use case is not clear to me and it might be wise to wait for it.The first two seem very safe to me.