Can you pass arguments to functions in Slate? - palantir-foundry

In Foundry's Slate application, is there a clean way to write functions that accept arguments as input using the handlebar syntax?

Instead of function arguments, inputs to a Slate function are defined by a Handlebar reference inside the Function itself; for example to access data from a query from inside a Function, you might write:
const data = {{q_myQuery}}
Defining dependencies in this way allows Slate to automatically recompute the Function outputs whenever the values of upstream dependencies change. In this way, you never "call" a function, but rather some other element in Slate references the Function output and that output is updated whenever the inputs change.
If you want to do some kind of code reuse you can use functionLibraries to write common code that you can re-use between Functions. These are standard javascript functions that are included in the global javascript scope and can be referenced simply by the function name from any Function and take function parameters using normal javascript syntax. Since these are vanilla javascript you cannot use Handlebars inside a functionLibrary - here any input must be passed in as a parameter from the parent Function.
From the documentation (Slate > Concepts > Functions):
Per-Document level function libraries
Users are able to write reusable javascript functions with parameters. This will assist in the refactoring of code and reducing the copying and pasting of code in functions. You can also re-run and update all the functions dependent on a function library using the Re-run All Function button.
Default JavaScript libraries available
For enhanced use of functions, Slate ships by default (as of Slate 2.15) with the following external JavaScript libraries: Lodash, Math.js, Moment, Numeral and es6-shim. Feel free to use these libraries when writing your functions.Do not use ES6 syntax features unless all users are mandated to use a browser supporting these features.

Related

CAPL Test Functions and Normal Functions in CAPL

I want to know the difference between the "CAPL Test Functions" and normal functions (Like in C or C++) which can be used in CAPL ??
Under which scenario should I use TestFunctions ??
Thanks.
Test functions are mainly used for test nodes which is used for running test cases (defined
in an XML file) and provide reports about the results.
Normal functions can be used in test/simulation/program nodes
Internally pre-defined CAPL functions does not require function libraries or linking header files to use and compile these functions.
CAPL's internal library provides functions in 3 categories.
1. capl's internal library
2. user defined functions
3. Dll functions, which require user to implement a dynamic linked library.
The idea behind test function and normal functions is quite simple. You can use both in Vector CANoe (test modules) and vTEST Studio. BTW. To make function visible in outter scope you use 'export' keyword.
Test Functions:
- they are always top-most (cannot be nested or executed by any other function)
- does not return anything
- provides additional logging in Vector CANoe test reports (visible either in HTML/XML based or CANoe Test Report Viewer)
- use it only in CAPL Test Modules as 'test steps' of test cases (top most functions)
Casual Functions:
- might be called by other functions and test functions
- might have a return
- executing a function does not influence test logs directly (only information added by testStep, testStepPassed etc. will be added in test report)
- use them in test cases only when you want to return some values (test functions cannot be used in this case)
- use them as smaller pieces of test functions

Google Apps Script order of execution: why do functions get invoked merely by being defined?

In Javascript, the following code will execute only once, but in Google Apps Script it executes twice (obviously the body and script tags would be omitted):
<body>
<script>
hi();
function hi() {
alert('hi')
}
</script>
</body>
In other words, in GoogleApps script merely defining a function invokes it. The following in Code.gs executes with undefined arguments passed to it.
function createQuery(keywords, dateRange) {
}
How can I define functions without them being called? Pointers to the docs would be helpful. I have scoured them without success.
In GAS, you save and test functions using the toolbar at the top. By virtue of telling the function to run using the toolbar, you are calling the function. Any triggers that you have will also call it to run without 'calling' inside the code.
You can more minutely determine how and when a function runs by calling it later in the code. This can be done in nested functions or inside of other functions. Regardless of where you are defining the function, eventually you will have to either create a trigger or use the toolbar to run the function.
I'm not sure how you are experiencing a double call seeing as your reference code is not very in-depth. Keep in mind that to execute the script at all, you would have had to either set a trigger or run it yourself in which you are adding in an execution. If you execute code that tells itself to execute that same code, you would incur an infinite loop.
Users will be able to more accurately understand your question and issue and thus answer them should you provide more data and references. You may also want to read the references and guides on the basics of GAS and its use of Javascript.

