Standard/unanimous variable for yes/no - variables

I'm trying to write code more clearly and follow protocol or precedence with variable names. My question is if there is a decided upon variable name for a yes/no question.
For example in c++ it would look something like:
cout << "Yes or no";
cin >> YesOrNoVariable;

Related

How to print a specific integer value in a Bottle in YARP?

I'm trying to print a specific integer value of a Bottle by using cout (the Bottle contains only integer values), but it seems that this is a wrong way to do it. The command I used in a for loop is (the b Bottle is defined outside the loop):
std::cout << b.get(i) << std::endl;
The corresponding error is:
I'd like to see an example regarding the reading of a Bottle value.
You would have to get at the underlying type of the Value, if you know that it is indeed an int32_t (in other words b.get(i).isInt32() is true) then
std::cout << b.get(i).asInt32() << std::endl;
For the purposes of writing, without having to check the underlying type, you might also consider simply stringifying the Value
std::cout << b.get(i).toString() << std::endl;

Replace with a different segment

I have a code which is having around 6000 lines in C++.
As a part of code refactoring, I'm required to modify all the output lines in this code.
Eg:
Currently, existing lines look like this -
cout<<"The string value is - " << sStringVal;
My modification is to add the class name in each cout statement, like -
cout<<"CFlowController: The string value is - "<< sStringVal;
There are around 3900 output lines which require this change. Can
anyone suggest a script or how to do this apart from the manual
replacement?

type of literal words

I was reading Bindology and tried this:
>> type? first ['x]
== lit-word!
>> type? 'x
== word!
I expected type? 'x to return lit-word! too. Appreciate any insights.
A LIT-WORD! if seen in a "live" context by the evaluator resolves to the word itself. It can be used to suppress evaluation simply with a single token when you want to pass a WORD! value to a function. (Of course, in your own dialects when you are playing the role of "evaluator", it's a Tinker-Toy and you can make it mean whatever you want.)
Had you wanted to get an actual LIT-WORD! you would have to somehow suppress the evaluator from turning it into a WORD!. You noticed that can be achieved by picking it out of an unevaluated block, such as with first ['x]. But the more "correct" way is to use quote 'x:
>> type? quote 'x
== lit-word!
Beware an odd bug known as "lit-word decay":
>> x-lit: quote 'x
>> type? x-lit
== word!
That has been corrected in Red and is pending correction in Rebol. Until then you have to use a GET-WORD! to extract a lit-word value from the variable holding it:
>> x-lit: quote 'x
>> type? :x-lit
== lit-word!
(You may have already encountered this practice as the way of fetching the value of a word vs. "running" it through the evaluator...as when you want to deal with a function's value vs. invoking it. It should not be necessary on values holding lit-word!. Accident of history, it would seem.)

How to print multiple outputs in Smalltalk

|X Y A B C D|
Y:= 7.
X:= 6.
(X = Y)
ifTrue: [X := 0]
ifFalse:[X := 1].
B:=2.
C:=5.
D:=1.
A:= (B squared)*(C-D).
"print both A and X to screen here"
Simple enough little smalltalk example. I'm just curious how I can get this to print X and A as outputs? is there any way to do it w/o having to perform a 'print it' on the top 6 lines and a seperate 'print it' on the bottom 5 lines? if it could print out on just a 'do it' or a single 'print it' please let me know!
You should define what is "printing" and what is X and A.
If "printing" is a result of the "print it" action, then you are talking in general about returning X and A, as "print it" prints the return result of the selected code. This way you have to think about an object which will represent X and A. For this object you can define a printString method or printOn: and get the result printed. Or you can cheat a bit and return a point by doing X#A.
If you are talking about actually printing the thing somewhere then you have to tell more about where do you want to do it. You can print it in Transcript or similar, but there you have to explicitly send a message to the Transcript with what you want to be printed.
Now if you want to use this for "debugging/testing" reasons, it can be easier to go with "inspect it". In your code you can send inspect messages to the objects that you want to look at, and during the execution inspectors will open showing this objects.
Also I encourage you to follow conventions and make your variable names start with lowercase letter.
Smalltalk has no equivalent of print() or println() or the like, since most Smalltalk environments live in a window environment. There are ways to write output to stdout or std error, but this is very dialect specific.
One of the places that somehow replaces stdout in most dialects is a place/stream/window called Transcript, in most dialects this is the window that launches first when your start the IDE.
To write something there you simple do:
Transcript show: 'A=', A asString, ' ; X=', X asString.
(please note that in Smalltalk, Strings and Collections are concatenated with a comma)
You can also write a newLine by sending the message cr to the Transcript like so:
Transcript cr.
Does this answer your question?
A hint for further learning/investigation: Transcript is just a Variable that holds a Stream object. show: is a message that writes some String onto that Stream. asString is a method that returns a String representation of an object.

How to emit a blank line using yaml-cpp

Using yaml-cpp, version 0.2.5 ...
I would like to emit a blank line between entries in a list (for readability purposes).
Is this possible?
I have tried experimentation with the Verbatim, and Null manipulators, but have not had success.
As of revision 420, this is possible:
YAML::Emitter emitter;
emitter << YAML::BeginSeq;
emitter << "a" << YAML::Newline << "b" << "c";
emitter << YAML::EndSeq;
produces
---
- a
- b
- c
I decided to go with YAML::Newline instead of YAML::Newline(n) since I found
I usually just wanted a single newline.
I kept accidentally typing YAML::Newline, which implicitly cast the function to a bool (specifically, true), so I figured other people would probably make the same mistake.
If you just want to patch your copy (and not sync with the trunk), use revisions 418-420. (Note: it's slightly trickier than the patch in the link you posted, since you have to be careful about a newline after an implicit key. See the comment on the (now closed) Issue 77 for more details.)