Debug.EvaluateStatement Microsoft Visual Studio - visual-studio

I am using Intel Fortran along with Microsoft Visual Studio 2012. In debug mode with a breakpoint at line 21 for the following dummy program:
program hello
implicit none
integer, dimension(2,2) :: Array
type Test
integer :: a
integer :: b
integer :: c
end type Test
integer::i
type (Test) :: TestVariable
i=1
Array(1,1) = 22
Array(1,2) = 2
Array(2,1) = 22
Array(2,2) = 25
TestVariable%a = 1
TestVariable%b = 2
TestVariable%c = 3
print *, Array(1,1)
print *, Array(2,2)
print *, TestVariable%b
print *, ubound(Array)
end program Hello
At line 21 (my breakpoint) the variable i is defined and accessible from the Locals Window. It is also accessible from the command window using the following command:
Debug.Print i
Now what I am exploring is the Debug.EvaluateStatement functionality.
Debug.EvaluateStatement i returns 1, as it should.
Debug.EvaluateStatement i+i returns 2, as it should.
Debug.EvaluateStatement 1 returns 1, as it should.
Debug.EvaluateStatement 1+1 returns 2, as it should.
Debug.EvaluateStatement i+1 however, throws the following error:
Undefined address
Why does this error occur, and what can I do to prevent it and obtain the (what I think is correct) value of 2?

Related

Rcpp sample sugar function, how to use

I am trying to permute the order of elements in a CharacterVector. In R I would simply use:
sample(charvec)
I am trying the same thing in Rcpp using the sample sugar function, but it keeps throwing 'error: no matching function for call to 'sample(Rcpp::CharacterVector&)'. Other sugar functions I have tried, like intersect or sort_unique work fine with CharacterVector, but sample refuses to work. This is the minimal example I have been experimenting with:
cppFunction('CharacterVector samplefunc() {
CharacterVector v = {"Cat", "Dog", "Fox", "Fish", "Lion"} ;
CharacterVector v2 = sample(v) ;
return v2 ;
}')
What I am doing wrong when trying to use the sample sugar function?
You are just missing the size parameter, which is mandatory for Rcpp::sample:
set.seed(42)
Rcpp::cppFunction('CharacterVector samplefunc() {
CharacterVector v = {"Cat", "Dog", "Fox", "Fish", "Lion"} ;
CharacterVector v2 = sample(v, v.size()) ;
return v2 ;
}')
samplefunc()
#> [1] "Lion" "Fish" "Cat" "Dog" "Fox"
UPDATE (about debugging this kind of errors): Admittedly, the error you see when you do not provide the size argument is kind of obscure (at least with gcc), but you can see:
file1294a34f4734f.cpp: In function ‘Rcpp::CharacterVector samplefunc()’:
file1294a34f4734f.cpp:8:30: error: no matching function for call to ‘sample(Rcpp::CharacterVector&)’
8 | CharacterVector v2 = sample(v) ;
| ~~~~~~^~~
This is the error: no matching function. And then,
In file included from /***/Rcpp/include/Rcpp/sugar/functions/functions.h:89,
from /***/Rcpp/include/Rcpp/sugar/sugar.h:31,
from /***/Rcpp/include/Rcpp.h:78,
from file1294a34f4734f.cpp:1:
/***/Rcpp/include/Rcpp/sugar/functions/sample.h:437:1: note: candidate: ‘template<int RTYPE> Rcpp::Vector<RTYPE, Rcpp::PreserveStorage> Rcpp::sample(const Rcpp::Vector<RTYPE, Rcpp::PreserveStorage>&, int, bool, Rcpp::sugar::probs_t)’
437 | sample(const Vector<RTYPE>& x, int size, bool replace = false, sugar::probs_t probs = R_NilValue)
| ^~~~~~
where gcc is showing you a candidate, and you can see that this function accepts a constant Vector of any RTYPE (numeric, character...), and then it needs a size argument, because there is no default. The others (replace, probs) do have a default. R functions may have missing arguments, C++ functions cannot.

Visual studio 2017 problem with namespaces in F#

I wrote this in HelperFunctions.fs:
namespace Tutorial1.HelperFunctions
module Factorials =
let rec fact n =
match n with
| 0 -> 1
| 1 -> 1
| _ -> n * fact (n - 1)
And then this in Tutorial.fsx:
#load "HelperFunctions.fs"
open Tutorial1.HelperFunctions
module start =
let x = Factorials.fact 5
printfn "%d" x
Code compiles and returns 120 as expected BUT: VS throws FS0039 error: Factorials and Tutorial1 namespace, type or module not defined... Tried many other combinations of open, module etc but then codes does not even compile. What is the problem I am not seeing here?
Okay, apparently the order of files in the vstudio matters, even if you include the file with #load. I had to shift the files upwards and it worked

