Object match feature in Sciter 3.2.0.3

In Sciter 3.2.0.3 I’ve added so called object match feature to built-in like operator and switch/like statement.

Let’s imagine that we have some sequence of objects/data like:

      var shoppingCartData = [
        { product:"Apple", price: 0.95, calories:52 },
        { product:"Orange", price: 0.75, calories:47 },
        { product:"Toothbrush", price: 1.75 },
        "deleted",
        { product:"Pear", price: 1.25, calories:57 },      
        { product:"Soap", price: 2.75 },
      ];

And we would like to do something separately for food items and other purchased goods. With the new switch/like addition that will simply look like this:

for( var item in shoppingCartData ) 
  switch(item) 
  {
     like { price: Float, calories: Integer } :  
           // appears as a food item, do something with it
           ...
           break; 
     like { price: Float } : 
           // not a food item
           ...
           break;            
     case "deleted" :
           // item was deleted, skip it  
           break;
     default:
           // unknown thing, is it just a present? 
           break; 
  }

Same pattern matching was added to the like expression:

if( item like { product: String, price: Float } )
    stdout.println( item, "is a pricey product" );

Hope this will make life easier in some cases.

Leave a Reply

Your email address will not be published. Required fields are marked *