_(I 've also posted the following on SO, but I guess it's a more Nim-specific 
question)_

**Before saying anything, please let me make it clear that this question is 
part of my work on an interpreter - and has nothing to do with validating a Nim 
proc 's arguments.**

Let's say we have an enum of Value types. So a value can be:
    
    
        SV, // stringValue
        IV, // integerValue
        AV, // arrayValue
        etc, etc
    
    
    Run

then let's say we have a function **F** which takes one of the following 
combinations of arguments:
    
    
        [
           [SV],
           [SV,IV],
           [AV]
        ]
    
    
    Run

Now, the function is called, we calculate the values passed, and get their 
types. Let's say we get [XV,YV].

**The question is:**

What is the most **efficient** way to check if the passed values are allowed?

* * *

In more specific terms, let's say we have these constraints:
    
    
    @[@[AV,FV],@[DV,FV],@[BV,FV],@[IV,FV]]
    
    
    Run

meaning: first argument can be AV, second FV - **OR** \- first argument DV, 
second FV - **OR** \- and so on...

and this is my validation function:
    
    
    proc validate(xl: ExpressionList, name: string, req: FunctionConstraints): 
seq[Value] {.inline.} =
        ## Validate given ExpressionList against given array of constraints
        
        result = xl.list.map((x) => x.evaluate()) # each x.evaluate returns a 
Value
        
        if not req.contains(result.map((x) => x.kind)):  # each Value has a 
kind: SV, IV, AV, etc...
    
    
    Run

Of course, even the .map, .contains and all that can be expensive when called 
many times...

So, I'm looking for alternatives. All ears! :)

Reply via email to