/* Copyright 2015 Google Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // Define a local function. // Default arguments are like Python: local my_function(x, y=10) = x + y; // Define a local multiline function. local multiline_function(x) = // One can nest locals. local temp = x * 2; // Every local ends with a semi-colon. [temp, temp + 1]; local object = { // A method my_method(x): x * x, }; { // Functions are first class citizens. call_inline_function: (function(x) x * x)(5), call_multiline_function: multiline_function(4), // Using the variable fetches the function, // the parens call the function. call: my_function(2), // Like python, parameters can be named at // call time. named_params: my_function(x=2), // This allows changing their order named_params2: my_function(y=3, x=2), // object.my_method returns the function, // which is then called like any other. call_method1: object.my_method(3), standard_lib: std.join(' ', std.split('foo/bar', '/')), len: [ std.length('hello'), std.length([1, 2, 3]), ], }