Syntax error when trying to create new empty list in Python

I'm embarking on my Project Euler adventure and the first line of my Python code is tripping me up. The error I get for the code below is:
Traceback (most recent call last):
File "python", line 3
3multlist = []
^
SyntaxError: invalid syntax
Which makes NO sense because I've verified up and down that the line in question does have proper syntax!
Code below:
3multlist = []
5multlist = []
3starter = 0
5starter = 0
While (3starter < 1000):
3starter = 3starter + 3
3multlist.append(3starter)
While (5starter < 1000):
5starter = 5starter + 3
5multlist.append(5starter)
b = sum(3multlist)
c = sum(5multlist)
d = b + c
print d
This is because variable name can not start with a numeral.Below are the variable naming convention rules
Variables names must start with a letter or an underscore, such as:
_
underscore
underscore_
The remainder of your variable name may consist of letters, numbers and underscores.
password1
n00b
un_der_scores
Names are case sensitive.
case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable
Correct version of your program would be
multlist = []
multlist = []
starter = 0
starter = 0
while (starter < 1000):
starter = starter + 3
multlist.append(starter)
while (starter < 1000):
starter = starter + 3
multlist.append(starter)
b = sum(multlist)
c = sum(multlist)
d = b + c
print(d)
If you are using python 3 you need to use brackets with print statement else you can drop them.
It looks like python does not like the number in front of the list declaration
try multlist3 rather than 3multlist

Term to packet erlang. Constructing a binary

I have the following code:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/integer-unit:8 >>.
However, when I run:
term_to_packet("Hello").
I get an error:
exception error: bad argument in function term_to_packet line 20
where line 20 corresponds to the last line of the term_to_packet function.
I'm not quite sure what's throwing this error.
B is a binary, but in the binary construction on the last line you specify that it is an integer. This seems to work:
term_to_packet(Term) ->
B = term_to_binary(Term),
A = byte_size(B),
<< 1:4/integer-unit:8, B:A/binary-unit:8 >>.

Cucumber and variables internal to methods called indirectly

Please note: I am new to TDD & cucumber, so the answer may be very easy.
I am creating a basic image editor for a test (the image is just a sequence of letters).
I have written a Cucumber story:
Scenario Outline: edit commands
Given I start the editor
And a 3 x 3 image is created
When I type the command <command>
Then the image should look like <image>
The step
Scenarios: colour single pixel
| command | image |
| L 1 2 C | OOOCOOOOO |
always fails, returning
expected: "OOOCOOOOO"
got: " OOOOOOOO" (using ==) (RSpec::Expectations::ExpectationNotMetError)
This is the step code:
When /^I type the command (.*)$/ do |command|
#editor.exec_cmd(command).should be
end
The function exec_cmd in the program recognizes the command and launches the appropriate action. In this case it will launch the following
def colorize_pixel(x, y, color)
if !#image.nil?
x = x.to_i
y = y.to_i
pos = (y - 1) * #image[:columns] + x
#image[:content].insert(pos, color).slice!(pos - 1)
else
#messenger.puts "There's no image. Create one first!"
end
end
However, this always fails unless I hardcode the values of the two local variables (pos and color) in the function in the program itself.
Why? It doesn's seem I'm doing anything wrong in the program itself: the function does what it's supposed to do and those two variables are only useful locally. So I'd think this is a problem with my use of cucumber. How do I properly test this?
---edit---
def exec_cmd(cmd = nil)
if !cmd.nil?
case cmd.split.first
when "I" then create_image(cmd[1], cmd[2])
when "S" then show_image
when "C" then clear_table
when "L" then colorize_pixel(cmd[1], cmd[2], cmd[3])
else
#messenger.puts "Incorrect command. " + "Commands available: I C L V H F S X."
end
else
#messenger.puts "Please enter a command."
end
end
When /^I type the command (.*)$/ do |command|
#output = #editor.exec_cmd(command)
end
Then /^the image should look like (.)*$/ do |expected_image|
#output.should == expected_image
end
Hope this may help you.
It's not a cucumber issue.
The problem was that, in exec_cmd, split was called only in the "case" clause, not in the "when"s. This meant that, since the command's format was "a 1 2 b", cmd[1] in the "when" would call the second character of the string, a space, not the second value of the array, and the other functions would convert that to_i, returning 0.
I changed exec_cmd like this:
def exec_cmd(cmd = nil)
if !cmd.nil?
cmd = cmd.split
case cmd.first
when "I" then create_image(cmd[1], cmd[2])
[...]
end
which fixed the issue.

Resources