Using apply ('remarray, list) inside a block forces evaluation
and allows programmed removal of assigned arrays
inside a block definition of a function.
I am having similar problems with declare and
remove inside a block definition of a function.
I want to maintain a list of declared scalars
in a package, maintaining a list scalarL, and I
want to simplify assignment of symbols to
scalars using a function mscalar([v]):
scalarL : []$
mscalar ([v]) :=
block ( [jj,_pp%],
for jj thru length (v) do (
_pp% : v[jj],
/* none of these three methods work: */
/* declare (_pp%,scalar), */
/* ev (declare (_pp%,scalar)), */
apply ( 'lambda([z], declare (z,scalar) ), [_pp%] ),
scalarL : cons (_pp%, scalarL) ),
display (scalarL) )$
unscalar ([v]) :=
block ([jj,_np%,_pp% ],
for jj thru length (v) do (
_pp% : v[jj],
if not lfreeof (scalarL, _pp%) then (
/* doesn't work */
remove (_pp%,scalar),
_np% : pos (scalarL,_pp%),
scalarL : remL1 (scalarL, _np% ) ) ),
display (scalarL) )$
-----------------------------------------------------
(%i68) load(dgexp);
(%o68) "c:/work3/dgexp.mac"
(%i69) scalarL;
(%o69) []
(%i70) mscalar (s1,s2,s3,s4)$
scalarL = [s4,s3,s2,s1]
(%i71) scalarp(s1);
(%o71) false
(%i72) declare([s1,s2,s3,s4],scalar);
(%o72) done
(%i73) scalarp(s1);
(%o73) true
(%i74) unscalar(s1);
scalarL = [s4,s3,s2]
(%o74) done
(%i75) scalarp(s1);
(%o75) true
------------------------------
So how can I get this to work?
Ted Woollett