What does it mean to have a flat scope? - influxdb

In Kapacitor documentation, there is a sentence that reads:
Each script has a flat scope and each variable in the scope can
reference a literal value, such as a string, an integer or a float
value, or a node instance with methods that can then be called.
I have never heard of a flat scope, what does that mean? I tried googling for that term but I cannot find anything that explains it.

Scopes in Kapacitor is similar to the scope in JS or PowerShell
References
Scopes in PowerShell
Scope in JavaScript

Related

Lua Terminology related to OOP

To be to the point; I've done Lua for awhile, but never quite got the terminology down to specifics, so I've been Googling for hours and haven't come up with a definitive answer.
Related to OOP in Lua, the terminology used include:
Object
Class
Function
Method
Table
The question is, when are these properly used? Such as in the example below:
addon = { }
function addon:test_func( )
return 'hi'
end
Q: From my understanding with Lua and OOP, addon is a table, however, I've read that it can be an object as well -- but when it is technically an object? After a function is created within that table?
Q: test_func is a function, however, I've read that it becomes a "Method" when it's placed within a table (class).
Q: The entire line addon:test_func( ), I know the colon is an operator, but what is the term for the entire line set of text? A class itself?
Finally, for this example code:
function addon:test_func( id, name )
end
Q: What is id and name, because I've seen some people identify them as arguments, but then other areas classify them as parameters, so I've stuck with parameters.
So in short, what is the proper terminology for each of these, and when do they become what they are?
Thanks
From my understanding with Lua and OOP, addon is a table, however, I've read that it can be an object as well -- but when it is technically an object? After a function is created within that table?
Object is not a well-defined term. I've seen it defined (in C) as any value whatsoever. In Lua, I would consider it synonymous with a table. You could also define it as an instance of a class.
test_func is a function, however, I've read that it becomes a "Method" when it's placed within a table (class).
You're basically right. A method is any function that is intended to be called with the colon notation. Metamethods are also methods, because, like regular methods, they define the behavior of tables.
The entire line addon:test_func( ), I know the colon is an operator, but what is the term for the entire line set of text? A class itself?
There's no name for that particular piece of code. It's just part of a method definition.
Also, I wouldn't call the colon an operator. An operator would be the plus in x + y where x and y both mean something by themselves. In addon:test_func(), test_func only has meaning inside the table addon, and it's only valid to use the colon when calling or defining methods. The colon is actually a form of syntactic sugar where the real operator is the indexing operator: []. Assuming that you're calling the method, the expansion would be: addon['test_func'](addon).
What is id and name, because I've seen some people identify them as arguments, but then other areas classify them as parameters, so I've stuck with parameters.
They're parameters. Parameters are the names that you declare in the function signature. Arguments are the values that you pass to a function.

Scopes in Rails. Is this a lambda? [duplicate]

This question already has answers here:
What do you call the -> operator in Ruby?
(3 answers)
Closed 6 years ago.
I'm unfamiliar with usage of lambdas. Is this one in the scope call? Or is it just a piece of syntactic sugar?
scope :by_frequency, -> (frequency) { where(delivery_frequency_id: frequency) }
Why is the frequency is parenthesis?
Yes this is a lambda - since Ruby 1.9 you could write a lambda in the shorthand form you have whereas before the only syntax was this:
lambda {|x| 2 * x }
In this case the example here the argument x is passed in which is the equivalent of frequency in your example - it is a required argument for the lambda. A Ruby lambda enforces this required argument and it would complain if you called it without a value which is ideal as the where query may not make sense without it.
The whole line is syntactic sugar of Rails to allow a really nice DSL (Domain Specific Language) but all it really does is store the lambda you wrote to essentially a static method on the class. The lambda will be called when you invoke that method.
You are largely correct, the calls to scope, like the one you wrote, are just syntactic sugar for writing a class method on the active record class in question.
Furthermore, It is using lambda notation in order to do so.
However, what you should keep in mind is that you are actually making a query by using the where keyword. It's the same as saying ClassName.where()
The first frequency being defined in the parenthesis following the -> is a parameter that's being passed into the scope method being created (and then subsequently passed into where).
So, what you have defined is a class method that returns all instances of this object where the delivery_frequency_id is equal to a specific parameter.

SPSS syntax: how can I generate a var_list of all variables from the active dataset?

Frequently, PSPP/SPSS syntax documentation (example) suggests I must to pass a list of variables with /VARIABLES=var_list and this is not an optional subcommand.
But I have a lot of datasets to process. I would like to programmatically get a list of all variables in the active dataset, pass that to a procedure, and then generate a file from the procedure output.
I've tried /VARIABLES=* but that didn't work.
error: DESCRIPTIVES: Syntax error at `*': expecting variable name.
You can use display variables. or display dictionary. to generate a table of all variables and their attributes which could then be captured using OMS. However if you want to pass all variables to a function that expects a list you can use all, i.e. descriptives /variables= all..
/VARIABLES is often optional in procedures, but ALL stands for all the variables. If you need to refine by a particular measurement level, type or other metadata, try the SPSSINC SELECT VARIABLES extension command. This command applies various filters based on the metadata and creates a macro with the variables that pass. You can then use that in any context.

Is this lambda? if not what is it?

a few days back i was trying the new ORM for delphi from Devart called EntityDAC, well i was reading the docs specific the LINQ part, when i saw something like:
Linq.From(Emp).Where(Emp['Sal'] > 1000)
got to say that wake me up the first moment i saw. the expression "Emp['Sal'] > 1000" isn't a lambda expression?! since the trial version is this component don't come with sources i couldn't figure out how Where function/procedure is declared.
reference: http://www.devart.com/entitydac/docs/ -> Linq Queries -> Linq Syntax -> Scroll down to Where session
I mentioned this in a blog post a few months ago. I don't have the source to look at, but it's almost certainly done this way:
The expression Emp['Sal'] returns a value of a record type
This record has operator overloads declared on it
The Delphi language defines operator overloads as functions, and does not require them to return any specified or intuitive type. Therefore, the > operator here does not return a boolean, but rather another record.
By chaining these operators, an expression tree can be created, which can be evaluated by their LINQ evaluator.

What are Lua's Introspection features?

What are Lua's introspection features? I know that you can query the type of a variable at runtime using type(var) and that the debug package provides some features for inspecting the environment, but it is not clear what that gives me.
What other introspection features are in Lua? Any good resources?
Lua values can have 7 types: nil, boolean, number, string, function, userdata, thread, and table. You can get the type of a value using the type function from the standard library.
If you are working with tables, you can iterate over its keys using the pairs function.
Finally, values in Lua can have metatables and this is often used in to program in an object oriented style. You can get a value's metatable using the getmetatable function.
You actually have to use the built-in function type() to get a variable's type at run time
t = 'asdf'
print(type(t))
for example. As far as introspection, the debug library is pretty much it for vanilla Lua. The best place to begin poking around would be in the reference manual for the debug library.

Resources