Post Reply 
[SOLVED] DSRN (dog slow roman numerals)
06-15-2014, 11:49 AM
Post: #32
RE: DSRN (dog slow roman numerals)
(06-15-2014 04:30 AM)Thomas Klemm Wrote:  Look at it as: \<< + \>> STREAM
What happens when you execute + with only one number on the stack?
Error: Too Few Arguments

The real question to ask is "Why should I look at it that way?"
I look at it from its meaning and what a user/developer might use it for. It tripped David, and forced him to adapt his code to the limitations of the function. That shouldn't happen with a good API unless there's a good reason for it. Back in the day of userRPL, there probably was a good reason, as they needed to implement it in the simplest/fastest way, but in 2014 I can't find any good reason.

(06-15-2014 04:30 AM)Thomas Klemm Wrote:  Or then the sum of an empty list is 0 as in Lisp.
And the product of an empty list is 1.
Code:
 > (+ 3 4)
=> 7
 > (+ 3)
=> 3
 > (+)
=> 0
 > (* 3 4)
=> 12
 > (* 3)
=> 3
 > (*)
=> 1

Yes, I thought about that too, and I'm still open to change it, but then I thought that the elements of the list may not be numbers, but for example strings.
The sum of a list of strings is a string, so the empty list should give an empty string, not a number. Same thing for a list of vectors: shouldn't it be a zero vector?
In the end I thought that it was more appropriate to say that the sum of an empty list is undefined because we don't know the object type of the answer, so an error is appropriate after all.
On the other hand, if you have one element, the result is that element and it's a clear and fully defined answer.
For the product is the same: should I return the number one? or an identity matrix?

Claudio
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: DSRN (dog slow roman numerals) - HP67 - 06-11-2014, 07:06 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 11:44 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 04:49 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-15-2014, 12:02 PM
RE: DSRN (dog slow roman numerals) - HP67 - 06-16-2014, 06:09 AM
RE: DSRN (dog slow roman numerals) - HP67 - 06-12-2014, 05:46 PM
RE: DSRN (dog slow roman numerals) - Claudio L. - 06-15-2014 11:49 AM



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