Post Reply 
DIM in a program
04-02-2014, 09:24 AM (This post was last modified: 04-02-2014 09:25 AM by Angus.)
Post: #1
DIM in a program
imagine this piece of code:

Code:

EXPORT foo()
BEGIN
  LOCAL vec=[1,2,3,4,5];
  LOCAL dim1:=DIM(vec);
  dim1:=dim1(1);        //splitting in 2 steps is ok...
  LOCAL dim2:=DIM(vec)(1)   //while this is not
 
  (...)
END;

Is it really not possible to assign something like DIM(vector)(1) to a local in one step?

I tried in cas and that works. I switched home from rpn to textbook and found that calling DIM(vec)(1) is translated to DIM(vec)*(1) there which seems to be a side effect of automatic operator expansion. However in a program such behaviour is painful, you just would not expect your code to be modified by the system.
Find all posts by this user
Quote this message in a reply
04-02-2014, 09:47 AM
Post: #2
RE: DIM in a program
Why are you using the return of dim as a list? dim returns the length of the string

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2014, 10:03 AM (This post was last modified: 04-02-2014 10:05 AM by Angus.)
Post: #3
RE: DIM in a program
Maybe that is another capitalized non-capitalzed matter?

In fact I expected the length to be a number and not a list containing the length. I found that I got a list.... But I did use DIM in the program.
A few seconds ago I tried both dim() and DIM() in the cas.

vec:=[1,2,3,4,5];

invocing dim(vec) in the cas turns to DIM(vec) in the history und results in 5.
invocing DIM(vec) in the cas gives {5}.

That is strange

P.S. The original question on splitting up a command to part1*part2 remains, though. For a student learning to program that can really become a problem don't you think?
Find all posts by this user
Quote this message in a reply
04-02-2014, 10:09 AM
Post: #4
RE: DIM in a program
Strange, I get 1 with dim and lowercase dim gets uppercased.

Well, yeah I don't like a lot the * thing either, seems counter intuitive but there should be a reason because otherwise why the calculator ask "create ___ variable?" instead of just creating it, it might be related to something internal. I think the double quotes handling (try to use a string function in the cas and modify something later, without undo/redo is even more frustrating) in the cas is much more annoying than the * thing.

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2014, 10:46 AM (This post was last modified: 04-02-2014 11:32 AM by Angus.)
Post: #5
RE: DIM in a program
I forgot to mention that I used the simulator. There dim() is also converted to uppercase and the result is as expected. But using uppercase DIM() from the beginning gives you a list containing the result.

Have to validate that with the calculator later the day.

edit: I checked it in the calculator doing DIM(vec) in the cas causes an "Unmatch control word" error. So the beaviour is different than in my simulator.
But I still get a list from dim used in a program. Could someone please confirm that?
Find all posts by this user
Quote this message in a reply
04-02-2014, 11:48 AM
Post: #6
RE: DIM in a program
The lower/upper case explain at least the issue in the code, this works:
Code:
  LOCAL dim2:=EXPR("dim("+vec+")(1)");

The CAS/Program DIM just returns 1 number, not a list.

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
04-02-2014, 12:12 PM (This post was last modified: 04-02-2014 12:13 PM by Angus.)
Post: #7
RE: DIM in a program
That is astounding: I just keep getting a list or an Error (from inside a program in cas itself things are fine). Starts getting frustrating.

Thank you anyhow - maybe we get some more comments here and my fault is solved.
Find all posts by this user
Quote this message in a reply
Post Reply 




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