What does an interpreter command do in unix/tcl? - unix

I am observing one command in my TCL code (interpreter) . the command name is "interpreter" .
I searched on the google for this command , but I did not get much information .
Can anyone explain about this command ?
Thanks in advance .

Looks like I'm a year late, but maybe you're using Expect, a tcl plugin?
If you follow the link above search for interpreter " with ctrl+f you will find the following (bizarrely formatted) description:
causes the user to be interactively prompted for Expect and Tcl commands. The result of each command is printed.
Actions such as break and continue cause control structures (i.e., for, proc) to behave in the usual way. However return causes interpreter to return to its caller, while inter_return causes interpreter to cause a return in its caller. For example, if "proc foo" called interpreter which then executed the action inter_return, proc foo would return. Any other command causes interpreter to continue prompting for new commands.
By default, the prompt contains two integers.
The first integer describes the depth of the evaluation stack (i.e., how many times Tcl_Eval has been called). The second integer is the Tcl history identifier. The prompt can be set by defining a procedure called "prompt1" whose return value becomes the next prompt. If a statement has open quotes, parens, braces, or brackets, a secondary prompt (by default "+> ") is issued upon newline. The secondary prompt may be set by defining a procedure called "prompt2".
tl;dr: It pauses your script and allows you to execute tcl commands

Related

How to use Wingethandle in Robot framework

I try to use this in Robot framework
#{Title} = Win get handle("[ACTIVE]")
But It seem doesn't work.I need some Example for this command.
Please Help
Sorry for my poor Grammar
**ERROR**
Cannot set variable '#{Title}': Expected list-like value, got string.
When running keywords, you don't use parentheses after the keyword to submit parameters. Instead use:
${Title}= Win Get Handle [ACTIVE]
The [ACTIVE] parameter is automatically submitted as a string.
Also, notice that I changed #{Title} into ${Title}. That is because # denotes a list variable that expects a list return from the keyword. Apparently the Win get handle returns a String variable, which shall be assigned to a scalar $-denoted variable.
Lastly, I'm not sure if you're using Win Get Handle correctly. To my understanding the implementation for that keyword would return a handle to a window (a unique identifier to run further actions against it) rather than its title.

How do I check whether a file exists without exceptions in Julia?

How do I see if a file exists without exceptions using Julia? I want to make sure that my program does not crash if for some reason the file I am trying to open is not accessible, has been deleted, or does not exist.
There are two simple ways of doing so.
First:
println(isfile("Sphere.jl"))
false
This isfile() function will simply check if the file exists. Note: if Sphere.jl is not in your current file path, you would need to provide the absolute path to get to that file.
Second (more of a trial by fire example):
try
open("Sphere.jl", "w") do s
println(s, "Hi")
end
catch
#warn "Could not open the file to write."
end
The second example utilizes the try-catch schema. It is always best for your program to not have to deal with errors so it's recommended that you use isfile() unless you have to use try-catch for your use case.
It's worth noting that there may be some cases where the file exists, but writing to it is not possible (i.e. it's locked by the os). In that case, using try-catch is a great option when attempting to write.

What does "1<" accomplish?

I'm trying to understand how the shell handles redirection a little bit better. My understanding is that the syntax "n<" means to redirect the file descriptor given by "n."
The command I'm struggling to understand is
echo "first" > test; echo "second" 1< test
What I thought would happen is that the file "test" would be overwritten with the text "first"; then, when the second command executed, 1--i.e., stdout--would be redirected to test.
What actually happens is the following:
Nothing writes to terminal, so stdout was redirected somewhere;
When I open "test," what's written is "first" rather than "second," so I didn't overwrite "test."
Can anyone explain what's going on? Is it that stdout is being redirected to test but in "readonly" mode or something like that? I can't find any reference to using 1< in a script elsewhere (since, admittedly, it seems like a strange thing to do).
The shell redirection 1<foo makes FD 1, aka stdout -- normally an output descriptor -- connected to a read-only handle on file foo.
Thus, when echo tries to write to that read-only handle, it will fail; in most reasonable shells, this will also write an error message to stderr.
In this context, that code serves no purpose, and is simply a bug; you'd need to have a program that tried to read from FD 1 (perhaps assuming that to be a connection to the current terminal) for it to be meaningful. (That said, any program that did this would be buggy itself; reads should be done, if not through FD 0, from a handle direct on /dev/tty).

Running Go from the command line nested JSON

I can think of workarounds on how to get this working however I'm interested in finding out if there's a solution to this specific problem.
I've got a go program which requires a json string arguement:
go run main.go "{ \"field\" : \"value\" }"
No problems so far. However, am I able to run from the command line if one of the json values is another json string?
go run main.go "{ \"json-string\" : \"{\"nestedfield\" : \"nestedvalue\"}\" }"
It would seem that adding escape characters incorrectly matches up the opening and closing quotes. Am I minuderstanding how this is done or is it (and this is the side I'm coming down on) simply not possible?
To reiterate, this is a question that has piqued my curiosity - I'm aware of alternative approaches - I'm hoping for input related to this specific problem.
Why don't you just put your json config to the file and provide config file name to your application using flag package
Based on the feedback from wiredeye I went down the argument route instead. I've modified the program to run on:
go run main.go field:value field2:value json-string:"{\"nestedfield\":nestedvalue}"
I can then iterate over the os.Args and get the nested json within my program. I'm not using flags directly as I don't know the amount of inputs into the program which would have required me to use duplicate flags (not supported) or parse the flag to a collection (doesn't seem to be supported).
Thanks wiredeye

Simplest way to validate non-library module

What is the simplest way to validate there are no syntax errors in an XQuery file? I want to test a number of xquery files as a part of routine testing to verify that no bad files exist with simple syntax errors. Generally for library modules I import the library module and that is enough to validate syntax of the file.
BaseX has an option RUNQUERY that can be used to disable query execution, so it only gets parsed. For using the command line, use the -R off flag.
The query can be passed as string, here I'm using the very simple query 1+1, which is totally valid and will not return any output, but a return value of 0.
basex -R off "1+1"
Passing an invalid query will return a syntax error message, and a non-zero return code.
basex -R off "1foo"
Stopped at [snip], 1/2:
[XPST0003] Expecting separator after number.
I guess there will be similar options for other XQuery implementations, but they're not standardized, so you'll have to look them up in the individual manuals.

Resources