Good explanation, Kirk, especially because it is so simple.

I had not been able to ‘get into’ v18 yet—just a cursory glance at the 
documentation—What’s new etc. This is a very exciting feature.
It will definitely help when processing collections, etc.
— Chris

> On Nov 2, 2019, at 12:40 PM, Kirk Brooks via 4D_Tech <[email protected]> 
> wrote:
> 
> The v18 beta introduces a new variable type: variant. Not surprisingly
> there is already discussion about what it could possibly be useful for and
> why it doesn't have more capabilities. We are who we are.
> 
> I have come across a clear case where it's a perfect solution.
> 
> Consider a collection of text and null values. Like so:
> 
> $tuple_col:=New collection("a";"b";"c";null;null;null;"z")
> 
> I want to iterate through the collection and concatenate the values into a
> string.
> 
> $str:=""
> For each ($element;$tpl_col)
> 
> If ($element#Null)
> 
> $str:=$str+$element
> 
> End if
> 
> $str:=$str+$delim
> 
> End for each
> 
> 
> If this code is interpreted and not typed things are fine. As soon as I
> declare $element as TEXT it throws an error when I hit a Null. If I declare
> it as an object it throws an error when it hits a text. But if I declare
> $element as C_VARIANT it's all good.
> 
> I suspect something like this is the motivation behind the C_VARIANT data
> type to begin with. Otherwise accomplishing this loop would get
> complicated. So here in 4D land C_VARIANT solves the problem of how we deal
> with a stream of different data types. Like a collection or object
> properties.
> 
> -- 
> Kirk Brooks
> San Francisco, CA
> =======================
> 
> What can be said, can be said clearly,
> and what you can’t say, you should shut up about
> 
> *Wittgenstein and the Computer *
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[email protected]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to