MAKELIST with a condition? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: MAKELIST with a condition? (/thread-3122.html) MAKELIST with a condition? - DrD - 02-17-2015 04:16 PM Just as an example, suppose a list of the positive elements are desired from this composition: MAKELIST(X,X,-pi,pi,p1/6); Is there a syntax to embed something like "IF X > 0 THEN X" as a valid EXPRESSION within the MAKELIST structure? The intent is to include the conditional expression WITHIN the MAKELIST command, not pre or post processing. IF not, would this notion be worthy of future development for MAKELIST? -Dale- RE: MAKELIST with a condition? - Han - 02-17-2015 04:35 PM (02-17-2015 04:16 PM)DrD Wrote:  Just as an example, suppose a list of the positive elements are desired from this composition: MAKELIST(X,X,-pi,pi,p1/6); Is there a syntax to embed something like "IF X > 0 THEN X" as a valid EXPRESSION within the MAKELIST structure? The intent is to include the conditional expression WITHIN the MAKELIST command, not pre or post processing. IF not, would this notion be worthy of future development for MAKELIST? -Dale- I am sure you had something more complicated in mind. But in your specific example, would it not make more sense to restrict the range of from 0 to PI rather than from -PI to PI? MAKELIST(X,X,(-PI MOD (PI/6)),PI,PI/6); RE: MAKELIST with a condition? - DrD - 02-17-2015 04:55 PM That was just a too-simple-generic example. A conditional expression within the MAKELIST command could make the command far more robust and useful. I'm sure there are countless examples that would be more significant, and more pertinent for any specific objective. I was converting a number different loops today, with the goal of using MAKELIST to gain runtime advantage. I tried to simply include IF THEN END; (with variants), as the EXPRESSION, and all resulted in error. Which begged the question from me. In many cases, there are so many additional needs that a 'FOR LOOP' construct is really the only practical solution, but the MAKELIST command sits there ... just begging to be called in to play! RE: MAKELIST with a condition? - Gilles - 02-17-2015 06:25 PM (02-17-2015 04:16 PM)DrD Wrote:  Just as an example, suppose a list of the positive elements are desired from this composition: MAKELIST(X,X,-pi,pi,p1/6); Is there a syntax to embed something like "IF X > 0 THEN X" as a valid EXPRESSION within the MAKELIST structure? The intent is to include the conditional expression WITHIN the MAKELIST command, not pre or post processing. IF not, would this notion be worthy of future development for MAKELIST? -Dale- Not sure to understand your idea.What about : MAKELIST(IFTE(X<5,X,X²),X,1,10,1) RE: MAKELIST with a condition? - Han - 02-17-2015 06:30 PM I think he was looking for a way to create a dynamic list as opposed to a fixed-sized list. The IFTE would still return a value whereas he was hoping to not include any value at all if the test condition fails. RE: MAKELIST with a condition? - Gilles - 02-17-2015 06:34 PM (02-17-2015 06:30 PM)Han Wrote:  I think he was looking for a way to create a dynamic list as opposed to a fixed-sized list. The IFTE would still return a value whereas he was hoping to not include any value at all if the test condition fails. OK ! I understand....