You are here

Arrays and Prolog

I am working on a function which is supposed to receive a two dimensional array and return one dimensional array, using C++ language.
If you have some experience on working with similar functions please let me know how you solved this problem.
Here are some problems I have encountered while working on this function.
1. How can I create a Prolog form for a function which will receive two dimensional array?
2. In C++ you can not return an array, but I can receive a pointer and work on arrays directly, will this work?
3. How can I create a Prolog form for a function which will receive a pointer?
Any Ideas are welcome.

Forums: 

Hi John...

It is not possible to create a function in the target language that works directly on arrays. This is because a parameter that appears as an array when composing a Simile equation may not actually be an array internally -- it might instead be a collection of values from different data structures representing submodel instances.

However you can create macros to handle arrays. These are implemented simply by translating them into the corresponding full expression when building the model. You will find examples of macros that handle arrays and lists in the file Simile/Examples/List handling.pl

If you tell me specifically what you want to do with your arrays I'll have a go at putting a macro together to do it.

Cheers
--Jasper

Thank you, but I will try to find other solutions