new to sml and not sure how to div two number in function?
i want to run if statment, than div two numbers, than run if else statment.

fun hello() = 
        if(x = 1) then true

         //x = 10 div 5 

         if(x = 4) then true
         else false;

It's not quite clear to me, what you're trying to do here. If you want the division to only happen if x = 1 is false, it should be inside the else block of the first if. Also every if needs an else, so your first if causes a syntax error because it doesn't.

Also if x is supposed to be the result of the division, why do you already use it on line 2 when the division hasn't happened yet? Further to define a local variable, you'd use let, just writing x = value is not syntactically valid. If you want to change the value of an already existing int variable named x, you can't do that. Variables in SML are immutable. If you want to simulate mutable variables, you can use an int ref instead. But you probably shouldn't.

It also seems strange that your hello function does not take any arguments. Or that both operands to the division are constant (why not just write x = 2 then?).

Here's something that I think might be close to what you might want:

fun hello x =
    if x = 1 then true
    else
        let
            val y = 10 div x
        in
            if x = 4 then true
            else false
        end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.