With "cpymem" it is possible to copy contents from one variable to another. This is handy when you want the startingaddress of the variable be the same. E.g.:
newLISP v.8.7.0 on linux, execute 'newlisp -h' for more info.
> (set 'a (array 2))
(nil nil)
> (nth-set 1 a "Peter")
nil
> (println (a 1))
Peter
"Peter"
> (println (address (a 1)))
134817864
134817864
> (println (address (a 1)))
134817944
134817944
> (println (address (a 1)))
134817792
134817792
> (println (address (a 1)))
134817840
134817840
> (println (address (a 1)))
134818008
134818008
So every time when I print the address of an array member, the address changes....?!?!
Actually, I try to find a way to have multiple string variables (say about 100) whose starting address in memory remain the same. So for all kinds of reasons the starting address *must* remain the same; that is way I need the 'cpymem' also. And using a 100 individual variable names is very ugly.....
Is there a nice way to do this? Arrays don't work, unfortunately.
pjot wrote:
So every time when I print the address of an array member, the address changes....?!?!
Peter
The manual defines "address" to work only with "int", "double flost", and "string". There is some more documentation of memory management in the FAQ at:
Thanks for your suggestions! I actually did read that part in the manual about 'address', but the text is confusing. It informs us about ints, floats and strings, but it does not tell something about the 'type of variable', e.g. a plain symbol, list or array.
So I tried to use an array variable, assuming that an array of strings was kept in some sort of numbered C character pointer. I should have checked the newLisp source code myself first, though ;-)
I also thought to 'do something with sym', and I see your solution points in this direction. But you're using the 'cons' statement, which I never used myself before; I'll start studying it right now.
pjot wrote:
I also thought to 'do something with sym', and I see your solution points in this direction. But you're using the 'cons' statement, which I never used myself before;
Peter,
I think I might have left out a few functions in that last example. However here is some working code I wrote yesterday that shows how to construct a context name from an array of ints and an array of capital letters. It is instantiaing a context for a point in 3-dimensional space. But you could use some functions like it to create an association list of int-address lists too...
(don't use flat as that un-conses the pairs!)