Menu

Check existence of variable

Help
Ian Krukow
2015-09-15
2015-09-17
  • Ian Krukow

    Ian Krukow - 2015-09-15

    Hi all,

    is there any way in Asymptote to check whether a variable exists? Maybe via error handling (like try-except in python)? An alternative would be to search the fields of a structure and check whether a field name exists, but I have not found anything on that either.

    Can anyone help me?
    Kind regards
    Ian

     
  • Charles Staats

    Charles Staats - 2015-09-17

    To the best of my knowledge, there is no way to check dynamically whether a variable exists. The closest thing I can think of that works is to check whether a struct or array is null. Example:

    struct foo {
      real x;
    }
    // Initialize to null [NOTE: "=null" is required here.]
    foo myreal = null;
    
    // \vdots
    
    if (alias(myreal, null)) {
      myreal = new foo;
      myreal.x = 17;
    }
    

    I would also note that Asymptote does not support error/exception catching.

    What is your use case?

     

Log in to post a comment.