LibertyOne Posted June 11, 2013 Posted June 11, 2013 What is the better way to store data that you need to constantly access? In an association list or external in a file? Any thoughts on this? Please share your experiences... Quote
Tharwat Posted June 11, 2013 Posted June 11, 2013 I think it depends on the data . so what kind of data you are talking about ? Quote
LibertyOne Posted June 11, 2013 Author Posted June 11, 2013 I've got a whole lotta things... For example: a table of rebar sizes, cross cut areas, weights and stock attributes (means of delivery, either bar or coiled) I wrote this last night: ;; A-List for Stabstahl ;; (Nenndurchmesser ds [mm] Nennquerschnittsfläche As [cm^2] Nenngewicht [kg/m] Betonstabstahl [T/nil] Betonstahl in Ringen [T/nil]) (setq *stabstahl* (list (list 6.0 0.283 0.222 T T) (list 8.0 0.503 0.395 T T) (list 10.0 0.785 0.617 T T) (list 12.0 1.131 0.888 T T) (list 14.0 1.54 1.21 T T) (list 16.0 2.01 1.58 T nil) (list 20.0 3.14 2.47 T nil) (list 25.0 4.91 3.85 T nil) (list 28.0 6.16 4.83 T nil) (list 32.0 8.04 6.31 T nil) (list 40.0 12.57 9.86 T nil) ) ) I have other tables in this pamphlet that I want to translate over to AutoLisp (12 in all). My gut feeling is that for this sort of job the association list is the best because the tables are not just a list of sizes. Many factors determine what to select out of the table and most of these desisions are made in your head because you know right off the bat what strength of concrete you are using or to what type of climate the concrete part is going to be exposed. But I'm not sold on it yet. I don't want to bog down my program with data. Quote
LibertyOne Posted June 11, 2013 Author Posted June 11, 2013 Even wrote some expressions to extract the data... What's the weight per m of a 20mm bar? (caddr (assoc 20.0 *stabstahl*)) --> 2.47 kg Is 16mm rebar avalible in rings? (last (assoc 16.0 *stabstahl*)) --> nil What is the area of 5 28mm rebars? (* 5 (cadr (assoc 28.0 *stabstahl*))) --> 30.8 cm^2 What is the total weight of 8.5m of 8mm rebar and 16m of 14mm rebar? (+ (* 8.5 (caddr (assoc 8.0 *stabstahl*))) ;3.3575 (* 16.0 (caddr (assoc 14.0 *stabstahl*))) ;19.36 ) --> 22.7175 kg Quote
alanjt Posted June 11, 2013 Posted June 11, 2013 If it's a series of lists that you will want to reference from many different programs, I'd keep the list in a separate .LSP file and have it loaded with your acaddoc.LSP. That way there's no converting of data, there's just a global variable from which you can reference. or You could code it as an assoc replacement subroutine. Rather than saying (* 5 (cadr (assoc 28.0 *stabstahl*))) say (* 5 (cadr (_thisIsMyCompanyListRoutine 28.0))). Quote
Lee Mac Posted June 11, 2013 Posted June 11, 2013 I agree with Alan's advice of retaining the use of an AutoLISP list to store the data; storing the data in a delimited file would require the additional processing of parsing and converting the string data before it can be used by the program. If the data structure was substantially complex, I might opt to use an XML file which could then be queried using the methods of the MSXML.DOMDocument object, but for your simple list this is not necessary. My only other suggestion would be to quote literal data where possible to avoid the need to evaluate superfluous expressions, for example, your posted list: (setq *stabstahl* (list (list 6.0 0.283 0.222 T T) (list 8.0 0.503 0.395 T T) (list 10.0 0.785 0.617 T T) (list 12.0 1.131 0.888 T T) (list 14.0 1.54 1.21 T T) (list 16.0 2.01 1.58 T nil) (list 20.0 3.14 2.47 T nil) (list 25.0 4.91 3.85 T nil) (list 28.0 6.16 4.83 T nil) (list 32.0 8.04 6.31 T nil) (list 40.0 12.57 9.86 T nil) ) ) Would become: (setq *stabstahl* '( ( 6.0 0.283 0.222 t t ) ( 8.0 0.503 0.395 t t ) (10.0 0.785 0.617 t t ) (12.0 1.131 0.888 t t ) (14.0 1.54 1.21 t t ) (16.0 2.01 1.58 t nil) (20.0 3.14 2.47 t nil) (25.0 4.91 3.85 t nil) (28.0 6.16 4.83 t nil) (32.0 8.04 6.31 t nil) (40.0 12.57 9.86 t nil) ) ) Quote
LibertyOne Posted June 11, 2013 Author Posted June 11, 2013 You could code it as an assoc replacement subroutine. Rather than saying (* 5 (cadr (assoc 28.0 *stabstahl*))) say (* 5 (cadr (_thisIsMyCompanyListRoutine 28.0))). I also wrote these to extract the data somewhat easier: (defun rebar-area (/ ds) (cadr (assoc ds *stabstahl*)) ) (defun rebar-weight (/ ds) (caddr (assoc ds *stabstahl*)) ) (defun rebar-bar (/ ds) (cadddr (assoc ds *stabstahl*)) ) (defun rebar-ring (/ ds) (last (assoc ds *stabstahl*)) ) My only other suggestion would be to quote literal data where possible to avoid the need to evaluate superfluous expressions Thanks for the tip, Lee...I bet that cuts down on evaluation time. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.