how to define a layer between data and functions

Discussion in 'Perl Misc' started by bpatton@ti.com, Aug 17, 2006.

  1. Guest

    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
     
    , Aug 17, 2006
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    > 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.
    Groucho Marx
     
    Ben Morrow, Aug 17, 2006
    #2
    1. Advertising

  3. Guest

    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 :
    > > 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.
    > Groucho Marx
     
    , Aug 17, 2006
    #3
  4. Ben Morrow Guest

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

    Quoth :
    > 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.
    ~ ~ Jorge Luis Borges, 'The Babylon Lottery'
     
    Ben Morrow, Aug 17, 2006
    #4
  5. Dr.Ruud Guest

    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."
     
    Dr.Ruud, Aug 17, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. et
    Replies:
    2
    Views:
    1,943
  2. Wolfgang
    Replies:
    1
    Views:
    1,131
  3. java-john
    Replies:
    0
    Views:
    543
    java-john
    Mar 23, 2006
  4. Ily
    Replies:
    2
    Views:
    355
    Robert Haken [MVP]
    Oct 13, 2006
  5. Dhananjay
    Replies:
    1
    Views:
    1,166
    sloan
    Dec 18, 2006
Loading...

Share This Page