HP Forums
Why "return 0;" - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Why "return 0;" (/thread-10102.html)



Why "return 0;" - compsystems - 02-05-2018 02:27 AM

Why the template of a new function in CAS mode, the declaration "RETURN 0" returns the number zero?

I think the logical thing is to return 1 (true or done), synonymous that the function reached the goal, while that 0 is synonymous with false.

PHP Code:
#cas
    
functionName():=
    
BEGIN
       
return 0;
    
END;
#end 



RE: Why "return 0;" - Paul Berger (Canada) - 02-05-2018 04:15 AM

The standard in the Unix world and in C is return 0 for success anything greater than 0 is a problem with the number returned indicating what went wrong.


RE: Why "return 0;" - compsystems - 02-05-2018 12:25 PM

Ok, but the programming language of the hp-prime is not a general purpose language, it is a mathematical language, 0 is synonymous, for example, that the equation has no solution, for this reason I recommend changing the template

Return Done

just like the command (:; )

makemat(1000,1000,0);: Returns Done

if it returned to zero, it would be confusing.

makemat(1000,1000,0);: => 0


RE: Why "return 0;" - Carlos295pz - 02-05-2018 02:32 PM

Le estas dando muchas vueltas, creo que el "return 0" es típico, solo representa un esquema común de retorno, no es necesariamente la más útil ni la más compleja, pero creo que la idea es que sea simple, ya que en la gran mayoría de los casos no se utiliza, es más un inicio para los principiantes.

Por otro lado la mayoría de valores por defecto de HP PPL también son 0, como cuando se crean posiciones fuera del rango de una lista y se rellena con ceros, funciones sin instrucciones, cuando no se define el valor de una variable y creo que algo más, puede que signifique falso en muchos casos, pero también recordar que es un real o entero.


RE: Why "return 0;" - compsystems - 02-05-2018 03:22 PM

The template of Xcas, I think it is more "didactic" and useful

[Image: xcas_function_template_image1.png]


RE: Why "return 0;" - toml_12953 - 02-05-2018 04:29 PM

(02-05-2018 12:25 PM)compsystems Wrote:  Ok, but the programming language of the hp-prime is not a general purpose language, it is a mathematical language,

HPPL is very much like C and is almost a proper subset of Pascal. Both of those are considered general-purpose programming languages.


RE: Why "return 0;" - Tim Wessman - 02-05-2018 05:01 PM

Does this example program matter? It could just be changed to RETURN a; and be equally valid.

I don't think changing this will benefit anyone particularly greatly.


RE: Why "return 0;" - DrD - 02-05-2018 05:18 PM

Even if the added cost of using template programming aids could be justified, for a limited memory device, how would that XCAS template resolve the "Why return 0?" (topic of this subject)?


RE: Why "return 0;" - TheKaneB - 02-05-2018 07:35 PM

It's just a blank template, there's no associated meaning to it.


RE: Why "return 0;" - StephenG1CMZ - 02-05-2018 10:29 PM

Put simply, when something works, it just works - you need one indication of success and whatever results you expect.
When something doesnt work, you need many different indications to show where the error is and what to do about it. A parameter error? A disk error? Memory full?

So, the single value for success is 0 and the many other values indicate errors...
It has been common practise since early DOS, if not sooner.


RE: Why "return 0;" - salvomic - 02-05-2018 10:43 PM

(02-05-2018 10:29 PM)StephenG1CMZ Wrote:  It has been common practise since early DOS, if not sooner.

Since Unix, also...
See, among other links, [https://shapeshed.com/unix-exit-codes/]
OK is a singular thing, KO are many things...

Salvo