HP Forums
Function "contains" in HOME and CAS - 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: Function "contains" in HOME and CAS (/thread-9838.html)



Function "contains" in HOME and CAS - JMB - 01-02-2018 03:15 PM

I've found a different behavior of the function "contents" in HOME and CAS, in the following situation:

L1:={"A","B"}

In CAS
contains(L1,"A") -> 1
contains(L1,"B") -> 2

In HOME
contains(L1,"A") -> 0 !!!
contains(L1,"B") -> 0 !!!


RE: Function "contains" in HOME and CAS - salvomic - 01-02-2018 03:18 PM

its name is in lowercase, so I think it should be only a CAS command (not Home)...


RE: Function "contains" in HOME and CAS - JMB - 01-02-2018 03:27 PM

(01-02-2018 03:18 PM)salvomic Wrote:  its name is in lowercase, so I think it should be only a CAS command (not Home)...

Agreed, but when L1 is filled with numbers instead of strings, it works correctly both in CAS and HOME.


RE: Function "contains" in HOME and CAS - DrD - 01-02-2018 03:29 PM

The lower case [CAS] command can work the same way in [Home] if you provide a CAS wrapper:

[CAS]
contains(L1,"A"); ==> 1

[Home]
CAS(contains(L1,"A")); ==> 1


RE: Function "contains" in HOME and CAS - JMB - 01-02-2018 06:18 PM

Ok, I realize that the safe way to execute a CAS function in HOME is to use the structure CAS(CAS_function).

What still bothers me is that you can use the CAS function directly in HOME and, depending on the arguments, get correct or incorrect results. As I said before, when L1 contains numbers instead of strings "contains" works correctly both in HOME and CAS.


RE: Function "contains" in HOME and CAS - Voldemar - 01-02-2018 06:32 PM

(01-02-2018 03:29 PM)DrD Wrote:  The lower case [CAS] command can work the same way in [Home] if you provide a CAS wrapper:

[CAS]
contains(L1,"A"); ==> 1

[Home]
CAS(contains(L1,"A")); ==> 1
How does it work in RPN mode?


RE: Function "contains" in HOME and CAS - cyrille de brébisson - 01-08-2018 06:10 AM

Hello,

home contains(L1, "A") will cause A to be parsed as a CAS command line before the switch to CAS mode and the execution of contains. Assuming that the var A contains 0, what you execute is: contains(L1,0).
CAS(contains(L1,"A")) will not cause a parse of the string.

Subtelties of HOME/CAS interraction :-)

Cyrille


RE: Function "contains" in HOME and CAS - Didier Lachieze - 01-08-2018 07:00 AM

(01-02-2018 06:32 PM)Voldemar Wrote:  
(01-02-2018 03:29 PM)DrD Wrote:  [Home]
CAS(contains(L1,"A")); ==> 1
How does it work in RPN mode?

'contains(L1,"A")' Enter
CAS(1) Enter


RE: Function "contains" in HOME and CAS - Carlos295pz - 01-08-2018 07:56 AM

It is as indicated by Cyrille, it is due to the topic of Home/CAS interaction, since strings are interpreted by using CAS commands such as contains, head, solve, etc. (similar post http://www.hpmuseum.org/forum/thread-8149.html)

It can be said that all CAS functions (~ lowercase commands) will present this interpretation of a string data. This article Home/CAS-Spanish may be useful.

Correct use under this consideration:
CAS(contains(L1,"A"))
contains(L1,("A"))
contains(L1,'"A"')
contains(L1,"A"+"")
LOCAL Strg="A"
contains(L1,Strg)