mighty ugly evalstring

F

fogh

Guest
Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the "evalstring"
below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result "ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi * xval(i("/V69/PLUS" ?result
"ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 
On Thu, 10 Feb 2005 10:19:16 +0100, fogh
<cad_support@skipthisandunderscores.catena.nl> wrote:

Hi Andrew,
indeed, this is sloppy code. It was written interactively. Is there a
documented procedural way to access ADE ( for instance in that famous and
mysterious oasis documentation for integrators) ?
Apart from what is in the ADE SKILL manual, the rest is in the OASIS
documentation, which is only provided to those integrating a simulator. Even
then, it covers just what is needed to add a simulator (I think - I've not
seen it).

Andrew.
 
I forgot to post the "gsub" function with that. Here it is ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
alias gsub CmStrSubstitute
procedure( CmStrSubstitute(old new argstring @key (magic t) )
let( ( (prevmagic rexMagic() ) )
rexMagic(magic)
rexCompile(old)
unless(stringp(argstring) argstring=sprintf(nil "%L" argstring))
when( rexExecute(argstring)
argstring=rexReplace(argstring new -1 )
)
rexMagic(prevmagic)
argstring
));let&proc

let(
()
substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result "ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi * xval(i("/V69/PLUS" ?result
"ac-ac"))))
)
);templates

index=1
outindex=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=outindex
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
outindex++
Outputs=cons(o Outputs)
);foreach
index++
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
);let
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


fogh wrote:
Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the
"evalstring" below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result
"ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi * xval(i("/V69/PLUS"
?result "ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 
I'm not sure i got it, but what about enclosing
gsub( substitutionkey sprintf(nil "%L" index) nth(1 tpl) )
in quote() instead of building the string and evaluating ?

fogh wrote:
Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the
"evalstring" below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result
"ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi * xval(i("/V69/PLUS"
?result "ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 
Stef,
It does not give me the right type:
stringp(evalstring(strcat("'" "foo(bar)")))
=> nil
stringp(quote("foo(bar)"))
=>t

do you have another idea ?

S. Badel wrote:
I'm not sure i got it, but what about enclosing
gsub( substitutionkey sprintf(nil "%L" index) nth(1 tpl) )
in quote() instead of building the string and evaluating ?

fogh wrote:

Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the
"evalstring" below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result
"ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi *
xval(i("/V69/PLUS" ?result "ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 
Frederic,

Unfortunately your code is so difficult to read that I couldn't entirely
figure out what you're trying to do (although I can hazard a guess).
You're also using private functions...

Anyway, I suspect you're trying to take an expression that's in a string, and
return it as a list equivalent? In which case, that would be:

car(linereadstring("foo(bar)"))

Avoids all that messing around with quotes.

Andrew.

On Sun, 06 Feb 2005 05:46:24 -0500, fogh <adff@xs4all.nl> wrote:

Stef,
It does not give me the right type:
stringp(evalstring(strcat("'" "foo(bar)")))
=> nil
stringp(quote("foo(bar)"))
=>t

do you have another idea ?

S. Badel wrote:
I'm not sure i got it, but what about enclosing
gsub( substitutionkey sprintf(nil "%L" index) nth(1 tpl) )
in quote() instead of building the string and evaluating ?

fogh wrote:

Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the
"evalstring" below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result
"ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi *
xval(i("/V69/PLUS" ?result "ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 
Hi Andrew,
indeed, this is sloppy code. It was written interactively. Is there a
documented procedural way to access ADE ( for instance in that famous and
mysterious oasis documentation for integrators) ?

Your proposition of car(linereadstring(...)) does what I need and is more robust.


Andrew Beckett wrote:
Frederic,

Unfortunately your code is so difficult to read that I couldn't entirely
figure out what you're trying to do (although I can hazard a guess).
You're also using private functions...

Anyway, I suspect you're trying to take an expression that's in a string, and
return it as a list equivalent? In which case, that would be:

car(linereadstring("foo(bar)"))

Avoids all that messing around with quotes.

Andrew.

On Sun, 06 Feb 2005 05:46:24 -0500, fogh <adff@xs4all.nl> wrote:


Stef,
It does not give me the right type:
stringp(evalstring(strcat("'" "foo(bar)")))
=> nil
stringp(quote("foo(bar)"))
=>t

do you have another idea ?

S. Badel wrote:

I'm not sure i got it, but what about enclosing
gsub( substitutionkey sprintf(nil "%L" index) nth(1 tpl) )
in quote() instead of building the string and evaluating ?

fogh wrote:


Hi CCC,

Again I wrote something ugly. Can anyone help me get rid of the
"evalstring" below and replace it with stg decent ?


substitutionkey="69"
templates='(
(
Q69
(imag(i("/V69/PLUS" ?result "ac-ac")) /real(i("/V69/PLUS" ?result
"ac-ac")) )
)
(
C69
(-imag(i("/V69/PLUS" ?result "ac-ac")) /(twoPi *
xval(i("/V69/PLUS" ?result "ac-ac"))))
)
);templates

index=1
Outputs=nil
while(index < 20
foreach( tpl templates
o=make_sevOutputStruct()
o->index=index
o->march=o->save=o->selectionDetail=o->type=o->signal=nil
o->plot=t
o->name=gsub(substitutionkey
sprintf(nil "%L" index)
nth(0 tpl) )
o->expression=evalstring(strcat("'"
gsub(
substitutionkey
sprintf(nil "%L" index)
nth(1 tpl) ) ))
);foreach
index++
Outputs=cons(o Outputs)
);while index
Outputs=reverse(Outputs)

session=asiGetCurrentSession()
sevsession=session->data->sevSession
session->data->outputList=sevsession->outputs=Outputs
sevUpdateOutListBox(sevsession)
 

Welcome to EDABoard.com

Sponsor

Back
Top