Printing to console in VDM++? - vdm++

How do I print text or values to the console to validate that my model is working correctly?
I would like to do something like this:
class Main
operations
public Run: () ==> ()
Run() ==
print "Text"
print mon.Func()
end Main
It seems to be possible, but I just cant figure out how to do it.

You need to use the VDM IO library. There are a couple of operations that do what you want - println (for printing fixed values) and printf, which has parameter substitution. So you would call IO`println("hello"), for example.
In the latest release of Overture and VDMJ, you can also use a VDM annotation to print values without adding anything to the "content" of the specification itself. Annotations are rather added as comments. See #Printf.

Nick Battle answered my question but for other beginners to VDM, there is missing a detail to his answer, how to include libraries.
Before one can use the IO library, you first have to include it.
I am using Overture and to include libraries into your project, you have to right-click on the project in the side menu and press New > Add VDM Library.
You can then choose which libraries you want to include in a menu that pops up.
Here you choose IO.
After this you should be able to print out values using the IO`println(val) function.

Related

Sparx Enterprise Architect DocumentGenerator does not honour TaggedValues on Stereotype or values from SetProjectConstants and ReplaceField

maybe someone can help me on this. I am trying to generate a document via the DocumentGenerator interface. All in all this works well, except that the DocumentGenerator does not replace the Report Constants with actual values (which are defined on the report package stereotype.
This is the general flow of the document creation code (which generally works):
var gen = Repository.CreateDocumentGenerator();
gen.SetProjectConstant("ReportName", "My Project");
gen.NewDocument(string.Empty);
gen.ReplaceField("ReportName", "My Project");
gen.InsertCoverPageDocument(tags[REPORT_COVERPAGE]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.InsertTOCDocument(tags[REPORT_TOC]);
gen.InsertBreak(DocumentBreak.breakPage);
gen.DocumentPackage((int)nativeId, 0, template);
gen.SaveDocument(fileName, DocumentType.dtDOCX);
I tried ReplaceField and SetProjectConstant both and one at a time before and after calls to NewDocument/InsertCoverPageDocument:
Strangely there is one constant that is being replaced: ReportSummary.
When I run the document generator via "F8" all constants are being replaced correctly.
Other project constants are being replaced correctly.
I can reproduce the behaviour on EA v14.1.1429 and v12.0.1215.
Does someone have a hint for further troubleshooting? Thanks in advance!
========== UPDATE ==========
When I use ReplaceField at the end (before the actual call to SaveDocument the following Report Constants get replaced: {ReportTitle} and {ReportName}
I discovered some workaround: when I manually remove the predefined {Report~} constants from the template and re-add them as Project Constants, their values get replaced correctly.
I will examine this further and give an update as
I did some further investigation on this and came to the following conclusion and workaround (as I have received no comments or answers on this):
I deleted all references to ReportConstants in my EA templates and replaced them by ProjectConstants with the same name.
In my code where I want to generate the documentation I (re)set all ProjectConstants with the actual values via SetProjectConstant and additionally added a call to ReplaceField to replace the constants with the actual values.
The previous mentioned calls are inserted directly before the call to SaveDocument document.
tags.ForEach(t =>
{
if (string.IsNullOrWhiteSpace(t.Key)) return;
generator.SetProjectConstant(t.Key, t.Value);
generator.ReplaceField(t.Key, t.Value);
});
generator.SaveDocument(fileName, DocumentType.dtDOCX);
If someone comes up with a better resonse or explanation for the behaviour I am happy to accept this as answer.
I have also found that when you call ReplaceField on these project constants in a CoverPage template, the formatting defined in the template is overwritten. It seems that some of the SetProjectConstant calls actually set the values as you would expect, and the rest do not.. hence the need to call both sets of APIs.

How can I create a Hierarchical block with GNURadio Companion?

I am trying to create a Hierarchical block using the GNURadio Companion GUI. Answers I've found in other posts say to select the blocks you want to incorporate, then go to More -> Create Hier. Then a new screen is supposed to appear. However, doing "Create Hier" with any combinations of blocks selected seems to do nothing.
Am I doing something wrong, or is there a problem with my GRC?
It's very simple. You just start with a new flow graph in GRC, and use Pad Sources as input, and Pad Sinks as output.
If you want to let the user configure something, use a Parameter GRC block.
You must set the Generate Options in the Options block to Hier Block, and set a sensible ID there, too – don't stick with top_block, but use something (without spaces or -; it needs to work as a python name) that won't conflict with something else.
Here's an example:
You can then Generate button (or press [F5]), and then, after you've done a rescan of your block library with the refresh button you can find (and use) your new block in the Block Category you specified.

Use the tree-view in Atom editor init script

I'm trying to write a init script for the Atom editor to add a custom command to be able to reveal the currently opened editor file in the tree-view with one key combination, instead of two.
Here is an example code (which makes something different) to make clear how it generally has to look like.
atom.commands.add 'atom-editor', 'custom:cut-line', ->
editor = atom.workspace.getActiveEditor()
editor.selectLine()
editor.cutSelectedText()
The two commands I need should not be sent to the editor, but to the tree-view. Here are the two commands:
tree-view:toggle-focus
tree-view:reveal-active-file
I assume I have to do something similar as above, like getActiveTreeView or something like that. I tried to google it but it doesn't seem to be obvious. Does someone know how to do this?
It could look something like this:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
tree-view.toggle-focus()
tree-view.reveal-active-file()
You can use the atom.commands.dispatch() method to send a command when getting a hold of the object to send the commands to is hard. In your case, you can use:
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')
Sadly, Lee's answer is not correct anymore. Within changes in the API the changed the naming of atom.workspaceView to atom.workspace.
So, if anyone gets here (sure questions and answer is a "bit" old), here's the current working script.
atom.commands.add 'atom-editor', 'custom:show-active-file', ->
atom.commands.dispatch(atom.workspace.element, 'tree-view:toggle-focus')
atom.commands.dispatch(atom.workspace.element, 'tree-view:reveal-active-file')
#Source
https://discuss.atom.io/t/workspaceview-events/14595/4

Perl Catalyst, pass to stash 2 template parts

I started learning Perl Catalyst and its awesome!!! However, I am having a little issue here with templateing.
I am trying to pass two template variables to the page (header and footer), what I did in the Controller function is
$c->stash(template => 'header.html');
//other page contents
$c->stash(template => 'footer.html');
but this only outputs the footer.html (which it should and seems logical)
What would be the way for this approach? I searched google but could not find many helpful results (at least results that I could understand and use)
You need to create a view.
https://metacpan.org/pod/Catalyst::Manual::Tutorial::02_CatalystBasics#Hello-World-Using-a-View-and-a-Template
Also, have a look at how wrappers work in TT -- they are really cool.
http://www.template-toolkit.org/docs/manual/Directives.html#section_WRAPPER
You cannot pass 2 templates in stash.Only the last value will be kept.However the to way to do this, is to include the footer template inside the header.The commands include and process are very helpfull.

Selenium WebDriver with Perl

I am trying to run the Selenium driver with Perl bindings, and due to the lack of examples and documentation, I am running into some roadblocks. I have figured out how to do some basic things, but I seem to be running into some issues with other simple things like validating the text on a page using Remote::Driver package.
If I try to do something like this:
$sel->get("https://www.yahoo.com/" );
$ret = $sel->find_element("//div[contains( text(),'Thursday, April 26, 2012')]");
I get a message back that the element couldn't be found. I am using xpath because the driver package doesn't appear to have a sub specific for finding text.. at least not that I've found.
If my xpath setup is wrong or if someone knows a better way, that would be extremely helpful. I'm having problems with some button clicking too.. but this seems like it should be easier and is bugging me.
Finding text on a web page and comparing that text to some "known good value" using Selenium::Remote::Driver can be implemented as follows:
File: SomeWebApp.pm
package SomeWebApp;
sub get_text_present {
my $self = shift;
my $target = shift;
my $locator = shift;
my $text = $self->{driver}->find_element($target, $locator)->get_text();
return $text;
}
Somewhere in your test script: test.pl
my $text = $some_web_app->get_text_present("MainContent_RequiredFieldValidator6", "id");
The above finds the element identified by $target using the locating scheme identified by $locator and stores it in the variable $text. You can then use that to compare / validate as required / needed.
https is a tad slower loading than http. Although WebDriver is pretty good about waiting until it's figured out that the requested page is fully loaded, maybe you need to give it a little help here. Add a sleep(2); after the get() call and see if it works. If it does, try cutting down to 1 second. You can also do a get_title call to see if you've loaded the page you think you have.
The other possibility is that your text target isn't quite exactly the same as what's on the page. You could try looking first for one word, such as "April", and see if you get a hit, and then expand until you find the mismatch (e.g., does this string actually have a newline or break within it? How about an HTML entity such as a non-breaking space?). Also, you are looking for that bit of text anywhere under a div (all child text supposedly is concatenated, and then the search done). That would more likely cast too wide a net than not get anything at all, but it's worth knowing.