Post Reply 
head-ache
04-11-2017, 10:08 PM (This post was last modified: 04-18-2017 12:07 AM by BruceH.)
Post: #1
head-ache
The 'head' and 'tail' commands don't seem to work consistently on strings in the Home and Cas environments.

[Image: y4mTut4IZcKcrUu9ga9VZHd88NAMzZfvipwYpZYK...pmode=none]
Find all posts by this user
Quote this message in a reply
04-11-2017, 11:07 PM
Post: #2
RE: head-ache
(04-11-2017 10:08 PM)BruceH Wrote:  The 'head' and 'tail' commands don't seem to work consistently on strings in the Home and Cas environments.

[Image: hp_prime_headache.png?psid=1]

Workaround in Home view: use double parentheses.

head("test") --> test (unexpected)
head(("test")) --> "t" (as expected)

tail("test") --> [[]] (unexpected)
tail(("test")) --> "est" (as expected)

The reason that head("test") in Home view yields test instead of "t" is because head is a CAS command, and calling CAS commands from Home with string arguments extracts the contents from the string and passes THAT to CAS as the argument. Therefore head("test") in Home is identical to head(test) in CAS (notice the lack of quotes). Using double parentheses in Home forces the string itself to be passed to CAS as the argument.

Here's a fun example of the difference:
CAS: head("VERSION") --> "V" (as expected)
Home: head("VERSION") --> "H" (do you see why?)

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
04-12-2017, 01:38 AM
Post: #3
RE: head-ache
(04-11-2017 11:07 PM)Joe Horn Wrote:  
(04-11-2017 10:08 PM)BruceH Wrote:  The 'head' and 'tail' commands don't seem to work consistently on strings in the Home and Cas environments.

[Image: hp_prime_headache.png?psid=1]

Workaround in Home view: use double parentheses.

head("test") --> test (unexpected)
head(("test")) --> "t" (as expected)

tail("test") --> [[]] (unexpected)
tail(("test")) --> "est" (as expected)

The reason that head("test") in Home view yields test instead of "t" is because head is a CAS command, and calling CAS commands from Home with string arguments extracts the contents from the string and passes THAT to CAS as the argument. Therefore head("test") in Home is identical to head(test) in CAS (notice the lack of quotes). Using double parentheses in Home forces the string itself to be passed to CAS as the argument.

Here's a fun example of the difference:
CAS: head("VERSION") --> "V" (as expected)
Home: head("VERSION") --> "H" (do you see why?)

Because it's the first character in
"HP Prime Graphing CalculatorSoftware Version..." ?

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
04-12-2017, 01:53 AM
Post: #4
RE: head-ache
The CAS uses the strings to communicate with Home/HP PPL, if you want to send strings to CAS from Home or HP PPL, break the string interpretation with an operation:
head("VERSION"+"") --> "V"
head(("VERSION")) --> "V"

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
04-12-2017, 05:17 AM
Post: #5
RE: head-ache
Hello,

From memory, you can also quote the strings (as in the quote command).

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
04-12-2017, 09:44 AM
Post: #6
RE: head-ache
(04-11-2017 11:07 PM)Joe Horn Wrote:  The reason that head("test") in Home view yields test instead of "t" is because head is a CAS command, and calling CAS commands from Home with string arguments extracts the contents from the string and passes THAT to CAS as the argument.

Thanks Joe. I probably knew that at one time. :-)
Find all posts by this user
Quote this message in a reply
04-16-2017, 08:14 PM
Post: #7
RE: head-ache
In Home, using CAS(cas_command) also works.

CAS(head("VERSION")) -> V
CAS(tail("VERSION")) -> ERSION
Find all posts by this user
Quote this message in a reply
Post Reply 




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