I have the following specification in Alloy:
sig A {}
sig Q{isA: one A}
fact {
all c1,c2:Q | c1.isA=c2.isA => c1=c2 // injective mapping
all a1:A | some c1:Q | c1.isA=a1 //surjective
}
run {} for 4
When I generate an instance of this specification, an extra arrow appears in the demonstration of the instances like $c1 arrow bellow in the picture. How can I avoid appearing such kind of arrows in instance demonstration? Is there any way to tell instance demonstrator interface not to show them?
By a bit of search I found the answer:
It is only necessary to define a desired Theme in the demonstration window: click the Theme button in the toolbar and do what ever you'd like! In above specific case remove the tick from the "show as arcs" option of arrow $c1 in the theme window!
Related
Say we have
class Foo {}
Is there a way to obtain "Foo" from within the class?
Yes.
class Foo {
say ::?CLASS.^name; # OUTPUT: Foo
}
Kaiepi's solution has its place, which I'll get to below, but also consider:
class Foo {
say Foo.perl; # Foo
say OUR.WHO; # Foo
::?PACKAGE
}
Foo.perl
This provides a simple answer to your literal question (though it ignores what you're really after, as explained in your comment below and as suggested by the metaprogramming tag and your use of the word "introspection").
OUR.WHO
I think this is typically more appropriate than ::?CLASS.^name for several reasons:
Looks less line-noisy.
Works for all forms of package, i.e. ones declared with the built in declarators package, module, grammar, or role as well as class, and also custom declarators like actor, monitor, etc.
Will lead readers to mostly directly pertinent issues if they investigate OUR and/or .WHO in contrast to mostly distracting arcana if they investigate the ::?... construct.
::?CLASS vs ::?PACKAGE
OUR.WHO only works in a value grammatical slot, not a type grammatical slot. For the latter you need a suitable ::?... form, eg:
class Foo { has ::?CLASS $bar }
And these ::?... forms also work as values:
class Foo { has $bar = ::?CLASS }
So, despite their relative ugliness, they're more general in this particular sense. That said, if generality is at a premium then ::?PACKAGE goes one better because it works for all forms of package.
Below is an Alloy representation of two desktops. In the fact I specify that the first desktop contains two icons, A and B, and the second desktop contains one icon, A. I'd like to specify that there are exactly two Desktops, so I put this in the fact:
#Desktop = 2
When I did the run command, I got this message: No instance found. When I omitted that from the fact and instead specified the number of Desktops in the run command:
run {} but 2 Desktop
then the desired instance was generated. Why? Why doesn't it work when I constrain the number of Desktops in the fact, but does work when I constrain the number of Desktops in the run command?
open util/ordering[Desktop]
sig Desktop {
icons: set Icon
}
abstract sig Icon {}
one sig A extends Icon {}
one sig B extends Icon {}
fact {
first.icons = A + B
first.next.icons = A
}
According to page 283 of the Alloy Reference, if no explicit bound is specified for a signature and no implicit bound can be found, that signature defaults to at most 3 elements. run {#Desktop = 3} works by default.
You also have open util/ordering[Desktop]. That module starts with module util/ordering[exactly elem], which adds the exactly constraint to the scope. This means that the implicit bound is exactly 3 elements, so run {#Desktop = 2} fails. Adding run {#Desktop = 2} for 2 changes the implicit bound to 2 elements per signature, so it succeeds.
I'm building a multi-modal editor using reactive-banana - and for the most part it's going perfect. To expand on my scenario, the editor is some mapping software, or you could think of it as a very simple vector graphics editor. It currently has two states - selection mode and polygon creation mode. In selection mode, the user is able to select previously created polygons with the right mouse button (which would in theory take you to a new selected mode) or they can begin creating a new polygon with the left mouse button.
The intention is, when the left mouse button is pressed, we switch from selection mode into polygon creation mode. In this mode, a left mouse button means "add a new vertex", until the user returns to the original vertex. At this point, they have closed the polygon, so we return to selection mode.
I've implemented this a few different ways, and recently noticed that event switch almost makes this very elegant. I can have:
defaultMode :: Frameworks t => HadoomGUI -> Moment t (Behavior t Diagram)
defaultMode gui#HadoomGUI{..} =
do mouseMoved <- registerMotionNotify guiMap
mouseClicked <- registerMouseClicked guiMap
let lmbClicked = ...
gridCoords = ...
diagram = ...
switchToCreateSector <- execute ((\m ->
FrameworksMoment
(=<< trimB =<< createSectorMode gui emptySectorBuilder m)) <$>
(gridCoords <# lmbClicked))
return (switchB diagram switchToCreateSector)
Along with
createSectorMode :: Frameworks t
=> HadoomGUI
-> SectorBuilder
-> Point V2 Double
-> Moment t (Behavior t Diagram)
createSectorMode HadoomGUI{..} initialSectorBuilder firstVertex =
do mouseClicked <- registerMouseClicked guiMap
...
This certainly works - for a single mouse click. If I click on the map once, I switch into sector creation mode from the state I was just in. However, if I click again, defaultMode receives the click event and switches into a new polygon creation mode, throwing away my previous state.
What I'd like to do is switch in defaultMode once and never have the possibility of coming back. Essentially I want to "swap" the Behavior t Diagram produced by defaultMode with the result of createSectorMode.
I understand reactive-banana has problems with garbage collection of dynamic events, but I'm willing to live with that for now. The above formulation is significantly more precise than anything else I've written so far - such as having a single CurrentState variable and filtering various events based on the contents of that. The problem I have with this is that it's too big, and leaves way too much scope for me to mess things up. With switching, I only have in scope the events I can about.
The problem is somewhat open ended, so I can't give a definite answer. But I can certainly give my opinion. ;-)
However, what I would probably do is to separate the switching between modes from the behavior within a mode. If we forget about FRP for a moment, your program looks a bit like pair of functions that recursively call themselves:
defaultMode = ... `andthen` sectorMode
sectorMode = ... `andthen` defaultMode
It's written a bit like a "sequential" program, "first do this mode, then do that mode". I think there is nothing wrong with that, though the default API reactive-banana, in particular switchB, does not support that style very well. You mentioned (privately) that you can write a
once :: Event t a -> Event t a
combinator that lets through the first occurrence of an event, but discards the rest. This is indeed what you would need for the sequential style.
Since you always return to the default mode, though, I would probably try a different approach, where each mode has an event that indicates that it wants to be switched away. The switching itself is taken care of by an "outside" entity. The idea is to avoid the explicit recursion in the program above by some higher-order combinator. In pseudo-code, this would look something like this:
modeManager = switchB initialMode changeMode
changeMode = defaultModeSwitch `union` sectorModeSwitch
though I am a bit unsure about the details. In fact, I'm not entirely sure if it works at all, you probably still need the once combinator.
Anyway, that's just an idea on how to go about the switching. I fully agree that switching is the right way to deal with different modes.
I have an edit control which should only take integers betweeen 1 and 99.To achieve this, i used, modifystyle() and limittext().Is there a way to restrict 0 from being entered?
You do not have to control values limit it using your code.
It is easier if you subclass (add variable) edit control using wizard, you can choose UINT type and set minimum and maximum value here.
Also do nto forget to set style to ES_NUMBER (setting Number to True in edit control Properties).
If you absolutely need that, you must derive a class from CEdit and process the input accordingly. Rendering the baloon that says "Unacceptable Character" may be bit tricky to give online-error. The class would be useful only if you are planning to use such class (edit-control) at multiple places, preferably with different ranges.
This is completely different problem from than one in your original post.
Make sure that your spin control follows immediately edit control in the Z-order (tab order).
In the resource set spinner style to: UDS_AUTOBUDDY UDS_SETBUDDYINT, UDS_ALIGNRIGHT,.
This will causse spinner to: choose edit control as buddy, set integer in edit box, place itself inside edit control to the right edge.
To do that, in the properties for the spinner set: "Auto Buddy" True, "Set Buddy Integer" True and "Alingment" to Right Align.
You do nto have to set minimum and maximum for the edit control, handle it now in the command handler for EN_CHANGE notification.
Place this code in the handler.
void CYourDlg::OnEnChangeEditNum()
{
int iValue = GetDlgItemInt(IDC_EDIT1);
if(iValue < 1 || iValue > 99)
{
m_Edit.ShowBalloonTip(_T("Number Out of Range"), _T("Value must fall between 1 and 99."), TTI_INFO_LARGE);
}
}
I want to achieve something like this in Enterprise Architect's Communication Diagrams:
start() ---------------- 1. create() ------------
------------> | RGController | ---------------> | U : User |
---------------- ------------
But I am facing 2 problems:
It seems I have to always make a
connection between 2 objects (I
can't have the start() message just
come out of nowhere, like I'd want).
I can't control the numbering as I'd
want. Is there any way I could just
set the numbering by myself? If I
define that an actor is calling
start() on RGController, it will
call it message 1 when I'd want
message 1 to be User.create().
A) Which Object is sending the start() message to RGController? Add it to the diagram and create the connection between these two objects.
Alternatively you could send the initial message from an Inital element (in the Activity toolbox).
You could also hack an invisible start element by creating an empty shape rendering script.
Just create a new Stereotype in Settings->UML...->Stereotypes, set the name to hidden, applied to , and set the shape script as:
shape main {
}
Then apply this stereotype to your initial element. It should be rendered as invisible.
B) I'm not sure how to manually set the message labeling. Are you aware of the message numbering settings?
right clicking one of the message
labels an selecting "Sequence
Communication Messages".
checking "start new group" in the
Message Properties->Sequnce
Expressions section.
Are you trying to draw an architecture which uses a Front-controller or Facade for handling incoming request?
If so in that case the client will call the start(). E.g. In case of an ASP.net application, it will be the UI code or presentation logic.
Client/User/Customer ---start()---> RGBController--- create() ---> u: User