Post Reply 
Type control
02-23-2015, 05:10 PM
Post: #11
RE: Type control
(02-23-2015 04:51 PM)salvomic Wrote:  
(02-22-2015 04:37 PM)Han Wrote:  In CAS, typing: a,b,c,d creates a list. That's just how the CAS environment parses a sequence of objects separated by a comma. So in a CAS program,

f(a,b,c,d)

can be considered as a function that takes 4 separate arguments named a,b,c, and d, or f can be considered as a function that takes a single argument: a list consisting of 4 items.

Han,
if I input [a,b], there is a way (in CAS) to tell the program that this input should be a matrix or vector and *not* a list? or other trick to do that?
In my program for Wronskian I would like threat only input like [x, x^2, ...] not also {...} or x,x^2,... if it's possible.

Thank you!

If you're trying to do some sort of dynamic input, then your function should be only defined as a function of a single variable (a list). For example:

Code:
#cas
myfunc(v):=
BEGIN
  local s;
  s:=SIZE(v);
  IF s>4 THEN RETURN("Too many arguments"); END;

  CASE
    IF s==1 THEN
      IF TYPE(v(1))<>4 THEN RETURN("First argument must be vector"); END;
      // and so on...
    END;

    IF s==2 THEN
      // etc.
    END;
  END;

END;

Note that in CAS, TYPE() and type() are two different functions. In non-CAS programs, there is only one "type" command -- the non-CAS one. In non-CAS programs, whether you use TYPE() or type(), either one will be interpreted as TYPE(). CASE vs case, RETURN() vs return, are among many differences you will have to learn.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Type control - salvomic - 02-22-2015, 03:42 PM
RE: Type control - Han - 02-22-2015, 04:37 PM
RE: Type control - salvomic - 02-22-2015, 04:46 PM
RE: Type control - Joe Horn - 02-22-2015, 08:47 PM
RE: Type control - salvomic - 02-22-2015, 08:52 PM
RE: Type control - Joe Horn - 02-23-2015, 04:17 AM
RE: Type control - salvomic - 02-23-2015, 08:31 AM
RE: Type control - toml_12953 - 02-23-2015, 04:52 PM
RE: Type control - salvomic - 02-23-2015, 05:01 PM
RE: Type control - Joe Horn - 02-23-2015, 11:40 PM
RE: Type control - salvomic - 02-23-2015, 04:51 PM
RE: Type control - Han - 02-23-2015 05:10 PM
RE: Type control - salvomic - 02-23-2015, 05:40 PM
RE: Type control - Han - 02-23-2015, 07:18 PM
RE: Type control - salvomic - 02-23-2015, 07:29 PM
RE: Type control - salvomic - 03-12-2015, 09:59 AM
RE: Type control - Han - 03-13-2015, 03:04 PM
RE: Type control - salvomic - 03-13-2015, 03:18 PM
RE: Type control - Han - 03-13-2015, 06:14 PM
RE: Type control - salvomic - 03-13-2015, 06:29 PM
RE: Type control - Han - 03-13-2015, 06:34 PM
RE: Type control - salvomic - 03-13-2015, 06:44 PM
RE: Type control - salvomic - 03-13-2015, 10:39 PM
RE: Type control - Han - 03-14-2015, 09:49 AM
RE: Type control - salvomic - 03-14-2015, 10:00 AM
RE: Type control - Angus - 02-24-2015, 06:28 AM
RE: Type control - salvomic - 02-24-2015, 06:34 AM
RE: Type control - Joe Horn - 02-25-2015, 05:52 AM



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