Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

weird function?

Moshe-A
Mentor

weird function?

Moshe-A
Mentor
Mentor

hey experts,

 

The following function returns a list of 4 angles and than causes AutoCAD to stuck and the cause of this is (angtos) can any one figure why?

 

 

(setq _degrees
   (lambda ()
     (mapcar
       (function
	 (lambda (ang)
	   (angtos ang 0 4)
	 )
       )
       (list (/ pi 4) (* (/ pi 2) 3) (* (/ pi 2) 5) (* (/ pi 2) 7))
     )
   )
 )

 

 

 

0 Likes
Reply
672 Views
19 Replies
Replies (19)

paullimapa
Mentor
Mentor

well this part of your code:

(mapcar
       (function
	 (lambda (ang)
	   (angtos ang 0 4)
	 )
       )
       (list (/ pi 4) (* (/ pi 2) 3) (* (/ pi 2) 5) (* (/ pi 2) 7))
)

Returns this:

("45.0000" "270.0000" "90.0000" "270.0000")

But when you do this you get a function:

(lambda ()
     (mapcar
       (function
	 (lambda (ang)
	   (angtos ang 0 4)
	 )
       )
       (list (/ pi 4) (* (/ pi 2) 3) (* (/ pi 2) 5) (* (/ pi 2) 7))
     )
)

AutoCAD returns:

#<SUBR @000001e69554f318 -lambda->

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

ВeekeeCZ
Consultant
Consultant

Exactly, what is the purpose of the outer lambda?

 

