I am new to both Julia and Visual Studio.
whenever I try to subtract two numbers
i.e. 3 - 5 I get 10
I am however able to add a negative number
3 + - 5 gives -2 as expected
The behavior also occurs with the .- and .+ operators. I thought there might be something wrong with my "-" character so I tried copying and pasting from the julia page on mathematical operators (https://docs.julialang.org/en/v1/manual/mathematical-operations/) to no avail.
I was unable to find any one else with the same problem. The problem appears to be limited to Visual studio as subtraction still works fine when I run Julia in terminal.
I am using Visual Studio Code 1.71.2 with the julialang 1.7.12 extension and Julia 1.8.1
EDIT-1:
If I copy and paste the code from Visual Studio Code into the julia terminal (not terminal in VSC) it works. However, if I run the code using julia the-script.jl in the terminal I still get 10 for any subtractions performed. I have also tested editing the script with nano and then running it and I am encountering the same problem.
EDIT3: As was pointed out by several responders the issue was not with VS code
Thank you for your help
Could someone explain where my code is breaking the function -?
I am unable to reliably break it so that I get 10 whenever I try and subtract, but I have been able to reproduce the error with the above script
# #make the neutral model that I have in R in julia and benchmark both models
# #imports
using Random
# #set the seed
Random.seed!(125)
#set the initial arguments
num_sp_local = 10::Int64;
init_sp_abundance = 100::Int64;
mig_prob = 0.01::Float64;
#meta community is uniform
num_sp-meta = 10; #ERROR IS HERE - function redefined to be 10
#the number of time steps to run the sim for
time_steps = 100000;
for i = 1:50
println(i - 35)
end
The error can be seen above num_sp-meta = 10; redefines the - function to be 10 irrespective of what is being subtracted.
This has nothing to do with VS Code, changing your editor/IDE is a pointless waste of time.
As #JoachimSauer suggested, someone (maybe you?) has re-defined the - function in your Julia instance.
Try fixing - by resetting it to Base.- like this: -(x::Int, y::Int) = Base.:-(x, y)
That might not work, depending on how the change was originally done.
Restart the REPL in VS Code. Perhaps the redefinition happened inside the script. Try to run 2 - 3, without running the-script first. This should work now.
This means that the change happened inside the-script.jl. Look for redefinitions of - inside that file.
If the above still doesn't work, the problem lies in some other library or script which is run. If so, try starting Julia like this:
julia --startup-file=no
and then run 2 - 3 or something like that.
I'm getting started with PyDev but am having trouble understanding its code validation.
For example, in a file containing just the code below, PyDev warns "Unused variable i" in the third line, but has no issue with j in the first line.
l1 = ['a' for j in range(10)]
def test():
l2 = ['a' for i in range(10)]
What is triggering PyDev's warning in this example?
(I know to avoid it by adding # #UnusedVariable)
The difference here is that in the first case you're creating global variables and in the second a local variable (global variables created are not reported because they may be used by another module).
You may add an underline (_) in front of the variable (i.e.: _i) to signal that you know it is not used and shouldn't be reported.
I want to to "t" (trace) and "dds #esp" X number of times.
.for (r $t0=0; #$t0<10; r $t0=#$t0+1){t;dds #esp;}
I tried the above and it doesn't work - it only does the "dds #esp" 10 times.
to try to narrow it down, I tried:
.for (r $t0=0; #$t0<10; r $t0=#$t0+1){t}
but get the followign error:
^ Debuggee already running error in 't'
Can someone assist me with this? Also are there any guides for learning these scripts from a rookie perspective?
Thanks.
I am trying out CoffeeScript in my Rails 3.1 app. However, I am not able
to figure out how to break long lines in CoffeeScript without getting the
above error
For example, how/where would you break the following line of code
alert x for x in [1,2,3,4,5] when x > 2
if you wanted something like
alert x for
x in [1,2,3,4,5]
when x > 2
In my vimrc, I have set
ts=2, sw=2 and I expand tabs.
And yet, I cannot get something as simple as the line above to work properly.
My Gemfile.lock shows coffee-script-2.2.0 with coffee-script-source 1.1.3
If you have a comprehension that is too long you can break it with \ as #brandizzi mentions, but I think you might have better luck just using comprehensions where they make sense and expanding to 'regular' code where they don't:
alert x for x in [1,2,3,4,5] when x > 2
...can be rewritten as...
for x in [1,2,3,4,5]
alert x if x > 2
...or even...
for x in [1,2,3,4,5]
if x > 2
alert x
In other words, comprehensions are syntactic sugar for short, concise snippets - you don't have to use them for everything.
You're trying to spread a comprehension out over multiple lines, which isn't allowed. It either needs to be on one line, or be a proper loop. Your one line version works as expected, so I'll show the loop version:
for x in [1..5] when x > 2
alert x
You may find it helpful to toss small things like this into the CoffeeScript compiler at http://jashkenas.github.com/coffee-script/ to see if they're compiling to what you'd expect.
I do not understand the inner details of CoffeeScript syntax, so I cannot say what is going wrong in detail. The error is a bit clear, however: you cannot put a newline between the for and its iterator variable. Also, you did not get this error yet, but you cannot put a newline between the iterated object and the when clause. However, if you really want to do it, it is easy: put backslashes at the end of the first and second lines.
console.log x for \
x in [1,2,3,4,5] \
when x > 2
I have created a custom toolchain and launch configuration to allow debugging on a remote target.
I've got the debugging working so that I can step through each statement. However, the stepping doesn't always match up with the position in the code editor.
For example, when debugging this code:
int x;
for(x = 0; x < 10; x++)
{
printf("%d\n", x);
}
The cursor will stay on the first line of the "for" statement rather than jumping onto the "printf" statement when stepping.
However, when I turn on "Instruction Stepping Mode" it does end up stepping onto the "printf" statement.
Any ideas would be very much appreciated. Please let me know if I can provide anymore details.
Best regards,
Alan
Just to draw a line under this one, it was due to me having compiler optimizations turned on... turn them off and it works fine.
Alan