How do I create a non-flattened list in Arden?

364 Views Asked by At

In Arden, when you add one list to another, both the lists are flattened.

For example:

MyList1 := "cat", "dog", "hamster";
DeepList := MyList1, ("hyena", "elephant", "puma");

Now, DeepList will not be a lists of lists as in:

("cat", "dog", "hamster"), ("hyena", "elephant", "puma") // 2 lists, 3 items each

But it will be flattened like so:

"cat", "dog", "hamster", "hyena", "elephant", "puma" // single list of 6 items

Is there a way to create a non-flattened list? It sometimes would be very useful to create such a list. I have searched the manuals and cannot find any way to do this. Searches online are fruitless--no one is putting up content about MLMs.

1

There are 1 best solutions below

0
On BEST ANSWER

In plain vanilla "Arden Syntax for Medical Logic Systems" there is no way to do this. However, in Sunrise Acute Care's implementation, there are two ways to get a multi-level, non-flattened list in Arden.

The first way is by accessing a property of a list of objects. This non-flattened nature is due to the object-handling extensions added by Sunrise to normal Arden. First, create a list of objects that have a property set to a list.

AnimalObj := OBJECT [AnimalList]; // create a single-property object type
Animal := NEW AnimalObj WITH ,("cat", "dog", "hamster"); // see notes below
Animals := , Animal;
Animal := NEW AnimalObj;
Animal.AnimalList := "hyena", "elephant", "puma"; // an alternate way
Animals := Animals, Animal;
MultilevelList := Animals.AnimalList; // this is the magic. No object any more!
ListCount := COUNT MultilevelList; // 2
Item1Count := COUNT MultilevelList[1]; // 3
Item2Count := COUNT MultiLevelList[2]; // 3

Notes about NEW AnimalObj WITH: The extra comma is required to indicate that this is not the normal syntax of mapping parameters, where "cat" is the first property, "dog" is the second, and so on. Instead, we have to add the comma to force it to be a list of lists, removing ambiguity about how to interpret the list, indicating that the entire first value in parentheses is to be assigned to the first property. This incidentally demonstrates that lists do live in Arden as non-flattened during parsing & handling, which if you think about it is actually a required feature, because when calling MLMs it is perfectly legal to pass a list to the first parameter and a different list to the second. Any time you are trying to pass a single list as a parameter (so that the parser cannot deduce you intend the entire list as just one parameter), you must pay very close attention so that it is not interpreted incorrectly by the parser as a simple list of parameters--even with the extra parentheses around the parameters.

Also note that in if you do a BREAK; and examine the value of the variable MultilevelList, it will show cat, dog, hamster, hyena, elephant, puma. This is highly misleading because it looks like a single list of 6 elements, but it is not, as we proved above with COUNT.

The second way to get a non-flattened list in the SCM variant of Arden Syntax is to cheat and use direct Lisp code. We take advantage of the fact that parameters passed to an MLM are non-flattened. Create an MLM--I'll call mine RETURN_ARGS, and put this code in the denoted slots:

data:
   CallerArguments := NULL;
   {(SETQ CallerArguments ARDEN_ARGUMENT)}; // direct Lisp code
logic:
   CONCLUDE True;
action:
   RETURN CallerArguments;

This can then be used very simply from another MLM:

MyList1 := "cat", "dog", "hamster";
RETURN_ARGS := MLM 'RETURN_ARGS';
DeepList := CALL RETURN_ARGS WITH MyList1, ("hyena", "elephant", "puma");

Close examination will prove that DeepList is exactly the same two-level list as produced with the object trick above.