hey guys I'm trying to compile this function called 2v2 that multiplies any number times 2. I'm doing it using Atom with ionide but when i run it using the f# interactive, it gives me this error saying that it doesn't see the rest of the function. Any suggestions?
let times 2v2 n =
let p = 2 in
n*2;;
times 2v2 10;;
let times 2v2 n =;;
let times 2v2 n =;;
----------^^^
/stdin(4,11): error FS1156: This is not a valid numeric literal. Sample formats include 4, 0x4, 0b0100, 4L, 4UL, 4u, 4s, 4us, 4y, 4uy, 4.0, 4.0f, 4I.
If I understand your question correctly, you want to have a function called times 2v2 that multiplies its parameter with 2. Since the name of your function contains a space, you have to enclose it with double backticks. For example:
let ``times 2v2`` n = 2 * n
And also use these when calling the function:
``times 2v2`` 10
Without double backticks, identifiers must not begin with numbers or contain spaces. Otherwise, the compiler would have a hard time figuring out whether it's dealing with one or multiple identifiers.
A minimalist way to make the question's code valid would be to remove the space between times and 2v2. The variable p would serve no purpose though.
Related
I am running a model which is written in Fortan (an executable), in some runs it started to deliver constant errors and apparently incoherent results, however when I closely checked the results file (a text with n columns of data) and I realized that when the concentration of certain mineral is very very low, lets say 2.9984199E-306, the code omits the 'E' and the number presented is 2.9984199-306 which of course causes problems. Since I have no access to the source code of the executable file, is there a way to avoid this problem in Windows? I have seen that in other computers these numbers are directly replaced by zero, however I was not able to find the specific configuration to achieve it.
You will need access to code to change the output formatting or you will need to post-process your output. You are seeing standard conforming Fortran behavior. Consider the simple program
program foo
implicit none
real(8) x
integer i
x = 1
do i = 1, 10
x = x / 5.4321e11
write(*,'(ES15.7)') x
end do
end program foo
It's output is
1.8409086E-12
3.3889446E-24
6.2387373E-36
1.1484945E-47
2.1142735E-59
3.8921843E-71
7.1651557E-83
1.3190397E-94
2.4282316-106
4.4701525-118
See Fortran 2018 Standard, 13.7.2.3.3 E and D editing, in particular, Table 13.1.
I have this script on 2 npcs but both choose the same random number (7) how do I make the Npcs choose their own number? I did try with self.math.random and it gave an error
so what would the solution be? will I have to create different variables for each npc related to the random function?
function Behavior:Awake()
math.randomseed (os.time())
self.destino = math.random( 1, 7 )
In the engine I work with it says to put self. for independence...
The fact that you call math.randomseed inside a function suggests to me that you're calling it every time you want a random number. The purpose of math.randomseed is to initialize the RNG, which means you're initializing the RNG multiple times, hence the repetition. Usually, you need to call math.randomseed exactly once in the entire program.
it says to put self. for independence...
That's not a great explanation of how self works. self is a function parameter that gets automatically declared when you declare a function with colon notation.
I develop mathematical model using gurobi solver, in python.
I get the following error while running:
SyntaxError: Generator expression must be parenthesized if not sole argument
My constraint is:
My code is:
for s in S:
m.addConstr(sum(x[s,s0,c,i] for s0 in S0 for c in C for i in D,s!=p) == 1,'C_3')
First of all, everything comes whenever you add that comma: ,s!=p.
I just emulated your code with a model I'm working on, and I obviously got the same error. Look around (e.g. if else in a list comprehension), and you will see that the only mistake you had was that the iterator within the generator wasn't well specified. That means, you had to use an if clause in order to achieve what you wanted:
for s in S:
m.addConstr(
quicksum(x[s,s0,c,i] for s0 in S0 for c in C for i in D if s!=p) == 1,
'C_3_'+str(s) )
By the way, as included in the code, you should use quicksum instead of sum. Furthermore, I would suggest to try changing the order of the iterators; in other words, it's not the same for a computer to enumerate a list of 5 elements 1000 times than to enumerate 5 times a list of 1000 elements, and this is something quite important in Python timing.
As a side note, I got into this question while looking for this:
TypeError: unsupported operand type(s) for +: 'generator' and 'generator'
I've been tinkering with the F# Interactive.
I keep getting weird results, but here's one I can't explain:
The following code returns 66, which is the value I expect.
> let f x = 2*x*x-5*x+3;;
> f 7;;
The following code throws a syntax error:
> let f x = 2*x*x - 5*x +3;;
stdin(33,21): error FS0003: This value is not a function and cannot be applied
As you can see, the only difference is that there are some spaces between the symbols in the second example.
Why does the first code example work while the second one results in a syntax error?
The problem here is the use of +3. When dealing with a +/- prefix on a number expression white space is significant
x+3: x plus 3
x +3: syntax error: x followed by the positive value 3
I've run into this several times myself (most often with -). It's a bit frustrating at first but eventually you learn to spot it.
It's not a feature without meaning though. It's necessary to allow application of negative values to functions
myFunc x -3: call function myFunc with parameters x and -3
The error message says that you are trying to call a function x with the argument +3 ( unary + on 3) and since x is not a function, hence the This value is not a function and cannot be applied
this is my first post here. I started using Ruby just 2 days ago and think it is an amazing language, however I have been getting stuck. My problem is I am wanting to calculate the event horizon of a black hole given an input defined in the code as "m" This will then be put into a calculation and the size then printed out to the screen. I did need it to be in binary and thats where I am having the issue.
Here is my code so far.
#Event Horizon Calculation Program
G = 6.67*10**-11
m = 20
C = 200000
R = G*m/(C**2)
puts "Here is the result in Binary."
R.to_i(2)
puts R
Now I do realise that the number are not accurate, that dosen't matter at the moment. I just need the function to work.
Thankyou,
Ross.
Your post is not even in a format of asking a question, but guessing from what you wrote, it seems that you are asking how to change your code so that it accepts an input to m and outputs the result. My answer is based on this assumption.
In order to take an input, use the 'gets' method. So, you may want to replace your 'm = 20' line with:
m = gets.to_f
'gets' accepts an input as a string, so you need to convert it to a numeric. to_f changes a string into a float. You can use to_i instead if you want an integer.
You have a line 'R.to_i(2)', and it seems like you want to output this, but you have two problems here. First of all, whatever that creates, it is only creating something in that position, and does not change the value of R, so, in effect, it actually does nothing. Second, ruby can accept numerals in source code written in different bases such decimal, binary, hex, etc., but it only has one internal representation, and you cannot output a numeral in binary. For your purpose, you need to convert it to a string that corresponds to a binary expression. For that, use the 'to_s' method. In fact, the 'to_i' method does not take an argument. Delete your line 'R.to_i(s)', and replace the line 'puts R' with:
puts R.to_s(2)