HP Forums
head-ache - 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: head-ache (/thread-8149.html)



head-ache - BruceH - 04-11-2017 10:08 PM

The 'head' and 'tail' commands don't seem to work consistently on strings in the Home and Cas environments.

[Image: y4mTut4IZcKcrUu9ga9VZHd88NAMzZfvipwYpZYK...pmode=none]


RE: head-ache - Joe Horn - 04-11-2017 11:07 PM

(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?)


RE: head-ache - toml_12953 - 04-12-2017 01:38 AM

(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


RE: head-ache - Carlos295pz - 04-12-2017 01:53 AM

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"


RE: head-ache - cyrille de brébisson - 04-12-2017 05:17 AM

Hello,

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

Cyrille


RE: head-ache - BruceH - 04-12-2017 09:44 AM

(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. :-)


RE: head-ache - JMB - 04-16-2017 08:14 PM

In Home, using CAS(cas_command) also works.

CAS(head("VERSION")) -> V
CAS(tail("VERSION")) -> ERSION