Post Reply 
makes me crazy
09-30-2015, 08:39 PM (This post was last modified: 09-30-2015 10:06 PM by ji3m.)
Post: #1
makes me crazy
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-01-2015, 05:50 AM
Post: #2
RE: 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

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
10-01-2015, 07:37 AM
Post: #3
RE: makes me crazy
Perhaps, ji3m, those responsible could consult this document:

http://c2.com/cgi/wiki?PythonPhilosophy
Find all posts by this user
Quote this message in a reply
10-01-2015, 12:24 PM
Post: #4
RE: makes me crazy
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-01-2015, 01:00 PM (This post was last modified: 10-01-2015 01:51 PM by Han.)
Post: #5
RE: makes me crazy
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
10-01-2015, 02:11 PM (This post was last modified: 10-01-2015 02:19 PM by ji3m.)
Post: #6
RE: makes me crazy
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?

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-01-2015, 02:16 PM
Post: #7
RE: makes me crazy
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
10-01-2015, 02:26 PM
Post: #8
RE: makes me crazy
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.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-01-2015, 03:05 PM
Post: #9
RE: makes me crazy
(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"
Find all posts by this user
Quote this message in a reply
10-02-2015, 05:35 AM
Post: #10
RE: makes me crazy
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

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
Post Reply 




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