vim - Checking whether some object has been already tested -


I have a script, which is to see that some values ​​(eg option or function argument) Or does not match. I want my script to be able to check recursive data structures. So the question is: Is there a more efficient way to re-run some inventory, which includes references to already checked lists and dictionaries, example code:

  function: already Check only (RGR, checklist) Type (A: AGR)! = Type ([]) & amp; Amp; Type (a: arg)! = Type ({}) obj in one: Return 0 AndIf for checklst if a: arg obj return 1 endif call add add (a: checklst, a: arg) return 0 endfunction  
Finding a way to sort

checklist (that is to compare the references, but not the value they found) or even to use a hash.

As I have guessed that you have already searched, as a list of inventory keys Do not allow list or dictionary variable to be used. This means that you can not do this, for example, to populate a "checked" dictionary like this:

  "Unless there is a string, it will not work Check [k] = 1  

There is no direct way to generate a unique string from a list or dictionary, so it is not reliable:

 : Check [String (K)] = 1  

Instead of trying to make a hashtable, data structures There is a better way to mark yourself. If you do not temporarily consider your data structures to be read only, one way to do this is by : lockvar :

 Use : Dict something {{}: Give some dicks ['foo'] = [1, 2, 3]]: Lockwalker 1 a few minutes  

To read only in the form of someDict . ( 1 limits the locking to the top level, then nested structures are automatically translated Lock status of a variable can be inspected:

 : Echo has been installed ('some duct') 1: Echo overlaps ("Some duct ['Foo'] ") 0: Unlocking the buzz is as simple:  
 : Unlockware 1 a few dicks  Alok (" Some Dict ['Foo'] [0] " ) 0  

So now we have a technique to mark the personal level of nested data structures as "check", a method to ask Is that Whether or not a specific level has been marked, and when we 're done, keeping it all together, pre-checking () can be modified as follows:

< Pre> function! S: Pre-check (arg, checklist) if type (A: AGR)! = Type ([]) & amp; Amp; Type (a: arg)! = Type ({}) 0 Back "If this particular list or dictionary has already been checked, then just" right back immediately "if Istocked ('A: AGR') echo" already checked " has gone. Lock the "Return 1 Endif" list or the dictionary was already checked to mark this item "Note that only the top level of the list or the dictionary is locked; the value is not locked" Lockvar 1 a: arg "We Remember what is locked, so it can be unlocked once "We have done." Add Call (a: Checklist, a: arg) Return 0 and Function

Once you've checked, just remove all the locks:

  For OBJE: Checklast UnlockWare 1 OBG Ender  

Hope this helps the abuse of the locking feature is misused, but it will probably work as important for you.


Comments