Re: help?

new topic     » goto parent     » topic index » view thread      » older message » newer message
kobi said...

I can't see what's wrong in this little piece of code:

include std/math.e 
 
function minmax(atom min, atom max, atom val) 
    atom temp = max ({min, val}) 
    atom res = min({max, temp}) 
    return res 
end function 
 
? minmax(7.2,99,6) 

Although your original problem has been resolved, you might like to consider a more straight forward version ...

function minmax(atom pMin, atom pMax, atom pVal)  
    if pVal > pMax then 
        return pMax 
    end if 
 
    if pVal < pMin then 
        return pMin 
    end if 
 
    return pVal 
end function  
  
for i = 5 to 120 by 20 do 
	? {i, minmax(7.2,99,i) } 
end for 

Also note that I've used my personal naming convention, that helps avoid name clashes.

  • Parameters are prefixed with 'p'
  • Variables local to a routine are prefixed with 'l'
  • Variables local to a module (file) are prefixed with 'm'
  • Variables that are exposed to other files are prefixed with 'g'
  • Constants local to a file are prefixed with 'k'
  • Constants that are exposed to other files are (usually) in all uppercase.
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu