if I have a set of certain sig e.g. I formulate a set of closed_Switches. Can I get a set of open_switches (or all the switches that are not closed) as following
some x:Switch | x = (univ - closed_switches) => "and then imply something on x"
Just started using alloy, is this a correct way of approaching this problem.
If you mean the set of all open switches, then use the expression containing
Switch - closed_switches
which you could give a name to:
let open_switches = Switch - closed_switches | ...stuff about open_switches...
If you want to work with one open switch then something like:
some x : Switch - closed_switches | ...stuff about x...
Related
I am looking for a M-Function that returns the currently opened Excel Spreadsheet Filename without the directory and extension.
i.e. If the spreadsheet that is opened is located here:
C:\HPCLMHSTLI_930.XLSX
I would like:
HPCLMHSTLI_930
Note: I got this working using a Custom M Function that reads a Settings Table which has two Cells defined with the following:
=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)
=LEFT(B3,(SEARCH(".",B3)-1))
So I am NOT looking for this solution. This solution just seems like a lot of work and that there should be a more elegant M-Language function that would return the currently opened spreadsheet filename.
I didn't quite follow how you got the path - I guess that is Cell("fileName"), but with a bit of fiddling with M Code, I came up with the following:
let
x = "C:\HPCLMHSTLI_930.XLSX",
y=Text.AfterDelimiter(x,"\"),
z=Text.BeforeDelimiter(y,".")
in
z
This seems to do the trick. Since a file name can have more than 1 period in it, this may be too simple, but maybe this can work if your filenames are simple enough.
But this can be improved by wrapping this in a function in the following way:
let
ParseFileName = (x) =>
let
y=Text.AfterDelimiter(x,"\"),
z=Text.BeforeDelimiter(y,".")
in z
in
ParseFileName
and then call that using something like this:
let
Source = ParseFileName("C:\HPCLMHSTLI_930.XLSX")
in
Source
I found two more possible answers.
This first is a bit more sophisticated than the one above. In this case, we grab the substring starting after the first "\" and the last "."
let
x = "C:\HPCLMHSTLI_930.XLSX",
y = Text.PositionOf(x,"\", Occurrence.First),
z = Text.PositionOf(x,".", Occurrence.Last),
a = Text.Middle(x,y+1,z-y-1)
in
a
There probably should be if statements in case one of these characters are not found.
I found one final solution that could also work in the simpler cases.
let
x = "C:\HPCLMHSTLI_930.XLSX",
z = Text.BetweenDelimiters(x,"\",".")
in
z
M gives us a bunch of choices on this.
I was trying to convert a match object to a string in perl6. The method Str on a match object is defined as:
method Str(Match:D: --> Str:D)
I would think I could use Str($match) to accomplish this. And it seems to convert it to a string, but I'm getting an error using the string with the following code:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = Str($match);
say $test1.WHAT;
say $test1;
With the output:
(Match)
(Str)
With the error:
Cannot find method 'gist': no method cache and no .^find_method in
block at .code.tio line 6
However, if I run:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = $match.Str;
say $test1.WHAT;
say $test1;
I get no error and the result:
(Match)
(Str)
rudolph
Is this a bug or me misunderstanding how it works?
Thanks for reading.
I'm writing this up as an answer even though it's actually an incomplete discussion of a bug, so not at all normal SO fare. The alternative of lots of comments doesn't seem better.
It's a bug. Perhaps you just golfed this.
dd $test1; instead of say $test1; is helpful in that it displays BOOTStr $test1 = (BOOTStr without .perl method).
Based on that I searched the rakudo repo for BOOTStr and that led to the above issue.
Golfing it further leads to:
say $ = Str(Match.new);
Note that these are all fine:
say Str(Match.new);
say $ = Int(Match.new);
say $ = Str(Date.new: '2015-12-31');
It appears to be a combination of leaking some implementation details regarding how Rakudo/NQP/MoarVM bootstrap; Match being an NQP object; Str() on that being wonky; and assigning it to a Scalar container (the $ is an anonymous one) making that wonkiness visible.
I'll add more when/if I figure it out.
I am using asciidoctor using asciidoctor-maven-plugin. In my document (actually documentation), I have one block repeated many times. Is there any way to do include with parameters.
What I want in pseudocode, I can't find how to write it:
template:
=== HTTP request
include::{snippets}/{variable}/http-request.adoc[]
=== HTTP response
include::{snippets}/{variable}/http-response.adoc[]
Usage
include template[variable=customer]
Thanks.
I think you can redefine attributes. With this tree:
Folder
| main.adoc
| template.adoc
|
\---code
+---first
| http-request.adoc
| http-response.adoc
|
\---second
http-request.adoc
http-response.adoc
My main.adoc file looks like this:
:snippets: code
== First Chapter
:variable: first
include::template.adoc[]
== Second Chapter
:variable: second
include::template.adoc[]
== End
This is the end.
The previous example works, but I have the feeling that this is not exactly what you want.
If you are looking for a Macro example, have a look at this maven & java example: java-extension-example.
Section 5.2 of the Haskell 2010 Report deals with module export lists. At one point, it says:
Entities in an export list may be named as follows:
A value, field name, or class method, whether declared in the module body or imported, may be named by giving the name of the value as a qvarid, which must be in scope. Operators should be enclosed in parentheses to turn them into qvarids.
...
But, uh... am I missing something? Because according to the Syntax Reference in Chapter 10:
qvarid → [ monid . ] varid
varid → ( small { small | large | digit | ' })
So in which universe does putting an operator in brackets turn it into a qvarid? It looks to me like an operator is clearly a varsym (or maybe qvarsym).
Does anybody know what's going on here? I mean, clearly Haskell definitely supports writing operators in an export list, but the syntax description in the Report doesn't appear to make sense...
Wait, hold up... According to the Control-Free Syntax given in section 10.5:
export → qvar | qtycon ... | qtycls ... | module monid
...
var → varid | ( varsym )
qvar → qvarid | ( qvarsym )
So it seems that it's not a qvarid, it's supposed to be a qvar. So it's just a typo, I guess? Is there a process for having such things fixed in the official report?
I'm a new R user, and work requires that I use R on linux. I am running into a very strange problem, and hope some of you expert users can provide a solution. :)
I have a large dataset with >200,000 observations/participants and >300 variables, that involves subsetting from various baseline datasets to create the working dataset.
My issue is that an essential variable changes some times when I run the length command.
"Withdrawlevel" is the variable that changes. This is how this variable should be:
describe(tbl$Withdrawlevel)
tbl$Withdrawlevel
n missing unique Mean
2833 218988 3 1.474
I then run several length commands like the following because I'm interested in getting the number of participants that meet certain criteria.
For example:
length(which(tbl[,'Reg_age_dob']>=18 & as.Date(tbl[,'QuestionnaireEndDate'])>='2013-07-21' & as.Date(tbl[,'QuestionnaireEndDate'])< '2013-07-28' & (is.na(tbl$Withdrawlevel) | (tbl$Withdrawlevel!=3) & (tbl$WithdrawDate<'2013-07-28')) | ((tbl$Withdrawlevel=3) & (tbl$WithdrawDate>='2013-07-28')) ))
And, then Withdrawlevel variable changes:
describe(tbl$Withdrawlevel) tbl$Withdrawlevel
n missing unique Mean
221821 0 1 3
Is the length command described above doing something to this variable, because my understanding is that it shouldn't. And, I have run many similar commands with this data, and this issue doesn't occur after each one.
Any insight into what is going on and how I can resolve this issue?
tbl$Withdrawlevel=3 assigns the value 3 to all observations of tbl$Withdrawlevel. You meant tbl$Withdrawlevel==3.
(Joshua's answer is correct.) In the future you can protect yourself against this sort of error by using with:
with( tbl, length( which(Reg_age_dob >=18 &
as.Date(QuestionnaireEndDate) >='2013-07-21' &
as.Date(QuestionnaireEndDate) < '2013-07-28' &
( is.na(tbl$Withdrawlevel) | (Withdrawlevel!=3) & ( WithdrawDate <'2013-07-28') ) |
( (tbl$Withdrawlevel=3) & ( WithdrawDate >='2013-07-28') ) )
)
)
The point is that this does not have the danger of corrupting your data object and it's also much easier to understand.
You should be using booleans for all your expressions in your which function. Make sure to use == instead of = which returns a value of True or False rather than setting the variable to equal the value.