(EVAL (+ # # # ...)) produces no result and no error

(EVAL (+ # # # ...)) produces no result and no error

hencoop
Advisor Advisor
552 Views
3 Replies
Message 1 of 4

(EVAL (+ # # # ...)) produces no result and no error

hencoop
Advisor
Advisor

Hello all,

I have discovered a strange problem. Sometimes, a long list of numbers cannot be resolved.  (EVAL (CONS + (MAPCAR ...))) will produce no result and no error.  The return to the console is just a blank line.  The program in which the numeric result is expected will return an error indicating the value is not a number.  I have examined the list resulting from (MAPCAR ...) and confirmed that it is populated with REALs and nothing else.  I have manually submitted the list (CONS + <number list>) to the console for evaluation and it returns a blank line and nothing else; however,

I can successfully use (setq x 0)(foreach n <number list> (setq x (+ x n)) to get the sum.

 

Is there a limit to the length of a list of numbers that the function + can sum?  This particular list has 2276 numbers in it.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Accepted solutions (1)
553 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

Try it with the apostrophe prefix to the function name:

 

(eval (cons '+ '(1 2 3)))
6

Kent Cooper, AIA
0 Likes
Message 3 of 4

pbejse
Mentor
Mentor
Accepted solution

Might as well use (apply '+ lst) ;< -- on initial test, it appears that this doesnt have a limit.

I tried this with 5000 items.

 

But you are right (eval (cons + lst)) or even  (eval (cons '+ lst))) failed for loooooong list

0 Likes
Message 4 of 4

hencoop
Advisor
Advisor

Thanks @pbejse@Kent1Cooper,

I've been using Autolisp for decades and I am still finding (or rediscovering) little gems that I should have made more use of.  APPLY is one of them.  It took me a long while to get comfortable with using MAPCAR in the beginning.  It is now my favorite function for radically speeding up my list processing code.

 

That said, in this same programing effort I was debugging another issue where MAPCAR had created a long list of REALs but with a period as item# 643 which I have not been able to explain.  The results were to be used in reporting some values using PRINC and was not critical to the program so I commented the code out.  I examined the source list at item numbers before, at, and after the period's position and that did not reveal any data that could have caused MAPCAR to put a period there.  To me, MAPCAR is essentially a "Black Box" and how it does what it does is a mystery.  Are either of you aware of any issues or limitations involving MAPCAR usage?

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes