- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am reading Efficient Variables post by Kenny Ramage.
And in post he says creating many variables in list is not efficient. But I debate what is more efficient:
1) To create many variables.
2) To search list multiple times for variables.
I have this code
(defun ListEntity (data / layer color linetype lineweight linescale space)
(setq data (if data data (list nil))
layer (nth 0 data) ; Layer name (string)
color (nth 1 data) ; Color code
linetype (nth 2 data) ; Linetype
lineweight (nth 3 data) ; Lineweight: by block -2
linescale (nth 4 data) ; Linetype scale (optional)
space (nth 5 data) ; 0 = Model space, 1 = Paper space (optional)
paper (if (eq 0 space) "Model" (nth 6 data)) ; Paper space tab name
)
(list
'(100 . "AcDbEntity")
(if space (cons 67 space) '(67 . 0))
(if paper (cons 410 paper) '(410 . "Model"))
(if layer (cons 8 layer) '(8 . "0"))
(if linetype (cons 6 linetype) '(6 . "BYLAYER"))
(if color (cons 62 color) '(62 . 256))
(if lineweight (cons 370 lineweight) '(370 . -1))
(if linescale (cons 48 linescale) '(48 . 1.0))
)
)
I am getting parameters in list data, because I don't know if all variables will be in list or not. Maybe data itself will be just nil.
First I check if data is nil. If it is I just create list with one nil so next code in setq would work. Retrive data to diffirent variables. They can also be nil.
After it, from line 13, I check if variable is nil or not. If it is not nil I add associative list with it, if it is nil, I just add default associative list.
So, I create 7 variables for data. I could write line 13 like this:
(if (nth 5 data) (cons 67 (nth 5 data)) '(67 . 0))But will this be more efficient? To get data from list two times? Would here be any meaning with current compiuters power?
Solved! Go to Solution.