Post Reply 
Type control
02-23-2015, 07:18 PM (This post was last modified: 02-23-2015 07:21 PM by Han.)
Post: #13
RE: Type control
(02-23-2015 05:40 PM)salvomic Wrote:  1. in my specific program the list is type [x, x, x], so I cannot control for v(1), but I must control for the whole v, and it is seen always as list, so the control for <>4 doesn't match (in that program the list is always seen as type 6)...
2. how to avoid (if it's possible) to input nameprogram without () that in my case give a strange (flist)→LOCAL[[mat s j k d ... error?

1. My example was simply that -- an example. It was not a direct answer to your specific case. You would need to modify the example to make it fit your own needs. I don't understand your need to encase args inside [ and ]. The input args is already a CAS list.

Just try this:
Code:
#cas
myexample(args):=
  local s;
  s:=SIZE(args);
  IF s==0 THEN RETURN("No args given"); END;
  RETURN(args(s));
END;
#end

This will always return the last item in the argument list. The more general case (code below allows myprog(real, list) or myprog(real, list, list):

Code:
#cas
myprog(args):=
BEGIN
  local s:=SIZE(args);
  IF s==2 THEN
    IF TYPE(args(1)) OR TYPE(args(2))<>6 THEN
      RETURN("Usage: myprog(real, list)");
    ELSE
      // your code; use a RETURN()
    END;
  END;

  IF s==3 THEN
    IF TYPE(args(1)) OR TYPE(args(2))<>6 OR TYPE(args(3))<>6 THEN
      RETURN("Usage: myprog(real, list, list)");
    ELSE
      // your code; use a RETURN()
    END;
  END

  RETURN("Invalid input");

END;
#end

This doesn't work for non-CAS programs because the Home environment doesn't parse comma-separated entries the same way. The non-CAS programs must either be programmed to take an explicit list of inputs or you must use a CAS program. That is, HOMEPROG(list) where list is an actual list would work for non-CAS programs. However, a CAS program can simply use CASPROG(args).

2. A CAS program is essentially a function, much like f is a function when declared as f(x):=x^2. When you type f, you will see (x)->(x^2) as this is how the CAS represents functions. Thus, by simply typing the name of a function, you return its actual contents. There is no getting around this.

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: 1 Guest(s)