Author Topic: The Function Function  (Read 2599 times)

0 Members and 1 Guest are viewing this topic.

Rustabout

  • Newt
  • Posts: 135
The Function Function
« on: July 07, 2020, 08:12:06 AM »
I don't 100% understand what the AutoLISP developer reference guide means when it states that the 'function' function optimizes the lambda expression. Is it somewhat of a relic for when LISP routines didn't run quite as fast as they do now? Do people here still use it in their code? It's a hard function to search for help on for obvious reasons ;-)

Cheers!

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: The Function Function
« Reply #1 on: July 07, 2020, 08:27:05 AM »
Do people here still use it in their code?
i always do

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: The Function Function
« Reply #2 on: July 07, 2020, 08:43:16 AM »
... It's a hard function to search for help on for obvious reasons ;-)

You've always got ours. Ours isn't as flashy as the Autodesk version but it helps. I haven't updated it in years either but it still has a ton of good info.
https://www.theswamp.org/Sources/doc/avlisp/#function
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: The Function Function
« Reply #3 on: July 07, 2020, 09:04:58 AM »
I've got small interesting observation from your question,
function converts any literal value into a symbol type, and any lambda function into a LIST type -

Code - Auto/Visual Lisp: [Select]
  1. #<SUBR @0000006ba3ccea98 MAPCAR>
  2. SYM
  3. _$ (function abc)
  4. ABC
  5. _$ (set (function abc) "hello world")
  6. "hello world"
  7. _$ abc
  8. "hello world"
  9. _$ (function (lambda (x) x))
  10. (quote #<USUBR @0000006bd150fcf0 -lambda->)
  11. _$ (type (function (lambda (x) x)))
  12. _$ (type (lambda (x) x))
  13. USUBR
  14.  

(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: The Function Function
« Reply #4 on: July 07, 2020, 01:20:50 PM »
I've got small interesting observation from your question,
function converts any literal value into a symbol type, and any lambda function into a LIST type -

You should compare function with quote, as when we do:
(macar '(lambda (x) ...) ...) or (macar (quote (lambda (x) ...)) ...)
vs
(macar (function (lambda (x) ...)) ...)

Code - Auto/Visual Lisp: [Select]
  1. _$ (function (lambda (x) x))
  2. (quote #<USUBR @000001eb96e3b138 -lambda->)
  3. _$ (quote (lambda (x) x))
  4. (LAMBDA (X) X)
  5. _$ '(lambda (x) x)
  6. (LAMBDA (X) X)
« Last Edit: July 07, 2020, 01:23:56 PM by gile »
Speaking English as a French Frog

d2010

  • Bull Frog
  • Posts: 326
Re: The Function Function
« Reply #5 on: July 07, 2020, 03:25:26 PM »
If you must learn Java or C# :smitten:, then you can try this newcode.txt, for teaching Csyntax, gramarlyC++,whole C+=source.
You  can convert this newcode.txt to 100%Vlisp.
http://lisp2arx.3xforum.ro/viewtopic.php?pid=168#168
Do not waste your-time with lambda, because the function+lambda not exists
in Java or JavaScript.?!


« Last Edit: July 07, 2020, 03:35:55 PM by d2010 »

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: The Function Function
« Reply #6 on: July 07, 2020, 04:03:56 PM »
Do not waste your-time with lambda
i've been doing lisp for quite a while and i must say that it covers 99% of my needs
and i've never thought of switching to smth else

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: The Function Function
« Reply #7 on: July 07, 2020, 04:10:18 PM »
'function' is to 'quote' what 'defun' is to 'defun-q'.
Code - Auto/Visual Lisp: [Select]
  1. (setq a '(lambda (x) (* x x)))
  2. (setq b (function (lambda (x) (* x x))))
  3. (defun c (x) (* x x))
  4. (defun-q d (x) (* x x))

Code: [Select]
_$ a
(LAMBDA (X) (* X X))
_$ b
(quote #<USUBR @000001eb9681c890 -lambda->)
_$ c
#<USUBR @000001eb96d17930 C>
_$ d
((X) (* X X))

Code: [Select]
_$ (benchmark '((apply a '(2)) (apply b '(2)) (apply 'c '(2)) (apply 'd '(2))))
Benchmarking ...................Elapsed milliseconds / relative speed for 65536 iteration(s):

    (APPLY B (QUOTE (2))).............1656 / 1.93 <fastest>
    (APPLY (QUOTE C) (QUOTE (2))).....1688 / 1.90
    (APPLY A (QUOTE (2))).............2969 / 1.08
    (APPLY (QUOTE D) (QUOTE (2))).....3203 / 1.00 <slowest>
Speaking English as a French Frog

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: The Function Function
« Reply #8 on: July 07, 2020, 06:21:40 PM »
Quote from: Random thoughts, Stuart Smalley ...
I wonder how many times benchmark has been run over the  years.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: The Function Function
« Reply #9 on: July 07, 2020, 06:26:55 PM »
MP, was that utility, you wrote, ever released on the newsgroups (or elsewhere: where were after the newsgroups and before here)? The reason I ask is because I was just wondering where else it is so widely used (besides here).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: The Function Function
« Reply #10 on: July 08, 2020, 05:41:26 AM »
The version that is used at the swamp - not my first benchmarker - was penned in 2005 - a year after I quit frequenting Autodesk’s discussion forum and joined - and participated exclusively - at the swamp. I’ve seen code I’ve written show up in other countries - never mind discussion forums - as early as the late 90s - yes, getting old as fk - so it's likely used elsewhere - but I've never attempted to identify where.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: The Function Function
« Reply #11 on: July 08, 2020, 06:49:07 AM »
If you must learn Java or C# :smitten:, then you can try this newcode.txt, for teaching Csyntax, gramarlyC++,whole C+=source.
You  can convert this newcode.txt to 100%Vlisp.
http://lisp2arx.3xforum.ro/viewtopic.php?pid=168#168
Do not waste your-time with lambda, because the function+lambda not exists
in Java or JavaScript.?!

C++ has std::function &  lambda expressions  :smitten: https://en.cppreference.com/w/cpp/utility/functional/function

Rustabout

  • Newt
  • Posts: 135
Re: The Function Function
« Reply #12 on: July 08, 2020, 08:46:35 AM »
I stumbled upon this by chance when looking for something else:

https://www.cadtutor.net/forum/topic/47217-lambda-function-mapcar-apply-foreach-explained/

There's a very useful explanation of the 'function' function in regards to optimization towards the end of that discussion.

I appreciate all the explanations! I'm still a bit confused... but that's due to my own deficiencies rather than the quality of the explainations you've posted above. I figure If I review all the posts with a fresh cup of coffee I'll be all sorted out; thanks everyone!!


baitang36

  • Bull Frog
  • Posts: 213
Re: The Function Function
« Reply #13 on: July 08, 2020, 08:50:38 PM »