HP Forums

Full Version: makes me crazy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
BEGIN
RETURN expr (s);
END;

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.
Hello,

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.

Cyrille
Perhaps, ji3m, those responsible could consult this document:

http://c2.com/cgi/wiki?PythonPhilosophy
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.
For CAS programs, one can make use of variables by simply using them, without having to "create" them.

#cas
test():=
BEGIN
return 2*x+y;
END;
#end

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.

http://www.hpmuseum.org/forum/thread-3590.html

Only technique 3 would be relevant in your case since you are only concerned about the CAS view.
Thank you so very much.
#cas
str2sym (S):=
BEGIN
expr (S);
END;
end;

Does exactly what I need!

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

since aa is defined but bb is not.

Yet
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?
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.
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.

hmm.
(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"
Hello,

#cas
#end

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.

Cyrille
Reference URL's