how to define a layer between data and functions

B

bpatton

I "think" I have a need to have a layer of something between my data
and the actual calls.

Here's what I percieve as my layers.

1. data. This is from an excel spread sheet representing design rules
for a process. Happens to be for Semi-Conductor Integrated circuit.
2. The functions that know how to deal with the keywords represented in
the data. Such as space, width and area for 3 of the very simple
rules.

In a past life I used CLIPS, an AI tool. In it there existed rules and
facts. An engine matched facts with rules and fired the rules. The
order of firing was random.

This is what I have
data is the facts
subroutines are the rules.

At the very worst and probably the most difficult to maintain would be
the if-then-else structure hundreds, maybe thousands of line long.

I need this to be almost like an event driven GUI, but where the data
drive the program, not where the program looks at the data and drives.
(SOS)

I believe if there were some method to have an engine that would match
data up with functions without to having to manually type all those
if-then-else this would allow me to easily expand the amount of
keywords.

I'm not even sure if I'm asking the right questions.
What i am sure about it this.
if-then-else would not be easily expandable. a maintence nightmare.
I need perl for transportability
 
B

Ben Morrow

Quoth (e-mail address removed):
I believe if there were some method to have an engine that would match
data up with functions without to having to manually type all those
if-then-else this would allow me to easily expand the amount of
keywords.

I don't think I entirely understand what you're asking, but one way of
doing something like this is having a hash of anon subs. That way you
have a main loop that goes through the data, looking each one up in the
hash and executing the given code.

Ben
 
B

bpatton

This has possibilites.
a hash of anonymous subroutines.

Let me give you a sample of some of the data as it would be in my hash
of data
{ 'Rule Code' => '1A' ,
'Description' => 'some bs',
'layer 1' => 'NWELL',
'relation 1' => 'space' ,
'layer 2 => '',
'drawing size' => '240'
'layer 3' => '',
'relation 2' => '',
'layer 4' => ''
'low range' => '',
'high range' => ''
}

As you can see the evaluations can get quite complex. Expically since
any one of the layers may be a psuedo layer, formed from teh boolean
function between several layers.

What I don't want to do is to have to
if ($h->{relation 1} eq 'space' and $h->{layer 2} eq '' then
the possible permutations would be endless. Since there are currently
just over 2400 of the hashes above, plus the subroutines to build the
psuedo layers, ths nuber of if-then-else would make it next to
impossible to do in my lifetime and completely un maintainable.
Probably get used one time the forgotten because of complexity.

Please tell me more about the use of a hash of anon subroutines.
My concept of teh hash would be
{
'space' => sub { my ($layer1,$layer2,$size) = @_;
create_data();
return 1;
},
'width'=> sub { my ($layer1,$size) = @_;
...
return 1;
}
}

Ok I can visualize how to create the hash of subroutines that
represents how to act upon my keywords.
But how to loop through my data hash and call the correct routines.
Can I make calls to determine what the prototyes of the anon are?
maybe match the prototypes with the data.
I remember reading something about getting the prototypes fro a
subroutine

return unless this exists and that
exists
 
B

Ben Morrow

[please don't top-post. have you read the Posting Guidelines?]

Quoth (e-mail address removed):
This has possibilites.
a hash of anonymous subroutines.

Let me give you a sample of some of the data as it would be in my hash
of data
{ 'Rule Code' => '1A' ,
'Description' => 'some bs',
'layer 1' => 'NWELL',
'relation 1' => 'space' ,
'layer 2 => '',
'drawing size' => '240'
'layer 3' => '',
'relation 2' => '',
'layer 4' => ''
'low range' => '',
'high range' => ''
}

As you can see the evaluations can get quite complex. Expically since
any one of the layers may be a psuedo layer, formed from teh boolean
function between several layers.

Err... no, I can't see anything from that. I have no idea what any of
the above represent or how they are related.
Please tell me more about the use of a hash of anon subroutines.
My concept of teh hash would be
{
'space' => sub { my ($layer1,$layer2,$size) = @_;
create_data();
return 1;
},
'width'=> sub { my ($layer1,$size) = @_;
...
return 1;
}
}

Yes, that's the basic idea.
Ok I can visualize how to create the hash of subroutines that
represents how to act upon my keywords.
But how to loop through my data hash and call the correct routines.

Assuming the above is assigned to $dispatch, you can call a sub with
e.g.

$dispatch->{space}->('NWELL', '', 240);

See perlref.
Can I make calls to determine what the prototyes of the anon are?

Err... yes, you can get the prototype of a sub with the prototype()
builtin function. Note that none of your subs above have prototypes... I
suspect you're on a wrong track here. You may need to store some
metadata about each sub alongside it, something like

my $dispatch = {
space => {
ARGS => 3,
SUB => sub {
my ($layer1, $layer2, $size) = @_;
...
},
},
...
};

Ben
 
D

Dr.Ruud

(e-mail address removed) schreef:
data is the facts
subroutines are the rules.

At the very worst and probably the most difficult to maintain would be
the if-then-else structure hundreds, maybe thousands of line long.

Try a 'state machine' approach. Maybe "just" yacc/lex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top