Hi everyone,
I have a file MY_TOOL.thy. I am trying to add a new variable $MY_TOOL_HOME that contains the directory of MY_TOOL without hardcoding it.
I see two ways:
ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)/../.."; pwd)"
is set in build_release.scala. I have not worked with scala before and am not sure how to connect it to my current theory.
Can anyone explain to me what the best way is and how to get to my goal?
Where are you planning to use the variable $MY_TOOL_HOME
? In independent shell scripts?
In the theory itself. As an argument to a command I wrote.
In ML I can write OS.FileSys.getDir()
to get the current directory (the one isabelle is started in) and I am sure that there is a way to get the one of the current file. But then, when I want to use the variable that contains that directory I would need to write a keywords
for it which does not seem right for a path variable like this
You could try passing ML code that retrieves the directory to the command that you wrote. The command can then evaluate the code to get the directory.
Thanks, that sounds great! How do I do that? They way I know to do something like this is to define a new keyword
keywords "my_new_command" :: diag
and then do something like this:
val _ = Outer_Syntax.local_theory \<^command_keyword>‹my_new_command› ...
I don't know if it is the best example but @Kevin Kappelmann logger antiquotation parses ML code and evaluates it to determine log levels. looking at the ML
command is easier.
Hanna Lachnitt said:
Thanks, that sounds great! How do I do that? They way I know to do something like this is to define a new keyword
keywords "my_new_command" :: diag
and then do something like this:
val _ = Outer_Syntax.local_theory \<^command_keyword>‹my_new_command› ...
The approach is the same. You just use Parse.embedded
or Parse.ML_source
to parse ML code and then other functions (not an expert there) to evaluate the code.
Perhaps it is easier to look at the implementation of the ML
command
Thanks, I'll look into it! It's not super critical but it would be a nice feature for my tool
Hanna Lachnitt said:
In ML I can write
OS.FileSys.getDir()
to get the current directory (the one isabelle is started in) and I am sure that there is a way to get the one of the current file. But then, when I want to use the variable that contains that directory I would need to write akeywords
for it which does not seem right for a path variable like this
Do you really need to pass the directory as an argument to the command or is it that you always pass the same argument (i.e. the directory of your tool) to the command anyway?
In the latter case, just get rid of the argument and use ML to retrieve the directory.
In the former, you can use this to evaluate parsed ML code as an attribute, and here, at ML_int
, you can see how one might use this attribute evaluation to obtain a primitive value from the parsed ML code. Beware: it is kind of a hack because it requires the invariant that the name of the ML structure that evaluates your code won't be shadowed in the future (which you cannot guarantee in general). Only use this if you know what you are doing :upside_down:
Last updated: Dec 21 2024 at 16:20 UTC