HP Forums
makes me crazy - 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: makes me crazy (/thread-4839.html)

makes me crazy - ji3m - 09-30-2015 08:39 PM

In the cas window, if i type

expr ("'rasp'") it returns: rasp //whether or not rasp is defined

That is i get the identifier back.

BUT If i define:

EXPORT tok (s)
RETURN expr (s);

and then enter

tok ("'rasp'") it returns: syntax error //??????

UNLESS a is defined as a cas var in which case it returns the identifier as above.


This makes me crazy.

RE: makes me crazy - cyrille de brébisson - 10-01-2015 05:50 AM


In the CAS world, it is OK to use undefined variables names. That is after all what the cas is and does.

In the Numerical world, it is not. Everything has to be declared (like in C) and have a value.

In order to make use of both system as easy as possible, the 2 systems are made to look as similar as possible, with functions bearing the same name doing (to the extent that it make sense) the same things.

expr ("'rasp'") in cas will parse the quote(rasp) which will non evaluate the rask identifier/varaible name.

expr ("'rasp'") in NUMERICAL (Non Cas programs are Numerical) will attempt to parse rasp, find it non declared and result in an error.

Both system are VERY powerful in their own domains, created to allow a VERY easy transition from one to the other. Are able to use/communicate/interact, BUT they have some fundamental differences, which are not always evident at first sight and which can be surprising/frustrating for someone transitioning from beginner to advanced user (It is even sometimes surprising for advanced users!).

Prime would be simpler if only one of the 2 modes existed, BUT it would not be Prime, a very versatile system able to takle most use cases.

I hope that this helps and that you can complete whatever you were trying to achieve.


RE: makes me crazy - Gerald H - 10-01-2015 07:37 AM

Perhaps, ji3m, those responsible could consult this document:


RE: makes me crazy - ji3m - 10-01-2015 12:24 PM

First, I could care less about the home mode.

My real problem is that the above program when executed in the cas window
fails in the same manner.

This means I cant write programs that deal with unbound algabraic or cas variables.

I even tried the #cas .... #end way. The same thing happens.

Im not trying to move between the two worlds.
I prefer to use cas mode only but need to write programs that
are consistant within that mode.
That is a command in a program needs to do exactly the same thing that direct entry does.

RE: makes me crazy - Han - 10-01-2015 01:00 PM

For CAS programs, one can make use of variables by simply using them, without having to "create" them.

return 2*x+y;

If x and y do not exist as variables, then the result is simply 2*x+y. In general, one does not have to "create" a variable in order to use it. The CAS simply treats any and all names as identifiers if they are not referenced much like in the HP48 series.

Here are some notes I put together on CAS programming.


Only technique 3 would be relevant in your case since you are only concerned about the CAS view.

RE: makes me crazy - ji3m - 10-01-2015 02:11 PM

Thank you so very much.
str2sym (S):=
expr (S);

Does exactly what I need!

str2sym ("aa+bb") returns 44+bb

since aa is defined but bb is not.

str2sym (" 'aa+bb' ") returns aa+bb

without evaluation.

This is perfect!

What exactly is #cas? A pragma or what?
Is there any other documentaion or articles about
cas style programs?

RE: makes me crazy - Han - 10-01-2015 02:16 PM

The #cas #end is like a pragma and simply tells the compiler that everything in between should be interpreted as if it were entered from the CAS view. This prevents things like parsing errors where a variable is used but has not been declared (an problem if found in a "Home" program but not an issue if implemented in a "CAS" program).

When creating a new program (on the calculator) there is an option to select whether or not the program is a CAS program. If so, the editor will provide a generic skeleton of one.

RE: makes me crazy - ji3m - 10-01-2015 02:26 PM

Days of anguish have now vanished.

I reread your article and now realize I didnt need
to create str2sym.

CAS(".....") does what I want with no fuss.


RE: makes me crazy - Thomas_Sch - 10-01-2015 03:05 PM

(10-01-2015 02:11 PM)ji3m Wrote:  What exactly is #cas? A pragma or what?
Is there any other documentaion or articles about
cas style programs?

Please have a longer look at the linked article Han mentioned,
Han wrote: Here are some notes I put together on CAS programming.
-> http://www.hpmuseum.org/forum/thread-3590.html
and to XCAS: http://www.hpmuseum.org/forum/thread-818.html,
-> "13) CAS (XCAS) Advanced Reference Programming"

RE: makes me crazy - cyrille de brébisson - 10-02-2015 05:35 AM



Is like a pragma, you are correct.
In essence, it allows to tell the compiler: From there on, switch language from PPL to cas.

HOWEVER! there are some limits, #cas #end MUST be at 'top level' in your program. By this I mean that you can NOT switch language in the middle of a function.
This allows you to have functions in PPL and functions in CAS programs, but not a function that does 1/2 the work in one language and 1/2 the work in the other.