Re: [eclipse-clp-users] structures - how would you implement associations between different 'types' of structures.

From: Joachim Schimpf <joachim.schimpf_at_...44...>
Date: Wed, 25 Feb 2009 12:58:17 +1100
Samuel Bayliss wrote:
> Dear All.
> Newbie question.
> I'm a bit bewildered as to style when building some data structures in 
> my first eclipse program...
> I have a list of 'command' structures defined with the
>             :- export struct(
>                     command(type,time,bank)
>                 ).
> Early in the program, the type and bank variables for structures 
> contained in my command list are grounded and no backtracking occurs 
> over these. The time variable remains unbound (this is a scheduling 
> program).
> Some of the command variables in my program have additional information 
> attached to them - i.e. read commands are commands, but have associated 
> information (which row and column to start reading from and how long a 
> burst to read for), activate and precharge commands have row 
> information, but no burst length information. 
> Essentially these command variables have types, I'm trying to associate 
> extra information with each variable according to it's type. It's akin a 
> problem I'd solve with inheritance in an object oriented imperative 
> language. I'm guessing this is a pretty common pattern people face.
> How do people go about implementing this kind of pattern in 
> Prolog/Eclipse - I suspect that the inherited structures syntax in 
> eclipse nearly does what I want, but will create a lot of unbound 
> variables I don't care about and the attributed variable implementation 
> sounds similarish, but seems overkill.
> Thanks in advance.
> Sam

I would use your 'type' field to not only hold the name of the command type,
but hold a structure that contains all the type-specific information
(the type would then be implicit in the functor of this sub-structure).

So, you'd use your command-declaration from above, and declare e.g.

:- export

and then use it like

..., Command1 = command{type:read{row:3,col:7}, time:T1}, ...
..., Command2 = command{type:activate{row:1}, time:T2}, ...

But alternatively, you could turn things inside-out, and have the
specific type-structures contain the generic command-struct, so

:- export

That would allow you to maintain the illusion of flatness:

..., Command1 = read{row:3, col:7, time:T1}, ...
..., Command2 = activate{row:1, time:T2}, ...

which is simply a shorthand for

..., Command1 = read{row:3, col:7, cmd:command{time:T1}}, ...
..., Command2 = activate{row:1, cmd:command{time:T2}}, ...

-- Joachim
Received on Wed Feb 25 2009 - 04:58:25 CET

This archive was generated by hypermail 2.3.0 : Sat Aug 24 2019 - 09:15:00 CEST