<Keyword>local</Keyword><Normal Text> utils </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><Keyword>import</Keyword><Normal Text> </Normal Text><String>'utils.libsonnet'</String><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Comment>/* A C-style</Comment><br/>
<Comment>   comment.</Comment><br/>
<Comment>*/</Comment><br/>
<Comment># A Python-style comment.</Comment><br/>
<Normal Text></Normal Text><br/>
<Comment>// Define a "local" function.</Comment><br/>
<Comment>// Default arguments are like Python:</Comment><br/>
<Keyword>local</Keyword><Normal Text> </Normal Text><Function>my_function</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>,</Symbol><Normal Text> y</Normal Text><Symbol>=</Symbol><Decimal>10</Decimal><Symbol>)</Symbol><Normal Text> </Normal Text><Symbol>=</Symbol><Normal Text> x </Normal Text><Symbol>+</Symbol><Normal Text> y</Normal Text><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> object </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>  </Normal Text><Comment>// A method</Comment><br/>
<Normal Text>  </Normal Text><Function>my_method</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>):</Symbol><Normal Text> x </Normal Text><Symbol>*</Symbol><Normal Text> x</Normal Text><Symbol>,</Symbol><br/>
<Symbol>};</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> string1 </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><String>'Farmer</String><String Char>\'</String Char><String>s Gin'</String><Symbol>;</Symbol><br/>
<Keyword>local</Keyword><Normal Text> string_newline1 </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><String>'this is</String><br/>
<String>a valid string</String><br/>
<String>with newlines'</String><Symbol>;</Symbol><br/>
<Keyword>local</Keyword><Normal Text> string_newline2 </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><String>"this is</String><br/>
<String>also</String><br/>
<String>a valid string"</String><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> timcollins </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><String>|||</String><br/>
<String> The Tom Collins is essentially gin and</String><br/>
<String> lemonade. The bitters add complexity.</String><br/>
<String>|||</String><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> obj </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>  </Normal Text><String>"foo"</String><Symbol>:</Symbol><Normal Text> </Normal Text><Decimal>1</Decimal><Symbol>,</Symbol><br/>
<Normal Text>  </Normal Text><String>"bar"</String><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>    </Normal Text><String>"arr"</String><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Decimal>1</Decimal><Symbol>,</Symbol><Normal Text> </Normal Text><Decimal>2</Decimal><Symbol>,</Symbol><Normal Text> </Normal Text><Decimal>3</Decimal><Symbol>],</Symbol><br/>
<Normal Text>    </Normal Text><String>"number"</String><Symbol>:</Symbol><Normal Text> </Normal Text><Decimal>10</Decimal><Normal Text> </Normal Text><Symbol>+</Symbol><Normal Text> </Normal Text><Decimal>7</Decimal><Symbol>,</Symbol><br/>
<Normal Text>  </Normal Text><Symbol>},</Symbol><br/>
<Symbol>};</Symbol><br/>
<Normal Text></Normal Text><br/>
<Comment>// Define a local function.</Comment><br/>
<Comment>// Default arguments are like Python:</Comment><br/>
<Keyword>local</Keyword><Normal Text> </Normal Text><Function>my_function</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>,</Symbol><Normal Text> y</Normal Text><Symbol>=</Symbol><Decimal>10</Decimal><Symbol>)</Symbol><Normal Text> </Normal Text><Symbol>=</Symbol><Normal Text> x </Normal Text><Symbol>+</Symbol><Normal Text> y</Normal Text><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Comment>// Define a local multiline function.</Comment><br/>
<Keyword>local</Keyword><Normal Text> </Normal Text><Function>multiline_function</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>)</Symbol><Normal Text> </Normal Text><Symbol>=</Symbol><br/>
<Normal Text>  </Normal Text><Comment>// One can nest locals.</Comment><br/>
<Normal Text>  </Normal Text><Keyword>local</Keyword><Normal Text> temp </Normal Text><Symbol>=</Symbol><Normal Text> x </Normal Text><Symbol>*</Symbol><Normal Text> </Normal Text><Decimal>2</Decimal><Symbol>;</Symbol><br/>
<Normal Text>  </Normal Text><Comment>// Every local ends with a semi-colon.</Comment><br/>
<Normal Text>  </Normal Text><Symbol>[</Symbol><Normal Text>temp</Normal Text><Symbol>,</Symbol><Normal Text> temp </Normal Text><Symbol>+</Symbol><Normal Text> </Normal Text><Decimal>1</Decimal><Symbol>];</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> object </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>  </Normal Text><Comment>// A method</Comment><br/>
<Normal Text>  </Normal Text><Function>my_method</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>):</Symbol><Normal Text> x </Normal Text><Symbol>*</Symbol><Normal Text> x</Normal Text><Symbol>,</Symbol><br/>
<Symbol>};</Symbol><br/>
<Normal Text></Normal Text><br/>
<Keyword>local</Keyword><Normal Text> large </Normal Text><Symbol>=</Symbol><Normal Text> true</Normal Text><Symbol>;</Symbol><br/>
<Normal Text></Normal Text><br/>
<Symbol>{</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  </Normal Text><Comment>// Functions are first class citizens.</Comment><br/>
<Normal Text>  call_inline_function</Normal Text><Symbol>:</Symbol><br/>
<Normal Text>    </Normal Text><Symbol>(</Symbol><Function>function</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>)</Symbol><Normal Text> x </Normal Text><Symbol>*</Symbol><Normal Text> x</Normal Text><Symbol>)(</Symbol><Decimal>5</Decimal><Symbol>),</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  call_multiline_function</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Function>multiline_function</Function><Symbol>(</Symbol><Decimal>4</Decimal><Symbol>),</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  </Normal Text><Comment>// Using the variable fetches the function,</Comment><br/>
<Normal Text>  </Normal Text><Comment>// the parens call the function.</Comment><br/>
<Normal Text>  call</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Function>my_function</Function><Symbol>(</Symbol><Decimal>2</Decimal><Symbol>),</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  </Normal Text><Comment>// Like python, parameters can be named at</Comment><br/>
<Normal Text>  </Normal Text><Comment>// call time.</Comment><br/>
<Normal Text>  named_params</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Function>my_function</Function><Symbol>(</Symbol><Normal Text>x</Normal Text><Symbol>=</Symbol><Decimal>2</Decimal><Symbol>),</Symbol><br/>
<Normal Text>  </Normal Text><Comment>// This allows changing their order</Comment><br/>
<Normal Text>  named_params2</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Function>my_function</Function><Symbol>(</Symbol><Normal Text>y</Normal Text><Symbol>=</Symbol><Decimal>3</Decimal><Symbol>,</Symbol><Normal Text> x</Normal Text><Symbol>=</Symbol><Decimal>2</Decimal><Symbol>),</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  </Normal Text><Comment>// object.my_method returns the function,</Comment><br/>
<Normal Text>  </Normal Text><Comment>// which is then called like any other.</Comment><br/>
<Normal Text>  call_method1</Normal Text><Symbol>:</Symbol><Normal Text> object</Normal Text><Symbol>.</Symbol><Function>my_method</Function><Symbol>(</Symbol><Decimal>3</Decimal><Symbol>),</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  standard_lib</Normal Text><Symbol>:</Symbol><br/>
<Normal Text>    </Normal Text><Keyword>std</Keyword><Symbol>.</Symbol><Function>join</Function><Symbol>(</Symbol><String>' '</String><Symbol>,</Symbol><Normal Text> </Normal Text><Keyword>std</Keyword><Symbol>.</Symbol><Function>split</Function><Symbol>(</Symbol><String>"foo/bar"</String><Symbol>,</Symbol><Normal Text> </Normal Text><String>'/'</String><Symbol>)),</Symbol><br/>
<Normal Text>  len</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><br/>
<Normal Text>    </Normal Text><Keyword>std</Keyword><Symbol>.</Symbol><Function>length</Function><Symbol>(</Symbol><String>'hello'</String><Symbol>),</Symbol><br/>
<Normal Text>    </Normal Text><Keyword>std</Keyword><Symbol>.</Symbol><Function>length</Function><Symbol>([</Symbol><Decimal>1</Decimal><Symbol>,</Symbol><Normal Text> </Normal Text><Decimal>2</Decimal><Symbol>,</Symbol><Normal Text> </Normal Text><Decimal>3</Decimal><Symbol>]),</Symbol><br/>
<Normal Text>  </Normal Text><Symbol>],</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>  cocktails</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>    </Normal Text><Keyword>local</Keyword><Normal Text> factor </Normal Text><Symbol>=</Symbol><Normal Text> </Normal Text><Control Flow>if</Control Flow><Normal Text> large </Normal Text><Control Flow>then</Control Flow><Normal Text> </Normal Text><Decimal>2</Decimal><Normal Text> </Normal Text><Control Flow>else</Control Flow><Normal Text> </Normal Text><Decimal>1</Decimal><Symbol>,</Symbol><br/>
<Normal Text></Normal Text><br/>
<Normal Text>    </Normal Text><Comment>// Ingredient quantities are in fl oz.</Comment><br/>
<Normal Text>    </Normal Text><String>'Tom Collins'</String><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><br/>
<Normal Text>      ingredients</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><br/>
<Normal Text>        </Normal Text><Symbol>{</Symbol><Normal Text> kind</Normal Text><Symbol>:</Symbol><Normal Text> string1</Normal Text><Symbol>,</Symbol><Normal Text> qty</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Float>1.5</Float><Symbol>*</Symbol><Normal Text>factor </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>        </Normal Text><Symbol>{</Symbol><Normal Text> kind</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Lemon'</String><Symbol>,</Symbol><Normal Text> qty</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Decimal>1</Decimal><Normal Text> </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>        </Normal Text><Symbol>{</Symbol><Normal Text> kind</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Simple Syrup'</String><Symbol>,</Symbol><Normal Text> qty</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Float>0.5E+1</Float><Normal Text> </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>        </Normal Text><Symbol>{</Symbol><Normal Text> kind</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Soda'</String><Symbol>,</Symbol><Normal Text> qty</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><Decimal>2</Decimal><Normal Text> </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>        </Normal Text><Symbol>{</Symbol><Normal Text> kind</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Angostura'</String><Symbol>,</Symbol><Normal Text> qty</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'dash'</String><Normal Text> </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>      </Normal Text><Symbol>],</Symbol><br/>
<Normal Text>      garnish</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Maraschino Cherry'</String><Symbol>,</Symbol><br/>
<Normal Text>      served</Normal Text><Symbol>:</Symbol><Normal Text> </Normal Text><String>'Tall'</String><Symbol>,</Symbol><br/>
<Normal Text>      description</Normal Text><Symbol>:</Symbol><Normal Text> timcollins</Normal Text><Symbol>,</Symbol><br/>
<Normal Text>    </Normal Text><Symbol>},</Symbol><br/>
<Normal Text>  </Normal Text><Symbol>},</Symbol><br/>
<Symbol>}</Symbol><br/>
