Properly declaring variables and handling variables when they may be null/nil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need help with an AutoLISP program I am editing/re-writing. I have tried searching the internet for how to address my issue without much success. I believe that my problem is that I don’t know how to properly handle, account for, and set null values, particularly when it comes to having a list with some null values as part of that list.
I have a LISP program that will read a text file and convert that text file into data points (X Y points) that the LISP routine then used to draw a polyline. The LISP program uses the read-line command to read in one line at a time the text string of that line, and then parses out that text letter by letter to obtain the X and Y coordinates and convert those text characters into real numbers that can be entered in as coordinates for a polyline.
The existing program uses a list variable containing the first list item of the X coordinate and the second list item of the Y coordinate, as well as other list variables. There are instances where a coordinate may not exist and I need to be able to properly handle that null instance and not pass a zero (0), or not pass a nil to a function that cannot handle a nil, etc. I am also not sure how the LISP routine is declaring variables and properly setting the variable type, or keeping variable types straight so that the wrong type of variable is not passed to a function expecting a different variable type. The LISP routine reads in G-code and converts the G-code XY coordinates into a graphical polyline representation of the tool path(s). The original LISP routine uses 0.0 as the default “no value” X and Y coordinate values, and 999 as the set value for the non-coordinate comparison check to know when to stop. This is problematic should the G-code contain 0.0 or 999 coordinate values.