Why "return 0;"
02-05-2018, 02:27 AM (This post was last modified: 02-05-2018 02:34 AM by compsystems.)
Post: #1
 compsystems Senior Member Posts: 1,364 Joined: Dec 2013
Why "return 0;"
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
Post: #2
 Paul Berger (Canada) Senior Member Posts: 547 Joined: Dec 2013
RE: Why "return 0;"
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.
02-05-2018, 12:25 PM (This post was last modified: 02-05-2018 12:26 PM by compsystems.)
Post: #3
 compsystems Senior Member Posts: 1,364 Joined: Dec 2013
RE: Why "return 0;"
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
02-05-2018, 02:32 PM (This post was last modified: 02-05-2018 02:33 PM by Carlos295pz.)
Post: #4
 Carlos295pz Senior Member Posts: 365 Joined: Sep 2015
RE: Why "return 0;"
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.

Viga C | TD | FB
02-05-2018, 03:22 PM
Post: #5
 compsystems Senior Member Posts: 1,364 Joined: Dec 2013
RE: Why "return 0;"
The template of Xcas, I think it is more "didactic" and useful

02-05-2018, 04:29 PM
Post: #6
 toml_12953 Senior Member Posts: 2,097 Joined: Dec 2013
RE: Why "return 0;"
(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.

Tom L
Cui bono?
02-05-2018, 05:01 PM
Post: #7
 Tim Wessman Senior Member Posts: 2,293 Joined: Dec 2013
RE: Why "return 0;"
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.

TW

Although I work for HP, the views and opinions I post here are my own.
02-05-2018, 05:18 PM
Post: #8
 DrD Senior Member Posts: 1,133 Joined: Feb 2014
RE: Why "return 0;"
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)?
02-05-2018, 07:35 PM
Post: #9
 TheKaneB Member Posts: 175 Joined: Jul 2014
RE: Why "return 0;"
It's just a blank template, there's no associated meaning to it.

Software Failure: Guru Meditation

--
Antonio
IU2KIY
02-05-2018, 10:29 PM
Post: #10
 StephenG1CMZ Senior Member Posts: 1,032 Joined: May 2015
RE: Why "return 0;"
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
02-05-2018, 10:43 PM
Post: #11
 salvomic Senior Member Posts: 1,396 Joined: Jan 2015
RE: Why "return 0;"
(02-05-2018 10:29 PM)StephenG1CMZ Wrote:  It has been common practise since early DOS, if not sooner.

Since Unix, also...