Author Topic: The difference between function and quote  (Read 1121 times)

0 Members and 1 Guest are viewing this topic.

baitang36

  • Bull Frog
  • Posts: 213
The difference between function and quote
« on: February 25, 2020, 07:35:55 AM »
(setq  TT (EVAL (quote(LAMBDA (K ) (ALERT K ) ) ) ))
(TT "dd" )
This is what it looks like when compiled:
Offset         0    1   2  3   4  5   6   7   8    9  A    B  C   D  E  F
00000000   0D 0A 20 46 41 53 34 2D  46 49 4C 45 20 3B 20 44      FAS4-FILE ; D
00000010   6F 20 6E 6F 74 20 63 68  61 6E 67 65 20 69 74 21   o not change it!
00000020   0D 0A 31 0D 0A 31 20 24  20 24 0D 0A 31 32 33 20    1  1 $ $  123
00000030   36 20 24 14 01 01 01 00  32 00 32 22 2A 39 01 00   6 $     2 2"*9 
00000040   55 01 00 02 00 64 64 5B  54 54 00 45 56 41 4C 00   U    dd[TT EVAL
00000050   00 5B 4C 41 4D 42 44 41  00 00 5B 4B 00 00 39 01    [LAMBDA  [K  9
00000060   00 5B 41 4C 45 52 54 00  00 5B 4B 00 00 39 02 00    [ALERT  [K  9 
00000070   39 03 00 01 01 43 00 00  06 00 0A 01 5C 00 00 43   9    C      \  C
00000080   00 00 01 00 0A 01 43 06  00 00 00 1C 14 01 00 00         C         
00000090   00 09 05 00 0A 09 04 00  34 00 07 35 01 03 00 03           4  5   
000000A0   0B 06 02 00 0A 09 01 00  35 01 02 00 03 16 15 00           5       
000000B0   B6 81 1A 52 B3 0A 3B 66  61 73 34 20 63 72 75 6E   ? R?;fas4 crun
000000C0   63 68 0A 3B 24 3B 41 32  2F 31 38 2F 32 30         ch ;$;A2/18/20


(setq tt (eval(function(lambda (k)    (alert k)   ))))
(tt "dd")
This is what it looks like when compiled:
Offset         0   1   2    3   4   5   6     7   8   9   A   B   C   D   E   F
00000000   0D 0A 20 46 41 53 34 2D  46 49 4C 45 20 3B 20 44      FAS4-FILE ; D
00000010   6F 20 6E 6F 74 20 63 68  61 6E 67 65 20 69 74 21   o not change it!
00000020   0D 0A 32 36 0D 0A 33 20  24 14 01 01 01 00 09 02     26  3 $       
00000030   00 5C 00 00 18 03 00 03  02 00 35 01 01 00 03 19    \        5     
00000040   01 00 16 24 0D 0A 31 33  39 20 37 20 24 14 01 01      $  139 7 $   
00000050   01 00 32 00 32 2A 2A 39  01 00 55 01 00 02 00 64     2 2**9  U    d
00000060   64 5B 54 54 00 45 56 41  4C 00 00 56 6B 77 6F 74   d[TT EVAL  Vkwot
00000070   65 00 00 01 01 43 00 00  06 00 0A 32 00 32 1A 2A   e    C     2 2 *
00000080   39 01 00 5B 41 4C 45 52  54 00 4B 00 00 5C 00 00   9  [ALERT K  \ 
00000090   43 00 00 03 00 0A 5C 00  00 32 00 5B 2D 6C 61 6D   C     \  2 [-lam
000000A0   62 64 61 2D 00 00 3A 01  43 06 00 01 00 1C 14 01   bda-  : C       
000000B0   00 00 00 09 05 00 0A 57  00 00 00 00 09 06 00 51          W       Q
000000C0   01 04 00 01 00 35 01 03  00 03 0B 06 02 00 0A 09        5         
000000D0   01 00 35 01 02 00 03 16  18 00 A9 8A FC F9 EA 3D     5       ?
000000E0   9D EE 0A 3B 66 61 73 34  20 63 72 75 6E 63 68 0A    ?;fas4 crunch
000000F0   3B 24 3B 41 32 2F 31 38  2F 32 30                            ;$;A2/18/20

The following points can be seen:1. No function is defined when quote is used.When you use function, you define a function, -lambda-.When quote is used, (alert k) is run as a table.3. When using function, alert and k are two separate strings.Conclusion: when using quote, lambda is not compiled into a function. With function, a lambda is compiled into a function that can be optimized quickly.The so-called optimization is that you can access the function entrance address quickly and directly, without looking up the address corresponding to the function name and then calling it.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: The difference between function and quote
« Reply #1 on: February 25, 2020, 08:17:51 AM »
Interesting.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

VovKa

  • Water Moccasin
  • Posts: 1629
  • Ukraine
Re: The difference between function and quote
« Reply #2 on: February 25, 2020, 08:50:08 AM »
and that's why (mapcar (function (lambda.... runs much faster than (mapcar '(lambda....