Post Reply 
50g System RPL list processing
10-28-2014, 02:12 PM
Post: #5
RE: 50g System RPL list processing
(06-21-2014 02:13 AM)ttw Wrote:  A list sum should return zero on an empty (or non-existent) list or the only element if a single element list (or a single variable is returned.)
I agree with your view. This is one of the improvements that were implemented in newRPL, and it makes things much more consistent. And it doesn't break compatibility, because if you have old code that checks for empty or single-element lists, it will work fine, but if you don't, you'll get the expected result.

(06-21-2014 02:13 AM)ttw Wrote:  Similarly for the produce (but here the product of an empty list is one rather than zero.)
This I don't agree. The summation of an empty list should still give an error, because you don't know that the empty list would contain reals. What if it was a list of strings? The sum of that empty list should return an empty string then (""), but how do you distinguish between an empty list of reals and an empty list of strings?


(06-21-2014 02:13 AM)ttw Wrote:  A scalar should promote up to a list. For that matter, operations on conformable lists-of-lists should work (->Q works but addition doesn't.)
I think scalars need to remain scalars. What I figured for newRPL was like this:
  • The four basic operations on lists are defined as element-by-element operations on lists that are of appropriate size. This includes the empty list ({ } { } * ==> { })
  • The basic operations between a list and a scalar apply the object to each element of the list ({ 1 2 3 } 1 + ==> { 2 3 4 }, and also the empty list { } 2 * ==> { })
Always remember that objects are not necessarily numbers, so { 1 X 3 } 1 + ==> { 2 'X+1' 4 }. If elements are lists, then this case automatically expands to an element-by-element, since { { 1 2 3 } } 1 + ==> { [[{1 2 3} 1 +]] } ==> { { 2 3 4 } }
(I'm using the [[ ]] to mark intermediate evaluation steps that you wouldn't normally see).
If you were to promote numbers to a list, then the operation of:
{ 1 X 3 } 1 +
{ [[1 {1} +]] [[X {1} +]] [[3 {1} +]] }
{ [[{1} {1} +]] [[{2} {1} +]] [[{X}??? {1} +]] }
{ { 2 } { 'X+1' } { 4 } }

I promoted the 1 to a list, then I ended up with a number plus a list, so I had to promote the number too, and when I found the X then what do we do? We don't know that X is a scalar or not, so do we promote it? In this case I did, but I'm not sure I should.
I think it's more natural to get { 2 'X+1' 4 } than { {2} {'X+1'} {4} }
It looks like adding a number to a list ended up transposing it (if you think of a list as a matrix).

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


Messages In This Thread
RE: 50g System RPL list processing - ttw - 06-21-2014, 02:13 AM
RE: 50g System RPL list processing - Claudio L. - 10-28-2014 02:12 PM
RE: 50g System RPL list processing - Han - 10-28-2014, 05:06 PM
RE: 50g System RPL list processing - Han - 10-31-2014, 02:15 PM
RE: 50g System RPL list processing - Han - 11-01-2014, 08:34 PM
RE: 50g System RPL list processing - Han - 11-02-2014, 01:04 AM
RE: 50g System RPL list processing - Han - 11-01-2014, 08:31 PM
RE: 50g System RPL list processing - Han - 11-02-2014, 06:26 PM



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