Function "contains" in HOME and CAS
01-02-2018, 03:15 PM
Post: #1
 JMB Member Posts: 89 Joined: Jan 2016
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 !!!
01-02-2018, 03:18 PM
Post: #2
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
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
01-02-2018, 03:27 PM
Post: #3
 JMB Member Posts: 89 Joined: Jan 2016
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.
01-02-2018, 03:29 PM
Post: #4
 DrD Senior Member Posts: 1,028 Joined: Feb 2014
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
01-02-2018, 06:18 PM (This post was last modified: 01-02-2018 06:22 PM by JMB.)
Post: #5
 JMB Member Posts: 89 Joined: Jan 2016
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.
01-02-2018, 06:32 PM
Post: #6
 Voldemar Member Posts: 192 Joined: Mar 2014
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?
01-08-2018, 06:10 AM
Post: #7
 cyrille de brébisson Senior Member Posts: 795 Joined: Dec 2013
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.
01-08-2018, 07:00 AM
Post: #8
 Didier Lachieze Senior Member Posts: 1,066 Joined: Dec 2013
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
01-08-2018, 07:56 AM (This post was last modified: 01-08-2018 07:57 AM by Carlos295pz.)
Post: #9
 Carlos295pz Member Posts: 264 Joined: Sep 2015
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
 « Next Oldest | Next Newest »

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