Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to define a layer between data and functions

Reply
Thread Tools

how to define a layer between data and functions

 
 
bpatton@ti.com
Guest
Posts: n/a
 
      08-17-2006
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

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      08-17-2006

Quoth http://www.velocityreviews.com/forums/(E-Mail 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

--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
(E-Mail Removed) Groucho Marx
 
Reply With Quote
 
 
 
 
bpatton@ti.com
Guest
Posts: n/a
 
      08-17-2006
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

Ben Morrow wrote:
> Quoth (E-Mail 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
>
> --
> Outside of a dog, a book is a man's best friend.
> Inside of a dog, it's too dark to read.
> (E-Mail Removed) Groucho Marx


 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      08-17-2006
[please don't top-post. have you read the Posting Guidelines?]

Quoth (E-Mail 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

--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ (E-Mail Removed) ~ Jorge Luis Borges, 'The Babylon Lottery'
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      08-17-2006
(E-Mail 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.

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
business layer, data access layer , presentation layer for asp.net using C#.net Dhananjay ASP .Net 1 12-18-2006 11:35 PM
The business layer and data access layer java-john Java 0 03-23-2006 07:10 PM
Business Layer, Data Layer, Speed Issues, Classes, and all that et ASP .Net 2 03-06-2006 02:46 PM
Using transparent layer for data input (glassPane?) over another layer Wolfgang Java 1 05-01-2004 03:09 AM



Advertisments