What's the AHK equivalent of one-line logical OR short-circuit evaluation? - conditional-statements

For example, in JavaScript, the following code would log foo:
false || console.log('foo')
How to achieve the same logic in one line in AutoHotkey?

The same is possible in ahk.
I'm guessing a problem you might be facing is if you tried to use normal commands with it. It's not possible you'd have to be calling functions.
If the thing you want to call is a command you might need to make a custom function to wrap it and be able to use it as function.
(Ahk v2 would be more comfortable to use in this regard but it's still in beta.)

Related

How do I implement a PDDL generated plan into a Python code communicating with motors?

So i have a problem which I modeled using PDDL. I want to implement the plan generated from this problem to a an existing Python code which controls two motors via Wi-Fi with a loop on VS Code (Python). I want this code to take my plan and execute it. Does this mean I need to define the actions I have as functions for my Python code and read the .plan file as a text and call the functions step by step? What are other options I might have?
Thank you for sparing your time!
Yes, it means that for every action of your PDDL, you have a corresponding function. And for every object in your problem, you have a corresponding instance that you can pass as an argument to the functions.
When you get a plan, you must parse it, take the step of the plan and:
look up the function by your action name
look up the instances by name to pass them to the function.
Once the function completes successfully, repeat.
Note that if you want to be able to interrupt the action while it is ongoing, you might need more complex kind of functions, if not objects.

Scripting Language with "edit and continue" or "hot swap" support? ( Maybe possible in Lua?)

I am making my existing .Net Application Scriptable for non programming users. I added lua, it works like a charm. Then I added debug functionality(pause/continue/step) via debug.sethook. It works also like a charm.
Now I realize that my Application needs edit and continue feature like Visual Studio has it. You pause the execution can edit the code and then continue from your current state with changes applied. This feature is very important to me. I thought this would be easy to do for scripting languages.
Everywhere I read that scripting languages can do this. But even after spending hours of searching I haven't found an Lua implementation yet. It hasn't to be Lua but hot swapping code in Lua would be my first choice.
How can the ability for the user be offered to pause and edit the script and than continue the execution with changes applied?
NOTE: It doesn't have to be Lua every scripting language would be okay
Update
#Schollii
Here is an example:
function doOnX()
if getValue() == "200" then
value = getCalculation()
doSomething() -- many function calls, each can take about 2s
doSomething()
doSomething()
print(value)
doX(value)
end
end
doOnX()
Thank you for your suggestions. This is how it might work:
I will use https://github.com/frabert/NetLua Its a very cool, well written 100% C# Lua Interpreter. It is generating an AST tree first and then directly executing it.
The parser needs to be modified. In Parser.cs public Ast.Block ParseString(string Chunk) there is a parseTree generated first. parseTree.tokens[i].locations are containing the exact position of each token. The Irony.Parsing.ParseTree is then parsed again and is converted to a NetLua.Ast.Block but the location information is missed. I will need to change that so later I will know which Statement is in which line.
Now each Statement from the AST tree is directly executed via EvalBlock. Debug functionality (like I have in my C Binding lua Interpreter DynamicLua via debug.setHook) needs to be added. This can be done in LuaInterpreter.cs internal static LuaArguments EvalBlock(`. Pause/continue/step functions should be no problem. I also can now add current line Highlighting because each statement contains position line information.
When the execution is paused and the code was edited the current LuaContxct is saved. It contains all variables. Also the last Statement with the last execution line is saved.
Now the code String is parsed again to a new AST tree. It gets executed. But all statements are skipped until the saved statement with the line statement is reached. The saved LuaContext is restored and execution can continue with all changes applied.
New variables could be also added after the last executed line, because a new NetLua.Ast.Assignment Statement could just add a new variable to the current LuaContext and everything should just work fine.
Will this work?
I think this is quite challenging and triicky to do right.
Probably the only way you could do that is if you recompile the chunk of code completely. In a function this would mean the whole function regardless of where edit is in function. Then call the function again. Clearly the function must be re-entrant else its side effects (like having incremented a global or upvalue) would have to be undone which isn't possible. If it is not reentrant it will still work just not give expected results (for example if the function increments a global variable by 1 calling it again will result in the global variable having been increased by 2 once the function finally returns).
But finding the lines in the script where the chunknstarts and ends would be tricky if truly generic solution. For specific solution you would have to post specific examples of scripts you want to run and examples of lines you would want to edit. If the whole user script gets recompiled and rerun then this is not a problem, but the side effects is still an issue, examples could help there too.

Stepping through code in Google Apps Script (equivalent VBA-GAS )

When writing my VBA macros I often used "F8" so as to debug the macro line by line. Is there a similar feature in Google Apps Script?
Similar, but not the same.
Google Apps Script is developed in a dedicated IDE1 called the Script Editor, which provides support for single-step execution and breakpoints, among other things.
For a quick introduction to debugging using the IDE, see this video. The Troubleshooting section of the online documentation includes a quick overview of the basics.
Debugging Functions with parameters
In the IDE you can select any function in your script for execution, and then select the "run" or "Debug" icons to start. Unfortunately, there is no way to pass parameters to a function this way, so here are a few ways you can deal with that.
Set defaults. There are numerous ways to define defaults in javascript, here is a picture of the debugger operating on a function using the simplest of them. The function toText() from this answer accepts a number as a parameter, so for this example we are forcing the default value to 21. The picture shows the debugger paused at line 40; if we continue stepping through the function we expect to end up with a result s == 'Twenty-one'.
Write a test function. This is a better approach than setting defaults, because it allows you to write multiple test cases, and it avoids polluting your target function with debug code. As an example, the target function flipFlopAndFly() and its test function test_flipFlopAndFly() were provided in this answer. The test function accesses the spreadsheet to provide appropriate data for testing the target, so we can easily modify the data for different tests. Note also, this function includes error checking, so it would not be appropriate to test by forcing default values.
There are many variations on these basic patterns, so feel free to adapt them to your own situation. It will help your debugging capability to think while you are writing about how you would step through your code:
Is each important object and value stored in a var, so you can see it?
Is your function result (return value) in a var?
Custom Functions
When developing or debugging custom functions that will be called from a spreadsheet, remember that you cannot "jump" into the IDE. If you need to step through the script, you will need to work entirely within the IDE to observe execution of your code. You can use the techniques described above to debug custom functions.
1 Integrated Development Environment

Quick way to add Stopwatch.start and Stopwatch.end to all functions vb.net

Just trying to look at a quick way to find the timings for each individual function in my application. Would like to optimize code and see if some function is taking longer than others but was wondering if there was some quick way i could add the Stopwatch.start and Stopwatch.end to the beginning and ending of each function. Could someone assist me in what to google? I can see how I want it to work but have no clue on how to start.
Not looking for answers, just guidance :)
Thanks!
You can use ReSharper (or something similar) to create a macro for your functions that would include the stopwatch code.
You could use a select-case block in your class. Use an enum to call the functions by name. The select block can then run the correct function according to the enum value. It'll be rather long but you only need the stopwatch calls around the select block and they will get called for each function.

Build if then statements at run time?

My product owner has asked me to make some comparision logic configurable so the process engineers can change things without making code changes. Currently the code is a SELECT CASE statement with various IF THEN statements that are fairly standard. The problem I can't seem to find a way around is that he wants through configuration to AND/OR a variable number of comparisons in the IF THEN statements. His idea is the that the configuration would work like a limited query builder for the process engineers. The only solution I've come up with is to build a function in a string and use the VBCodeProvider to compile it at runtime. Is there a better way to approach this?
One way to do it is just store the booleans in your configuration file, load them up at run time, and use them in your code like any other boolean.
A better way would be to have the configuration as close to his problem domain as possible, then code up the proper booleans from those to use in your code.
You could use expressions to accomplish this. With this you would be able to build up an IfExpression and build up its conditions. You would be able to compile this and run it all at runtime.