Module Alias Namespace In Alloy 4 - alloy

Lets say I do the following:
open util/ordering[A]
open util/ordering[B]
What value does ordering/first have? Is it undefined? Do you need to use module aliases to disambiguate?

Yes, you should use aliases, e.g., like I did below
open util/ordering[A] as orda
open util/ordering[B] as ordb
sig A{}
sig B{}
sig C {
firstA: A,
firstB: B
} {
firstA = orda/first
firstB = ordb/first
}
run {one C}

Related

Why does alloy model with but 1 set A return instance of more than 1 A

I am sorry for the title, I tried hard to make it as understandable as possible but I know I failed.
Here is the simple model:
sig ETHBusStation {
next: set ETHBusStation
}
one sig Polyterrasse, HaldenRight, HaldenLeft, Hoengg extends ETHBusStation {}
sig ETHBus {
station: lone ETHBusStation
}
fact {
//no (Hoengg - HaldenRight)
all s: ETHBusStation | ETHBusStation in s.^next and some s.next
all b1, b2: ETHBus | b1.station != b2.station}
run {} for 2 but 1 ETHBusStation
when I run the analyzer it finds an instance with one of each Polyterrasse, HaldenRight, HaldenLeft, Hoengg
but since these are all disjoint subsets of ETHBusStation, how can this be with the but 1 parameter?
I am expecting it to have a single station that links to itself via next.
I am grateful for any hints and tips.
If we use in instead of extends it behaves as expected, but then they also don't have to be disjoint which makes sense.
I believe the scope declaration is being overridden by the one sig decl. If it didn't do this, the expected behavior would be to find no instances, since the sig decl claims that exactly four bus stations exist, and the scope says that there is at most one bus station.

How to use an enumerated type in a class outside of the file where it is declared in system verilog

So I have the following code in bool_struct.sv:
typedef enum {false=0, true=1} bool;
class my_bool_class;
bool my_bool_value;
function new (bool initial_bool_value)
my_bool_value = initial_bool_value;
endfunction
endclass
In checker.sv I want to do the following:
class checker;
my_bool_class bool_class_handle = new(true)
endclass
My question is, will this compile? I imagine the "true" in the new call will be out of the scope of the typedef so it will not. How do I get that "true" in the new call to work?
A typedef for an enumerated type declares all the labels as well as the enumeration at the same level (That is why you cannot declare two different enumerations with overlapping labels in the same scope).
What you should always do is put typedefs and class declarations in a package and then import the package where you want to use bool, false, true, and my_bool.
See http://go.mentor.com/package-import-versus-include

Structs in Lua?

I searched but not found anything can help me.
I have the following C struct:
struct Home {
int num;
int city_ID;
int area_ID;
};
How do I write this in Lua?
Thanks in advance.
Tables is the closest thing to a struct that you get in Lua:
local s = {}
s.num = 2
s.city_id = 234
s.area_id = 2345
Now you can use struct syntax on it:
print(s.area_id)
Lua provides tables, which can be used as dynamic structs, in which fields are added dynamically.
You could create a table for your example with this code:
s = {
num = 2,
city_id = 234,
area_id = 2345,
}
To access its fields, use s.area_id, etc.
Read Lua 5.3 reference manual.
You'll either use tables or (for struct-s implemented by some C code!) userdata.

Alloy - scope for this/Univ, ordering, "open" statement

I am having errors in Alloy (4.2) specifications of the following kind:
You must specify a scope for sig "this/Univ"
The issue is easy to reproduce with a toy example:
open util/ordering[State]
open util/integer
sig State { value : Int }
fact {
first.value = 0
all s:State, s': s.next | s'.value = plus[s.value, 1]
}
run { } for 5 State, 3 Int
All of the above is fine. Now, when I define State in an external file and import it with an open statement, I get the "Univ scope" error:
open util/ordering[State]
open util/integer
open State
fact {
first.value = 0
all s:State, s': s.next | s'.value = plus[s.value, 1]
}
run { } for 5 State, 3 Int
I tried several variations of the above without success.
Why does this happen and how can it be solved?
In my project, it would be useful for me to define the target sig of the ordering module in a different file.
Thanks,
Eduardo
This is an Alloy "design bug".
It was decided that a Univ signature would appear when no signatures are defined in the module in order to check some property over built-in relations (e.g., unit, iden, none).
You have many ways of going around this problem, here is a selection :
You can add ",0 Univ" at the end of your run command
You can add a signature in your Alloy module
You can specify a global scope of zero (run { } for 0 but 5 State, 3 Int )
See this question for additional informations

How to join multiple variable declarations with Resharper?

If I have
class A
{
int a;
int b;
}
Is there a way for resharper to reformat this code on "code cleanup" action to the following?
class A
{
int a, b;
}
There is no way to do it in ReSharper because this is considered a bad style. See Why do you not declare several variables of the same type on the same line? and Declaring Multiple Variables in JavaScript

Resources