>> (setq _degrees (mapcar '(lambda (a) (angtos a 0 4)) (list (* pi 0.25) (* pi 1.5) (* pi 2.5) (* pi 3.5))))

>> ("45.0000" "270.0000" "90.0000" "270.0000") 

or 

>> ("45" "270" "90" "270")

...it depends on 'dimzin setting.

0 Likes

Moshe-A
Mentor
Mentor

@ВeekeeCZ ,

 

(setq _degrees (lambda (args)   ....    ))  ; create anonymous function

 

usage:

(_degrees) ; this returns the list as needed but than AutoCAD stuck

the result is the same even if changing it to regular function.

 

for test, if you replace (angtos) to (rtos) ... autocad does not stuck

(on my laptop on AutoCAD 2024 😀)

 

edit: sorry i had a mistake and fix it but this does not change the result, my AutoCAD get stuck

 

 

 

(defun degrees ()
  (mapcar
   (function
     (lambda (ang)
       (angtos ang 0 4)
     )
   )
   (list (/ pi 4) (* (/ pi 4) 3) (* (/ pi 4) 5) (* (/ pi 4) 7))
  )
 )

 

 

0 Likes

ВeekeeCZ
Consultant
Consultant

@Moshe-A 

 

sorry, I tried 2000 and 2025, and I don't see any issues. No lag, no stuck.

 

By the way, why do you prefer this construct? If I remember correctly, it was not recommended for some reason... What's the benefit of it over a classic named function?  

(defun _degrees () ...)

 

Edit: I see you used defun now... anyways, can't replicate the issue. Sorry.

0 Likes

paullimapa
Mentor
Mentor

no problems in my 2024.1.6 whether (_degrees) or (degrees)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Moshe-A
Mentor
Mentor

@ВeekeeCZ 

@paullimapa 

 

thanks for your help,

 

By the way, why do you prefer this construct? If I remember correctly, it was not recommended for some reason... What's the benefit of it over a classic named function?  

 

many years ago i saw here some one used it and like it. than i went back to the documentation and read this 

 

Use the lambda function when the overhead of defining a new function is not justified. It also makes your intention more apparent by laying out the function at the spot where it is to be used. 

 

and thought it is more efficient but now that you are asking i have second thoughts, maybe assigning it to a variable  actually defines a regular function?! 

 

Moshe

 

0 Likes

ВeekeeCZ
Consultant
Consultant

If you ask me, I would probably do something like this

 

(defun :angtos04 (rad) (angtos rad 0 4))

(setq angdec (mapcar (function :angtos04) (list (/ pi 4) (* (/ pi 4) 3) (* (/ pi 4) 5) (* (/ pi 4) 7))))
or just... 
(setq angdec (mapcar ':angtos04 (list (/ pi 4) (* (/ pi 4) 3) (* (/ pi 4) 5) (* (/ pi 4) 7))))

But I might not understand the context of your work. Also, I am not a theoretician, so it's just me.

Still, dunno why you got 'angtos stuck.

0 Likes

dbroad
Mentor
Mentor

To me, this would be preferrable and more readable to just assign the list to a variable: (setq degrees '("45.0000" "270.0000" "90.0000" "270.0000"))

 

What's the point of hiding logic inside a function?  What is weird is why those angles and why the different ways to calculate the 270 degree angles?

Architect, Registered NC, VA, SC, & GA.
0 Likes

Sea-Haven
Mentor
Mentor

I have used this for use within lisps where need an angle as radians used multiple times in calcs. The function DTR RTD have been used for years so not sure why would need to do multi angles.

 

 

(setq pi45 (* pi 0.25) pi2 (/ pi 2.) pi135 (* pi 1.25) pi180 pi) 

 

Could do the same for degrees.

 

 

0 Likes

Moshe-A
Mentor
Mentor

@ВeekeeCZ 

@paullimapa 

 

update:

On my office machine with R2023 it works fine

on my laptop R2024 on new clean installation (only 10 day ago) it stuck

still if i replace (angtos) with (rtos) just for test it does work without...

 

any way guys thanks 😀

Moshe

 

 

0 Likes

john.uhden
Mentor
Mentor

@Moshe-A ,

I think the lambda function has to be preceded by either an apostrophe or the function function.

The 2nd example starts with (lambda ...) without any prefix so that's as far as it gets... returning the value of the lambda function itself and nothing else.

John F. Uhden

john.uhden
Mentor
Mentor

@Sea-Haven ,

I like your style.  Decades ago I adopted a similar convention...

(setq 1/4pi (* 0.25 pi)

          1/2pi (* 0.5 pi)

          3/4pi (* 0.75 pi)

          2pi  (* 2 pi)

    ;     etc.

)

At the time I thought that recalling a value by symbol name had to be faster than the calculation to create the value.

But since those days I think someone here (probably @Kent1Cooper) taught me that unless the value requires numerous steps to create, 'tis faster to create the value on the fly.  I don't think I ever tested.

Nevermind.  The tests I made on a tiny function revealed a tie.

John F. Uhden

0 Likes

Moshe-A
Mentor
Mentor

update:

the issue comedown to this:

at VLIDE console key in this expression

 

MosheA_1-1734167404130.png

 

OK, return "90", AutoCAD window filp on and the VLIDE pops on the command line, AutoCAD enters to an unstable state, vlide is stuck and can be close only from Task Manager.

 

Could not be i am the only one having this?!  (AutoCAD 2024 Vanila)

i have checked Autodesk Access and there are no updates waiting to download.

 

MosheA_4-1734168092817.png

 

 

 

 

 

 

 

0 Likes

ВeekeeCZ
Consultant
Consultant

@Moshe-A 

 

you're a programmer. you should know the drill... you need to break down the problem into pieces. 

 

(angtos (* pi 0,4) 0 4)

 

from what see...  

PI symbol, does it behave correctly, what about different calculations?

ANGTOS function, again, is definition ok? Can't that be redefined?

Units.. is there an issue with all units conversion, or just decimal? In ACAD, unit setting in a regular drawing, any sort of issues there?

 

Can't Windows be an issue? What about some country setting... how about Excel, all good there?

 

I can't really help you... you don't need to answer all the questions for me... I just wanted to point out possible causes to check, and maybe you'll come across something that will give you a clue and help you resolve the problem. If you've already done so, sorry, but you're not mentioning it.

 

Good luck!

 

0 Likes

paullimapa
Mentor
Mentor

Stopped using Vlide since Autodesk switched to VS Code. I’d recommend the switch 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Moshe-A
Mentor
Mentor

@ВeekeeCZ 

 

It only happen under vlide on R2024

On R2022 (on the same computer) it is working very well.

 

My machine: normal Laptop with windows 11

 

thank you

 

 

0 Likes

Moshe-A
Mentor
Mentor

@paullimapa 

 

Thanks

0 Likes

calderg1000
Mentor
Mentor

Regards @Moshe-A 

After the first lambda has been executed.
What sense would it make to use lambda without arguments and without an expression, on a list. Even more so without an apostrophe or preceded by "function"

In my opinion, this expression does not make sense. Its evaluation only results in the parameter falat message. But still my C3D will see. 2025, does not crash

(setq  _degrees
(lambda() (list "45.0000" "270.0000" "90.0000" "270.0000"))
 )

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes

Moshe-A
Mentor
Mentor

@calderg1000 ,

 


@calderg1000 wrote:

Regards @Moshe-A 

After the first lambda has been executed.
What sense would it make to use lambda without arguments and without an expression, on a list. Even more so without an apostrophe or preceded by "function"

In my opinion, this expression does not make sense. Its evaluation only results in the parameter falat message. But still my C3D will see. 2025, does not crash

 


the answer to this is in my reply on message #7

 

thank you

Moshe

 

0 Likes