![](/sites/default/files/inline/images/images/esher-infinite.jpg)After many sleepless nights it's a pleasure to announce the newer, better, moderner ObjectScript compiler which implemented pretty much everything you ever wanted to have in [modern ObjectScript](https://github.com/tsafin/ShinyClosures/blob/master/README.md): But we not only parse the modern ObjectScript syntax, we have implemented finally the long-standing request which we always dreamed about. Closures! ##  Closures in ObjectScript Lambdas, functors and closures are everything today. Ask every MIT graduate what they are thinking about functional-programming and Haskell - you will soon learn that it's hot. Every modern (or not so modern, but decent enough) language has their own way to implement closures: JavaScript/TypeScript, Haskell, even Perl or C++. We want to be modern and hot, that's why we implement closures  in our ObjectScript parser.  
==test.mac==
 set closure = &function { return "hello world!" }

 write $$&closure(),!

 set makeCounter = &function(init) {return &function() { $Increment(init) } }

 set cnt1 = $$&makeCounter(1)

 set cnt2 = $$&makeCounter(3)

 

 write makeCounter,!

 write $$&cnt1(),!

 write $$&cnt2(),!

 write $$&cnt1(),!

 

=============

 

USER>do ^test

hello world!

1@%Library.Closure

2

4

3

 

 i.e. &function(args) { statement; } creates closure with arguments which will be used inside of braces. This is actually creating anonymous function object, which in turn could return closure (another anonymous function object), and if this inner function object accesses local variables passed then they will be captured for later invocations. Yes, this intentionally resembles JavaScript.

`$$&id(args)` calls closure commands via value stored to `id` local variable;
===resultset.mac==

 set rs = ##class(%ResultSet).%New()

 do rs.Prepare("select ID,Age from Sample.Person where :fn(Age) = 1")

  set adult = &function() { return age > 21 }

 do rs.%Execute(.adult)

 while rs.Next() {

   write rs.GetData(1), " ", rs.GetData(2)," ", rs.GetData(3),!

 }

=====

USER>do ^resultset

1 Gallant,Yan N. 62

2 Waal,Umberto G. 54

3 Jenkins,Sam A. 75

4 Marks,Milhouse B. 35

6 Peterson,Zeke U. 63

....

 

This syntax is preliminary and is subject to modifications, but hope you already got an idea, and want to begin to use it asap. The future with this new modern language implementing closures is bright, and it (hopefully) it will come soon!

The next steps we foresee: Update #1: We have received some initial feedback, and decided to change syntax to be more JS-ish, than rather C++-ish. Because it's looking more compatible with current ObjectScript design look.