Post Reply 
Why "return 0;"
02-05-2018, 02:27 AM (This post was last modified: 02-05-2018 02:34 AM by compsystems.)
Post: #1
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 
Find all posts by this user
Quote this message in a reply
02-05-2018, 04:15 AM (This post was last modified: 02-05-2018 04:16 AM by Paul Berger (Canada).)
Post: #2
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.
Find all posts by this user
Quote this message in a reply
02-05-2018, 12:25 PM (This post was last modified: 02-05-2018 12:26 PM by compsystems.)
Post: #3
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
Find all posts by this user
Quote this message in a reply
02-05-2018, 02:32 PM (This post was last modified: 02-05-2018 02:33 PM by Carlos295pz.)
Post: #4
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-05-2018, 03:22 PM
Post: #5
RE: Why "return 0;"
The template of Xcas, I think it is more "didactic" and useful

[Image: xcas_function_template_image1.png]
Find all posts by this user
Quote this message in a reply
02-05-2018, 04:29 PM
Post: #6
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?
Find all posts by this user
Quote this message in a reply
02-05-2018, 05:01 PM
Post: #7
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.
Find all posts by this user
Quote this message in a reply
02-05-2018, 05:18 PM
Post: #8
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)?
Find all posts by this user
Quote this message in a reply
02-05-2018, 07:35 PM
Post: #9
RE: Why "return 0;"
It's just a blank template, there's no associated meaning to it.

Software Failure: Guru Meditation

--
Antonio
IU2KIY
Find all posts by this user
Quote this message in a reply
02-05-2018, 10:29 PM
Post: #10
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
Visit this user's website Find all posts by this user
Quote this message in a reply
02-05-2018, 10:43 PM
Post: #11
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...
See, among other links, [https://shapeshed.com/unix-exit-codes/]
OK is a singular thing, KO are many things...

Salvo

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)