Post Reply 
Function "contains" in HOME and CAS
01-02-2018, 03:15 PM
Post: #1
Function "contains" in HOME and CAS
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 !!!
Find all posts by this user
Quote this message in a reply
01-02-2018, 03:18 PM
Post: #2
RE: Function "contains" in HOME and CAS
its name is in lowercase, so I think it should be only a CAS command (not Home)...

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
01-02-2018, 03:27 PM
Post: #3
RE: Function "contains" in HOME and CAS
(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.
Find all posts by this user
Quote this message in a reply
01-02-2018, 03:29 PM
Post: #4
RE: Function "contains" in HOME and CAS
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
Find all posts by this user
Quote this message in a reply
01-02-2018, 06:18 PM (This post was last modified: 01-02-2018 06:22 PM by JMB.)
Post: #5
RE: Function "contains" in HOME and CAS
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.
Find all posts by this user
Quote this message in a reply
01-02-2018, 06:32 PM
Post: #6
RE: Function "contains" in HOME and CAS
(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?
Find all posts by this user
Quote this message in a reply
01-08-2018, 06:10 AM
Post: #7
RE: Function "contains" in HOME and CAS
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
01-08-2018, 07:00 AM
Post: #8
RE: Function "contains" in HOME and CAS
(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
Find all posts by this user
Quote this message in a reply
01-08-2018, 07:56 AM (This post was last modified: 01-08-2018 07:57 AM by Carlos295pz.)
Post: #9
RE: Function "contains" in HOME and CAS
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)

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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