Why are scripted cmdlets listed as functions?

If I create a simple Powershell function e.g.
Function Hello {
[CmdletBinding( )]
Param (
[parameter()]
$Name
)
Begin{}
Process{
Write-Output "Hello $Name"
}
End{}
}
then use Get-Command to list it with Get-Command Hello, the cmdlet is listed as 'CommandType' function. Why isn't it listed as 'CommandType' cmdlet?
When exporting from modules I've also found I have to use FunctionsToExport instead of CmdletsToExport.
It doesn't seem to affect the use of the functions, I'm just curious why they're listed like this.
There potentially isn't much difference between a function and a cmdlet, but that depends on how much work you're willing to put into writing the function. Don Jones wrote an article on TechNet back when these first came out to highlight some of these differences.
These functions, written entirely in script, have the same capabilities as a “real” cmdlet written in C# or Visual Basic and compiled in Visual Studio. These advanced functions (they were originally called “script cmdlets” early in the v2 development cycle) help you write more flexible functions you can then use seamlessly alongside regular cmdlets.
...
The real difference between a mere function and a full cmdlet is that cmdlets support powerful parameter bindings. You can use positional parameters, named parameters, mandatory parameters, and even do basic parameter validation checks—all by simply describing the parameter to the shell.
The code example you've offered already begins to blur the lines between the two by allowing a host of addition parameters via [CmdletBinding()], and beginning to describe a brand new parameter called $Name. For example, you could now use Write-Verbose anywhere in that function, and call the -Verbose flag to see those statements without having to do any additional work.
Functionally, the end results of a compiled cmdlet or a function written in powershell don't have to be very different at all -- it seems to be more a matter of distinguishing compiled cmdlets from scripted functions.

Why does Google Closure Compiler NOT rename these external variables?

According to documentation (https://developers.google.com/closure/compiler/docs/api-tutorial3#externs), it seems the closure compiler should rename variables when no external declaration exists, including when using functions/variables from an external bit of code. The example they give is
function makeNoteDom(noteTitle, noteContent, noteContainer) {
// Create DOM structure to represent the note.
var headerElement = textDiv(noteTitle);
var contentElement = textDiv(noteContent);
...
}
where the textDiv function is declared in the global scope by a third-party lib of some sort. It says textDiv should be declared external to prevent renaming.
My question is - when I put this code or similar into the Closure Compiler without any extern declarations why is textDiv not renamed (which would break the code), as the documentation indicates?
The compiler assumes that calls to an undefined function are in fact calls to an external functions. Using the command line compiler, you can use --warning_level VERBOSE to have the compiler treat this condition as an error.
The Web Application is primarily built for demos and assumes this by default. While you can set a VERBOSE warning level, it will not change this functionality. See the Additional Web Service Options page for information on options. I've filed a bug report about this.
Due to the renaming algorithm for properties, undeclared properties will be renamed in a breaking way if that same property name isn't declared on an object in externs.

Inlining functions in AS3

I'm looking for a way to inline functions in AS3.
I know that the language itself doesn't offer a native way of doing that but perhaps there is another option:
ANT precompile task
shell script
command line tool
...
Basically, anything that could eventually be integrated with ANT and run on a Hudson CI server.
You can use Joa Ebert Apparat tools to achieve such a thing and more.
You can't inline whatever function you want they are some restrictions
Basically you have to create a new class that extends Macro or Inlined following your need, and declare static function within it, then after running TDSI your function will be inlined.
Check out for example Math inlined function or Macro function
Adobe introduced native inline functions with the new ASC2 compiler in 2012. Use the -inline compiler argument to inline all getters and setters and any functions marked with the new [Inline] metadata. Inlined functions must meet these conditions:
The function is final, static or the containing scope is file or package
The function does not contain any activations
The function does not contain any try or with statements
The function does not contain any function closures
The function body contains less than 50 expressions
http://www.bytearray.org/?p=4789