What is a value called, that signals that nothing has happened? - semantics

I'm at a loss for what to call that or even what to search for.
What I'm looking for is something like this:
value = None
if something_is_true:
value = 123
if value is not None:
send(value)
What is the use of None called in this instance? In my head it sounds something like Cardinal Value, although that is not it.

The word you're probably looking for is "sentinel", that is a variable that triggers some behavior depending on whether it's set or not.
For further information see Sentinel value on Wikipedia.

Related

easiest way to figure out what waiver() is doing?

If one looks at the (e.g.) ggplot2::scale_y_continuous, the default value of many of the arguments is set to waiver(), e.g. for breaks:
‘waiver()’ for the default breaks computed by the
transformation object
How does one figure out/look at how these defaults are computed? Let's say I want to find the breaks for scale_y_log10(). ?scales::log10_trans doesn't say anything about computation of breakpoints.
I think log10_trans()$breaks might do it, which is the same as ?log_breaks. Not sure how to figure this out in general, though ...

AnyLogic - Why does my condition based transition not work?

I have a question related to a transition in my statechart (see image above). I have a variable called palletInUse which is a boolean-type and changes between true and false. For one transition in my statechart I want it to change when the variable palletInUse has the value true. I have tried it with for example:
palletInUse == true;
and also tried different code like, equals and contentEquals etc. but nothing seems to work. Do you have a solution for this, seemingly simple problem?
Thanks in advance
The condition is not monitored constantly, only when something is changed in the agent. When you assign a new value to variable with common "=" Java operator, it is not caught by the AnyLogic engine. You need to call onChange() function after that. Then, the transition should be executed.
There are other ways to trigger the condition check without explicit onChange() call. You may find them in AnyLogic Help article.
BTW, you may specify just boolean variable as the condition, it is not required to compare it with true or false:
palletInUse
The condition is not evaluated if nothing is happening, for that reason you have to make something happen constantly to have your condition evaluated. A typical way of doing is as you see in the following pictures:

how to decide if a element is in a set in GAMS

The situation is: I define a set in gams, like:
set n /n1*n100/;
And later in the code, I want to find a way to decide a if a element is in a set. For example, I want to have a function f, such that
(1) if a element in a set, it returns true(or '1'). Like, f('n1',n) = true(or '1')
(2) if a element not in a set, it returns false(or '0'). Like, f('n111',n) = false(or '0')
Does anyone know if there exists this kink of function? Also, if exists, does it also works for multiple dimensional set?
The question is a bit unclear in what you want to do. That being said, subsets seem one to do what you want, for instance:
set m /n1*n100/;
set n(m) /n1*n50/;
parameter test(m);
test(m)=0;
test(n)=1;
display test;
This is overly explicit, for instance, you do not need test(m)=0; as gams default value is 0.
So that you could use param(m)$test(m) = 3; to only set the values where test is positive.
Of course, it is much simpler to use param(n) = 3
Finally, strictly speaking, the instructions: sameas(set1,set2) or sameas(set1,"n101") do what you want.
Without a clearer question, it is hard to help beyond this point.

What is the best way to evaluate all occurrences of a field within a list in VB.NET?

I am new to VB.NET and I keep telling myself there must be a better way to do what I need to do several times a day which is look into a list and see if that one field is set to true anywhere in that list.
So far, I've been using the For Each statement:
For Each player In ListOfPlayers
If player.isActive Then
... do something ...
End If
Next
But I know some of the other languages can do something like:
if ListOfPlayers(*).isActive == true
which just seems more concise and to the point. Any suggestion?
As proposed by Bobby in the comments, use LINQ:
If ListOfPlayers.Any(Function (p) p.IsActive) Then …
This asks whether there’s any player (Any) for which IsActive is True.

naming a function that exhibits "set if not equal" behavior

This might be an odd question, but I'm looking for a word to use in a function name. I'm normally good at coming up with succinct, meaningful function names, but this one has me stumped so I thought I'd appeal for help.
The function will take some desired state as an argument and compare it to the current state. If no change is needed, the function will exit normally without doing anything. Otherwise, the function will take some action to achieve the desired state.
For example, if wanted to make sure the front door was closed, i might say:
my_house.<something>_front_door('closed')
What word or term should use in place of the something? I'd like it to be short, readable, and minimize the astonishment factor.
A couple clarifying points...
I would want someone calling the function to intuitively know they didn't need to wrap the function an 'if' that checks the current state. For example, this would be bad:
if my_house.front_door_is_open():
my_house.<something>_front_door('closed')
Also, they should know that the function won't throw an exception if the desired state matches the current state. So this should never happen:
try:
my_house.<something>_front_door('closed')
except DoorWasAlreadyClosedException:
pass
Here are some options I've considered:
my_house.set_front_door('closed')
my_house.setne_front_door('closed') # ne=not equal, from the setne x86 instruction
my_house.ensure_front_door('closed')
my_house.configure_front_door('closed')
my_house.update_front_door('closed')
my_house.make_front_door('closed')
my_house.remediate_front_door('closed')
And I'm open to other forms, but most I've thought of don't improve readability. Such as...
my_house.ensure_front_door_is('closed')
my_house.conditionally_update_front_door('closed')
my_house.change_front_door_if_needed('closed')
Thanks for any input!
I would use "ensure" as its succinct, descriptive and to the point:
EnsureCustomerExists(CustomerID)
EnsureDoorState(DoorStates.Closed)
EnsureUserInterface(GUIStates.Disabled)
Interesting question!
From the info that you have supplied, it seems to me that setstate (or simply set, if you are setting other things than states) would be fine, though ensure is good if you want to really emphasize the redundancy of an if.
To me it is however perfectly intuitive that setting a state does not throw an exception, or require an if. Think of setting the state of any other variable:
In C:
int i;
i = 5; // Would you expect this to throw an exception if i was already 5?
// Would you write
if (i != 5)
i = 5;
// ?
Also it only takes about one sentence to document this behaviour:
The function does nothing if the
current state equals the requested
state.
EDIT: Actually, thinking about it, if it is really important to you (for some reason) that the user is not confused about this, I would in fact pick ensure (or some other non-standard name). Why? Because as a user, a name like that would make me scratch my head a bit and look up the documentation ("This is more than just an ordinary set-function, apparently").
EDIT 2: Only you know how you design your programs, and which function name fits in best. From what you are saying, it seems like your setting functions sometimes throw exceptions, and you need to name a setting function that doesn't - e.g. set_missile_target. If that is the case, I think you should consider the set_if, set_when, set_cond or cond_set names. Which one would kind of depend on the rest of your code. I would also add that one line of documentation (or two, if you're generous), which clarifies the whole thing.
For example:
// Sets missile target if current target is not already the requested target,
// in which case it does nothing. No exceptions are thrown.
function cond_set_missile_target ()
or function cond_set_MissileTarget ()
or function condSet_MissileTarget ()
or function condSetMissileTarget ()
ensure is not so bad, but to me it implies only that there is additional logic required to set the state (e.g. multiple states tied together, or other complications). It helps to make the user avoid adding unnecessary ifs, but it does not help much with the exception issue. I would expect an ensure function to throw an exception sooner than a set function, since the ensure function clearly has more responsibilities for, well, ensuring that this setting operation is in fact done right.
I'd go for ensure for the function you describe. I'd also use camelCase, but I suppose you may be in a language that prefers underscores.
You could always document (shock!) your API so that others don't make the mistakes you describe.