Post Reply 
DOSUBS with binary operations
05-15-2022, 11:56 AM
Post: #1
DOSUBS with binary operations
In an older thread I stumbled upon the following program:
Code:
\<<
  DUP HEAD +
  :: CROSS DOSUBS
  \GSLIST ABS 2 /
\>>

Compared to my original program I noticed that \<< CROSS \>> can be replaced by :: CROSS:
Code:
\<<
  DUP HEAD +
  2 \<< CROSS \>> DOSUBS
  \GSLIST ABS 2 /
\>>

But then I noticed that also 2 was missing.
This surprised me since I wasn't aware that the frame index could be omitted.
It turns out that this doesn't work for :: DROP but only with operations that operate on two objects like :: + or :: ^.
Furthermore, it also works when these operations are wrapped within a code object like \<< CROSS \>>.

However, the following doesn't work:
Code:
{ 0 1 4 9 16 25 }
\<< SWAP - \>>
DOSUBS

We get:

DOSUBS Error:
Invalid User Function


But we can use:
Code:
{ 0 1 4 9 16 25 }
\<< \-> u v \<< v u - \>> \>>
DOSUBS

Or then of course:
Code:
{ 0 1 4 9 16 25 }
2
\<< SWAP - \>>
DOSUBS

Which returns the expected result:
Code:
{ 1 3 5 7 9 }

Please excuse my ignorance but is this behaviour described in the manuals?
At least in the HP 48G Series User's Guide I couldn't find anything.
Or is it just folklore like the null-tag trick?



Addendum:

It also works for more than two arguments as long as they are declared:
Code:
{ 1 2 3 4 5 }
\<< \-> u v w \<< u v + w * \>> \>>
DOSUBS

The result is:
Code:
{ 9 20 35 }

It appears to work with DOLIST as well, which is nice.
However, while it works with \<< * \>> it doesn't work with :: *.

We get:

DOLIST Error:
Bad Argument Type

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


Messages In This Thread
DOSUBS with binary operations - Thomas Klemm - 05-15-2022 11:56 AM



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