TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Logan on August 25, 2017, 04:19:00 PM
-
Hi all.
According to the help documentation the function function optimize the lambda expression...
Tells the Visual LISP compiler to link and optimize an argument as if it were a built-in function
Signature
(function symbol | lambda-expr)
Remarks
The function function is identical to the quote function, except it tells the Visual LISP compiler to link and optimize the argument as if it were a built-in function or defun.
Compiled lambda expressions that are quoted by function will contain debugging information when loaded into the Visual LISP IDE.
Ok.
Can anyone tell me if this optimization can be measured? :rolleyes2:
I always use the function function in set of lambda expressions just in case.
I'm sorry if this question has been answered before or if it does not make sense the question.
cheers
-
Use Michael's Benchmark (http://www.theswamp.org/lilly_pond/mp/lisp/benchmark.txt?nossi=1) code and test for yourself 8)
-
Hi,
You can try to write 2 similar defun, one using quote and the other using function:
)
(defun functionLambda
(l
) )
Save them in a .lsp file.
Compile the file into .vlx
Run a benchmark calling the 2 functions, you'd see functionLambda running 2 times faster than quoteLambda.
$ (setq l '(1 2 3 4 5 6 7 8 9 ))
(1 2 3 4 5 6 7 8 9)
_$ (benchmark '((quoteLambda l) (functionLambda l)))
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):
(FUNCTIONLAMBDA L).....1029 / 2.2 <fastest>
(QUOTELAMBDA L)........2262 / 1 <slowest>
-
Wow
I am really very happy with the answers. :yay!:
It was exactly what I was looking for.
Ron, thanks for showing me this code Ron, he's really very helpful.
Many thanks for your generosity Gile. I'm sure your answer will help many beginners like me.
Cheers
-
I'm just putting this here for my own understanding really but I think the key word here is 'compile', when an interpreter or compiler eval's your Lisp code as text it parses it and creates bytecodes (like machine assembly instructions) and puts them on the program stack which makes the execution of these functions much faster when needed.
So, when the compiler sees the 'function' directive it can create the bytecodes like a normal function whereas the quoted expression version (which is just data list at this point) must be evaluated to bytecodes each time it's used.
Hope that made sense :)
-
I'm just putting this here for my own understanding really but I think the key word here is 'compile', when an interpreter or compiler eval's your Lisp code as text it parses it and creates bytecodes (like machine assembly instructions) and puts them on the program stack which makes the execution of these functions much faster when needed.
So, when the compiler sees the 'function' directive it can create the bytecodes like a normal function whereas the quoted expression version (which is just data list at this point) must be evaluated to bytecodes each time it's used.
Hope that made sense :)
Nice. That helps my understanding. *cheers*
-
Hi all.
According to the help documentation the function function optimize the lambda expression...
Tells the Visual LISP compiler to link and optimize an argument as if it were a built-in function
Signature
(function symbol | lambda-expr)
Remarks
The function function is identical to the quote function, except it tells the Visual LISP compiler to link and optimize the argument as if it were a built-in function or defun.
Compiled lambda expressions that are quoted by function will contain debugging information when loaded into the Visual LISP IDE.
...
Logan,
Just for your information, TheSwamp has a built in Autolisp help page which you can read/link to. The web page is located in my directory on the server. The document is hyper-linked and all that good stuff. Below is a link how you can access a given function in the document/page.
http://www.theswamp.org/~john/avlisp/#function
Type the function name you want to link to or read up on after the hash mark.
Leave the hash mark off and you will get the index of the page.
http://www.theswamp.org/~john/avlisp/
Also, click any blue function name in a code block to access the same help page.
-
Se7en, thank you very much for the information.
It will be of great use to me.
That's why I love this place.
I am very grateful to all of you who contribute to my learning.
Thank you all.
-
No problem.
IMO that help file is very helpful and very useful; it's fast and self contained (you can download it and have a copy on your hard drive). Not to mention it's linked to the code blocks so if anyone uses a function in their code you can just click the function name and read up on it (that's why I wanted all users to use the custom code tags we created; so other people have an easier time learning from their code).
-
No problem.
IMO that help file is very helpful and very useful; it's fast and self contained (you can download it and have a copy on your hard drive). Not to mention it's linked to the code blocks so if anyone uses a function in their code you can just click the function name and read up on it (that's why I wanted all users to use the custom code tags we created; so other people have an easier time learning from their code).
It really is a great idea.