macro to go to struct definition in Julia - macros

In Julia, I could go directly to the definition of a method by the #edit macro as follows:
#edit 1 + 2
Is there a macro which achieves the same functionality for struct definitions? Something like,
#edit SomeType
which opens the definition of SomeType in an editor.

Try dump(SomeType) - see the code below for an example:
julia> struct MyStruct
a::Int
b::String
end
julia> dump(MyStruct)
MyStruct <: Any
a::Int64
b::String
Another option I can think of is to look for the default constructor (which in many cases is the struct definition itself), for an example try:
edit(DataFrame, fieldtypes(DataFrame))

Related

How can define enumerator in Methods?

There is a problem when u define an enum in a method.
I was trying to do this:
VAR
enumA:(A,B,C);
END_VAR
and there is the compiler reaction when I used this in TwinCAT3 Shell (TcXaeShell).
any help would be appreciated.
You can only use global enumerations in methods. It's one of the limitations with local enumerations.
https://alltwincat.com/2021/11/16/local-enumerations/
You should first define variable type as enumeration in DUT
TYPE MyEnum:
(A, B, C)
END_TYPE
Then in a program you can declare variable of that type
VAR
enum: MyEnum;
END_VAR
Inside the program if you want to compare it.
IF enum = MyEnum.C THEN
// Do something
END_IF;
I’ve run into this issue before. You must declare the local enumeration in the variables section of the function block. Then you can use it in the methods of the function block.

Why might TypeScript not be enforcing a type declared for a class property?

This is on a large code base, so I'm just looking for general pointers.
In one file, a function takes a parameter a:MyClass.
At runtime, typeof a.b yields string.
In VSCode I hit F12 on the b of a.b and am brought (correctly, judging by the import statement) to another file:
export class MyClass {
...
b: string[]; // brought to this line
}
How is it possible within a TypeScript environment for a.b to be a string instead of a string[] like the class declaration says? And what should I look for that might cause this behaviour?
Type declarations in TypeScript are only suggestive. Because TypeScript is transpiled into plain JavaScript it can not make any guarantees about the actual content of a variable.
Even in TypeScript itself is fairly easy to put an object of a different type in a variable:
let myClass = new MyClass();
myClass.b = "I'm a string placed into a string array" as any;
Notice the as any at the end of the last line, this removes type information from an expression and allows it to be placed into a variable or argument of any type.

Why std::atomic defined as struct?

According to the clause 29.5 of Standard std::atomic is defined as struct:
namespace std {
template <class T> struct atomic { ...
I would understand if it gave direct access to data members like std::pair, but it doesn't. Or if it used like functor, std::hash for example.
What is the main reason for std::atomic being struct, not class?

What's the proper way to declare a field holding a function in dart?

Imagine a silly class like this:
class ConditionalWorker{
var validityChecker= (inputs)=>true;
ConditionalWorker(this.validityChecker)
...
Now my question is, what is the proper way of declaring the validityChecker field?
This tutorial suggests using typedefs. But that's not very practical. Firstly it's a chore to write a lot of typedefs that would only be used once. And secondly these typedefs show up and pollute the autocompletion of my IDE.
The var works best, with custom setters/constructor arguments to keep it always of a specific kind, but I know it's discouraged by the style guide.
I could do Function<bool> but that just a more glorified var and the amount of work is the same.
It's a shame because it's perfectly legal to have a function like this:
bool every(bool test(E element));
where the parameter is a very well defined function, but I can't have a field declared the same way:
bool test(E element);
But hopefully there is something just as good that I didn't figure out. Right?d
If you want a function type more specific than Function, you need a typedef.
If you don't like to have named typedefs for every return type, you can define generic function types yourself.
typedef R function0<R>();
typedef R function1<S,R>(S arg1);
typedef R function2<S,T,R>(S arg1. T arg2);
typedef R function3<S,T,U,R>(S arg1, T arg2, U arg3);
Then you can write:
function1<int,int> curryAdd(int x) => (int y) => x + y;
Or if function0 looks bad to you, you can name them NullaryFunction, UnaryFuncytion, BinaryFunction, TernaryFunction, or any other name that you like.
If Function<bool> is not specific enough (you also want to specify the number and type of the arguments you have to use typedefs. There are no other ways.
I'm not sure why you think it is not practical. If you want to specify the type for a field that references a value you have to use one of the existing classes or create a new one. It's the same for fields referencing functions.
With Dart 2 we can use inline function types and we need to use it instead of typedefs where possible.
With inline function types we now can define a function as a field or a property as simple as this:
final bool Function(E) test;

What is the meaning/use of #geplant in an assignment?

I'm just starting with X++ (Java background) and I found a code like
#XYZBatchScheduling
;
...
order.Status = #geplant;
order is a record to a table with a Status column.
My question: what is the meaning of #USRBatchScheduling and #geplant ("geplant" is "planned" in german) and eventually where to find it's definition.
I suppose it is some kind of constant but was unable to find # in the X++ reference (keywords).
#XYZBatchScheduling is a Macro library. Look in the AOT under Macros for XYZBatchScheduling.
#geplant is a Macro, it is probably defined in the XYZBatchScheduling macro library, but it could be defined in several other places. It could be defined in the class declaration of the class the method is in, or if the class is a derived class, in the class declaration of any of the base classes. Look for a line that looks like:
#define.geplant(42)