2024-07-09 20:54:54 I've got a really basic design style question: if I've got a word that has a result that's a data structure (i.e. bigger than a cell), what's the usual way of dealing with this? 2024-07-09 20:55:12 Do I put the address of where the result should go onto the stack as a parameter? 2024-07-09 20:55:33 Or do I leave the components of the result on the stack where I can use another word to store them? 2024-07-09 20:57:41 Or something else, that I haven't thought of yet? 2024-07-09 20:58:49 would also be interested to hear the responses, but i think the unsatisfying answer is probably going to be "it depends" 2024-07-09 21:03:29 In my case specifically, I'm doing vector maths, so the structures I'm thinking of right now are generally three or four floats (or 9-16 floats for matrices). 2024-07-09 21:08:27 because the three fields are pretty tightly coupled, i think i would be inclined to just pass a memory address around. but i'm by no means the leading authority on forth style, or even a very good forth programmer, so like i said: also interested to hear others' opinions 2024-07-09 22:20:51 Yes, I would return a pointer to it. 2024-07-09 22:21:06 The same for when you've "giving" such a structure to a word. 2024-07-09 22:23:05 So would I have : v+ ( v1addr v2addr resultaddr -- )... or : v+ (v1addr v2addr -- resultaddr )... 2024-07-09 22:23:23 and if the latter, how (and where) does the space for the resultaddr get allocated? 2024-07-09 22:27:21 Well, that depends on your memory management. If you are handling memory management manually, then I think it would be the first - that is, ( v1 v2 vresult -- ) 2024-07-09 22:27:47 If your system can dynamically allocate RAM as needed, then you might go with the latter and let the word get the ram for its result. 2024-07-09 22:27:58 The first way is probably higher performance and less "mixing of functionality." 2024-07-09 22:30:55 OK. At the moment, I'm going with the former, because I have limited understanding and I've learned all my forth so far from reading a 40-year-old copy of Moore's "Starting Forth" 2024-07-09 22:33:29 Aha, I find the memory-allocation word set. Probably still go with the former approach, because I can then allocate memory either with create & allot or with allocate, and it'll still work. 2024-07-09 22:34:03 Yes, I think you'll be happier telling it where to put the result. 2024-07-09 22:35:08 Say you were adding vectors of 3D points. You'd want each 3D component of that sum vector to go in the right slot of, well, a new vector. So in that case you'd want to tell it the right s pot in the output vector to put each result. 2024-07-09 22:36:06 I guess it's the difference between C: "void add(v3 *p1, v3* p2, v3* res)" and "v3* add(v3 *p1, v3 *p2)", where the latter calls malloc for its return value. 2024-07-09 23:02:07 Thanks for the help. :)