Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added watch.sh #9

Merged
merged 4 commits into from
Dec 9, 2024
Merged

Added watch.sh #9

merged 4 commits into from
Dec 9, 2024

Conversation

johannesloetzsch
Copy link
Contributor

Use inotifywait (from inotify-tools) to rebuild everytime the SOURCE changed

@johannesloetzsch
Copy link
Contributor Author

Till now, there is one minor issue:
In case of syntax errors, doclog.sh keeps running, prompting the user in a prolog repl.
When using watch.sh this is not intended. It would be nice to exit doclog after errors instead.

I could work around this in watch.sh but I would prefer, to have this as default behavior of doclog.sh. What do you think @aarroyoc ?

@aarroyoc
Copy link
Owner

It should be possible to add a catch/3 that prevents going back to the REPL. Give me a few days

@johannesloetzsch
Copy link
Contributor Author

johannesloetzsch commented Oct 29, 2024

It should be possible to add a catch/3 that prevents going back to the REPL. Give me a few days

Thank you :)

Even without I used DocLog with watch.sh quite extensively and successful :)
Till now when errors occur. Ctrl+d closes the repl and continues the watch loop.

I wrote a little tutorial about how to use prolog + scryer + playground. I assume I will push it soon and will let you know than…

Are you interested in a listing of issues, workarounds and error messages I experienced, while working with DocLog?

@triska
Copy link

triska commented Oct 29, 2024

It should be possible to add a catch/3 that prevents going back to the REPL.

One elegant and also more generally useful way to solve this would be to add a -t Goal command line option to Scryer Prolog itself, which would specify the Goal to use as the toplevel.

For instance, by specifying -t halt, we would invoke Scryer Prolog in such a way that any goals are run, and then the process halts, no matter in which way the "toplevel" was reached, i.e., whether the initialization and any given goals succeeded, failed or resulted in an exception.

@triska
Copy link

triska commented Oct 29, 2024

Previous related discussion: mthom/scryer-prolog#187 (comment)

@aarroyoc
Copy link
Owner

While we implement that on Scryer, I pushed a commit that wraps everything in a catch/3. Let me know if it works for you

@triska maybe that flag deserves its own issue as the original one was closed

@johannesloetzsch
Copy link
Contributor Author

@triska Thanks for your support :) -t halt sounds like a good improvement in the future

@aarroyoc Thank you for the catch wrap :) I tested it and it works for many cases.
I added a little change to print the error message before halting.

There are some cases when the catch is not enough. Here an example in case you would like to reproduce:

  • edit doclog.config.pl and add a bug like trying to use page/4 instead of page/3:
page("Test page", "First steps", "test-page.dj", "this causes an error")

When starting DocLog, I get:

% Warning: initialization failed for: run("~/src/prolog/scryer-prolog","~/src/prolog/scryer-prolog/target")
?- 

Obviously parsing the config was not catched.

In practice there is one case I had several times, when I produced syntax-errors in the config:
For adding new pages, I copied the entry of the last page and adopted it, but forget to add a comma to the now second last entry.

If you have a simple fix for catching syntax-errors during initialization (e.g. by consulting the config from main inside the catch) I appreciate it. If not, it should be fine too.

From my perspective the feature works well enough to be merged.

@triska
Copy link

triska commented Oct 31, 2024

Not yet having a -t switch, an appropriate construct could be call_cleanup/2 from library(iso_ext): It reliably performs the cleanup, which in this case would be halt.

@triska
Copy link

triska commented Oct 31, 2024

maybe that flag deserves its own issue as the original one was closed

Yes thank you, good point, I have filed mthom/scryer-prolog#2651 for it!

@triska
Copy link

triska commented Oct 31, 2024

As mentioned by @hurufu in mthom/scryer-prolog#2651 (comment), multiple -g switches can be used, so adding -g halt to the invocation may suffice to solve this more elegantly!

@aarroyoc
Copy link
Owner

Does the proposed solution by @triska work for you?

johannesloetzsch added a commit to johannesloetzsch/doclog that referenced this pull request Nov 10, 2024
@johannesloetzsch
Copy link
Contributor Author

Does the proposed solution by @triska work for you?

Yes, seems to work well :)

From my side, this PR is ready to be merged

doclog.sh Outdated
@@ -5,5 +5,5 @@ SOURCE=$(realpath $1)
OUTPUT=$(realpath $2)

cd $DOCLOG
scryer-prolog -g 'run("'$SOURCE'", "'$OUTPUT'").' main.pl
scryer-prolog -g 'run("'$SOURCE'", "'$OUTPUT'").' -g 'halt.' main.pl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-g halt should work.

@@ -5,5 +5,5 @@ SOURCE=$(realpath $1)
OUTPUT=$(realpath $2)

cd $DOCLOG
scryer-prolog -g 'run("'$SOURCE'", "'$OUTPUT'").' main.pl
scryer-prolog -g 'run("'$SOURCE'", "'$OUTPUT'").' -g 'halt' main.pl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, I think -g halt would work.

@aarroyoc aarroyoc merged commit 82c2d8c into aarroyoc:master Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants