example:
(foreach n '(2 3 4) (print n))
Compile and decode this sentence
<... >
结论:Conclusion:
(foreach n '(2 3 4) (print n))相当于:Equivalent to:
(setq var1 '(2 3 4))
(while var1
(SETQ N (car var1))
(setq var1(cdr var1))
(print N)
)
thank youexample:
(foreach n '(2 3 4) (print n))
Compile and decode this sentence
<... >
结论:Conclusion:
(foreach n '(2 3 4) (print n))相当于:Equivalent to:
(setq var1 '(2 3 4))
(while var1
(SETQ N (car var1))
(setq var1(cdr var1))
(print N)
)
Most excellent post @baitang36
I can appreciate the work you've done to decipher the bytecode.
Well done !
Regards,
I agree with, kdub. Another great post, baitang36!thank you
I agree with, kdub. Another great post, baitang36!thank you
Dear baitang36, please you calculate the speed .
I got , in autocad2007, the function foreach is more faster that while......
But inside Autocad2022 or AutoCad2014?
:smitten:Try compiling it into Fas and then compare the speedI agree with, kdub. Another great post, baitang36!thank you
Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s):
(REVERSE_WHILE L).......1500 / 2.35 <fastest>
(REVERSE_FOREACH L).....1562 / 2.26
(REVERSE_REPEAT L)......3531 / 1.00 <slowest>
Elapsed milliseconds / relative speed for 512 iteration(s):
(TEST_FOREACH MYLIST).....1969 / 1.04 <fastest>
(TEST_WHILE MYLIST).......1984 / 1.03
(TEST_REPEAT MYLIST)......2047 / 1.00 <slowest>
---- Benchmark Utility: In memory of Michael Puckett ----
AcadVer = 21.0 BricsCAD
We can immediately see the relative inefficiency of repeat for this kind of task.
I think it shows the inefficiency of nth..You are absolutely right.
By my side, I'd rather use foreach for this kind of task, despite the fact if is 'slower', because it allows to write the code a more declarative and self explanatory way.
With foreach, the code describes what you want it to do; with repeat or while, the code details how it should do it. I prefer to let the interpreter (or compiler) handle the how part (as shown by baitang36).
Over time, I've learned that it's better to spend time writing directly understandable code than to chase hundredths of a millisecond.
I was just trying to show empirical data. I also prefer to use foreach for the reason you stated and the simplicity. never really liked processing selection sets with a counter
You are wrong, the function the "(ssname ss i)" inside C++Arx is very,very fast selection of entities
< .. >
Over time, I've learned that it's better to spend time writing directly understandable code than to chase hundredths of a millisecond.
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
I agree with, kdub. Another great post, baitang36!thank you