HP Forums

Full Version: head-ache
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The 'head' and 'tail' commands don't seem to work consistently on strings in the Home and Cas environments.

[Image: y4mTut4IZcKcrUu9ga9VZHd88NAMzZfvipwYpZYK...pmode=none]
(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?)
(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
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"
Hello,

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

Cyrille
(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. :-)
In Home, using CAS(cas_command) also works.

CAS(head("VERSION")) -> V
CAS(tail("VERSION")) -> ERSION
Reference URL's