HP Forums
to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] (/thread-10315.html)



to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - John P - 03-12-2018 07:47 PM

Hello,
Does somebody know how to change list to a set. I am trying to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4], but the program when it comes to EXPR("%{1,2,3,3,4%}") gives me "Error: Syntax Error". When I do not use EXPR I get "%{1,2,3,3,4%}" and outside the prgm. when I use EXPR("%{1,2,3,3,4%}") I get the set [1,2,3,4]. The problem is; how to get the program to return the set [1,2,3,4] instead giving me "Error: Syntax Error" when using EXPR.

Thank you,
John P


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Carlos295pz - 03-12-2018 09:44 PM

EXPR is a Home command
To interpret CAS functions use CAS (...)

CAS("%{1,2,3,3,4%}") → [1,2,3,4]


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - compsystems - 03-12-2018 10:01 PM

expr (lowercase) is a CAS command for CAS environment #cas ... #end

expr("%{1,2,3,3,4%}") returns
[1,2,3,4] (History) =(.
returns set[1,2,3,4] =) (entryline or textbook flag: off)

expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}") returns
[a,b,c,d,ee,f] (History) =(
returns
set[a,b,c,d,ee,f] =) (entryline or textbook flag: off)

For [hp-prime team]
I think that the history should be conversed the prefix SET[], to differentiate it from arrays, lists, vectors , tables, etc

expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}") → set[a,b,c,d,ee,f]


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - John P - 03-12-2018 10:20 PM

(03-12-2018 09:44 PM)Carlos295pz Wrote:  EXPR is a Home command
To interpret CAS functions use CAS (...)

CAS("%{1,2,3,3,4%}") → [1,2,3,4]


Thanks Carlos295pz.
It works now but I had to use, in the prgm. body, CAS(CAS(l(1))) where l(1)="%{1,2,3,3,4%}". Why CAS inside the CAS?

Cheers,


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - John P - 03-12-2018 10:26 PM

(03-12-2018 10:01 PM)compsystems Wrote:  expr is a CAS command =)

expr("%{1,2,3,3,4%}") returns
[1,2,3,4] (History) =(.
returns set[1,2,3,4] =) (entryline or textbook flag: off)

expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}") returns
[a,b,c,d,ee,f] (History) =(
returns
set[a,b,c,d,ee,f] =) (entryline or textbook flag: off)

For [hp-prime team]
I think that the history should be conversed the prefix SET[], to differentiate it from arrays, lists, vectors , tables, etc

expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}") → set[a,b,c,d,ee,f]

Thanks compsystems,
If I understand your post correctly you did the EXPR i the history of CAS. I need it to work inside the body of a program. It works for now, see the response to Carlos295pz above.

Cheers


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - compsystems - 03-12-2018 10:41 PM

PHP Code:
EXPORT exprprg1()
BEGIN
return expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}");
END

exprprg1() returns "Error: Syntax Error" =(

another solution is to work on the CAS environment, you avoid being added CAS( )

PHP Code:
#cas
exprprg2():=
BEGIN
  
return expr("%{ a, a, b, c, c, d, ee, ee, ee,f %}");
END;
#end 

exprprg2() returns set[a,b,c,d,ee,f]


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Carlos295pz - 03-12-2018 10:45 PM

(03-12-2018 10:20 PM)John P Wrote:  Thanks Carlos295pz.
It works now but I had to use, in the prgm. body, CAS(CAS(l(1))) where l(1)="%{1,2,3,3,4%}". Why CAS inside the CAS?

Cheers,

There is a topic of Home/CAS interaction.

Only with data

CAS("%{1,2,3,3,4%}") → [1,2,3,4] //OK
CAS("%{1,2,3,"+"3,4%}") → "%{1,2,3,3,4%}" //You need to send the pure chain, not an operation that loses the first evaluation to the chain

CAS(EVAL("%{1,2,3,"+"3,4%}")) → [1,2,3,4] //OK, string was created before being sent as a parameter


With variables

LOCAL lr="%{1,2,3,3,4%}",ls={"%{1,2,3,3,4%}"};
CAS(lr) → "%{1,2,3,3,4%}"
CAS(ls(1)) → "%{1,2,3,3,4%}"
CAS(EVAL(lr)) → [1,2,3,4] //OK, string extracted from lr before the parameter pass
CAS(EVAL(ls(1))) → [1,2,3,4] //OK, string extracted from ls(1) before the parameter pass

I have written about Home/CAS Interaction, but I can only create it in Spanish.


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Carlos295pz - 03-12-2018 10:49 PM

CAS(CAS(...)) may look like CAS(EVAL(...)), but I think I have seen some differences that could be considered as unexpected behaviors, so I advise using CAS(EVAL()), since the implementation was designed so that EVAL controls the passage of parameters to CAS, or that is what I understand.


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - ggauny@live.fr - 03-15-2018 12:37 PM

Buenos dias Carlos,

No hablo español, pero con google traduzco tus textos.
Su trabajo es importante para todos nosotros, ya que HP no lo ha estado haciendo desde 2013.
Tengo 83 años, pero el cerebro todavía está allí (¡no de salud, qué mal!).
Gracias amigo. (un ejemplo de lo que hago).


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Carlos295pz - 03-15-2018 01:11 PM

Si google no existiera tampoco estaría aquí xD, es un gusto saber que incluso los que no hablan mi idioma puedan aprovechar lo que publico, sinceramente son pocos los que lo leen pero veo que esos pocos son personas realmente interesadas y esa es mi principal meta.


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - Han - 03-15-2018 09:40 PM

The CAS() command is intended to provide users with access to the CAS environment as well as the CAS commands. It is, however, a "Home" command which means the "Home" environment rules are applied. Generally speaking, this means that all referenced variables were passed as resolved values. For example, if x:=2 and we subsequently called a routine using: MYPROG(x), then 2 is passed in place of x. This method, however, caused problems for symbolic computations in which it is sometimes necessary to pass arguments unevaluated.

In much older firmwares, the CAS() command would always resolve all variables first before passing control over to the CAS environment. In the newer firmwares, all variables passed to CAS() are left as-is (to be resolved from the CAS environment). In order to pass resolved values, we use EVAL().


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - ggauny@live.fr - 03-16-2018 08:30 PM

Hola Carlos !

A tranlate I try to do, surely not very good but it is good for me enough.
It take me about 3 hours with google.

Be sure your work is in my french friends to study.

Thanks.


RE: to get a program to return EXPR("%{1,2,3,3,4%}") as the set [1,2,3,4] - webmasterpdx - 03-18-2018 11:29 AM

There is a CAS document here that is very good. It's not completely up to date, but has most of it described.
https://www-fourier.ujf-grenoble.fr/~parisse/hp-prime_cas.pdf

There are also some references to CAS vs HOME here in the main PRIME page, under Programming...
http://wiki4hp.com/doku.php?id=prime:start