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

0 Members and 1 Guest are viewing this topic.

baitang36

  • Bull Frog
  • Posts: 213
The difference between function and quote
« on: July 08, 2020, 08:48:00 PM »
Let's start with an example
Code - Auto/Visual Lisp: [Select]
  1. (setq TT (EVAL (quote(LAMBDA (K ) (ALERT K ) ) ) ))
  2. (TT "dd" )
  3.  
After compiling, it looks like this:
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")

These two sentences are compiled as follows:
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

We can see the following points:
1. No Function is defined when quote is used
Function function is used to define a Function, - lambda -, the content of the Function is the red part
2. When quoting, (alert K) is interpreted as a table.
3. If Function function is used, alert and K are two independent strings.
Conclusion: when quote is used, lambda is not compiled into a Function, which is interpreted and runs slowly. When Function function is used, lambda is compiled into a function, which can be optimized with high speed.
The so-called optimization is that you can quickly and directly access the function entry address, and do not need to find the address corresponding to the function name before calling.
Some decompiler tools do not properly handle function, so that programs that use this function cannot be decompiled.


VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: The difference between function and quote
« Reply #1 on: July 09, 2020, 04:43:14 AM »
thanx baitang36
cool as always

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: The difference between function and quote
« Reply #2 on: July 09, 2020, 07:44:50 AM »
Yes there are differences in compiled files, but I don't see importance of this research... We all know that (function) function has a role in converting (lambda) functions into very similar expressions as built-in ALISP protected functions OOTB... But I don't know how can that be used in real situation useful ways that it has some sense... We all know you can write (lambda) in both ways, so what is real benefit of (function) function? - to me you are stating that it isn't recognizable by decompilers... But then how did you find such pattern in your examples - so it's surely recognizable... There is no obvious benefit of using (function) - I suppose that only benefit in real situations is that when combined with operators or (lambda)s it works just slightly faster than usual way... BTW. I prefer storing my lisps in open source non-compiled form - I can read, modify, comment, do cosmetic changes, copy+paste subs, ... With compiled files, I almost can't do anything without reverting them into ordinary LISP and I and suppose others don't have such software to do opposite reverse engineering which is in fact illegal procedure... IMO if you want to keep your intellectual property, then don't share your files - they can be otherwise used or abused in known and unknown manners and you will loose any form of authority over them. To me when I share, I think that someone may find that useful data as reference for further improvements, so I share LISP for higher purposes - I believe in future progression of mankind in all aspects of life - so why would programming be excluded from that belief... On the other side I sometimes have this thought in mind - why I wouldn't help someone that may find tool useful in some simple way - we all share sometimes something we find interesting, so interesting things and solutions occasionally fall into sphere of spreading knowledge further and wider and to me it has sense in facts that it may bring some positive aspects and change habits we usually do things - to me this is also important aspect of every person - dynamically thinking and adapting to new everyday working situations. But that's my opinion and you don't have to agree with it, after all we all have free will and freedom to do things we think are correct...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: The difference between function and quote
« Reply #3 on: July 09, 2020, 08:36:44 AM »
I prefer storing my lisps in open source non-compiled form - I can read, modify, comment, do cosmetic changes, copy+paste subs, ... With compiled files, I almost can't do anything
why not keep both of them?
i have lsp files for editing and fas files for loading/running

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: The difference between function and quote
« Reply #4 on: July 09, 2020, 08:49:18 AM »
I prefer storing my lisps in open source non-compiled form - I can read, modify, comment, do cosmetic changes, copy+paste subs, ... With compiled files, I almost can't do anything
why not keep both of them?
i have lsp files for editing and fas files for loading/running

It works for me if I load/run lisps in non-comipled form also pretty well, so no need to make duplicates... And if I change something I have resluts instantly...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Crank

  • Water Moccasin
  • Posts: 1503
Re: The difference between function and quote
« Reply #5 on: July 09, 2020, 12:54:54 PM »
I prefer storing my lisps in open source non-compiled form - I can read, modify, comment, do cosmetic changes, copy+paste subs, ... With compiled files, I almost can't do anything
why not keep both of them?
i have lsp files for editing and fas files for loading/running
I used to do the same thing: VLX and LSP in the same folder.
This was because I assumed Acad was smart enough to know that loading a VLX would be a little faster (smaller, so less network traffic).
.
.
.
.
.
After a year I found out that actually it was loading both: VLX and LSP.
Vault Professional 2023     +     AEC Collection

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: The difference between function and quote
« Reply #6 on: July 09, 2020, 09:52:15 PM »
baitang36, Very nice explanation. Thank you.

After studying Scheme I developed a habit of writing a lot of my code as:
Code - Auto/Visual Lisp: [Select]
  1. (defun TT (K)
  2.   ( (lambda ()
  3.      (alert K))) )
Would that function body be interpreted as a table as well?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Rustabout

  • Newt
  • Posts: 135
Re: The difference between function and quote
« Reply #7 on: July 09, 2020, 10:56:32 PM »
Re: Compiling,

I think that computers run so fast these days that compiling codes like LISP, and a more modern example with Python, isn't quite as critical as it once was. Even my sloppy coding runs only a bit faster compiled. That said there would still be enough slow down to aggravate the most 'comlainy' draftsperson enough to not use the code at all, and instead continue to do things 10x slower. I've also had issues with people placing files in the same folder path (I leaned towards avoiding placing files on the server in the small offices I worked for). This meant that any code with a file path would need to be adjusted.

Baitang36: Very impressed with anyone that can decipher compiled code!

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: The difference between function and quote
« Reply #8 on: July 10, 2020, 12:03:44 AM »
Decipher code comes from the old DOS days and debug.

I agree vlx v's plain lsp did some code a bit slow added a 1000 objects, changed to entmake almost instant, so the moral here is small "command" is ok big entmake far more speed than worrying about compiling. Still need to sip the coffee every now and then.
A man who never made a mistake never made anything

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: The difference between function and quote
« Reply #9 on: July 10, 2020, 06:40:34 AM »
After a year I found out that actually it was loading both: VLX and LSP.
hehe :)
i have a 'loader' lisp which i put in the Startup Suite and it loads all my fas/lsp files with every drawing
(load ...) function has a hidden 'feature' (incorrectly described if the help file) - if you do not specify file's extension it will load the newest of the files with the given name

P.S
also (load ...) function loads lsp files differently depending where it was called from

if you (load ...) lsp file from autocad's command line or with '_appload' command's dialog it will evaluate functions in this lsp file as 'SUBR'
but if you (load ...) or use 'File\Load File' in VLIDE then the functions will be 'USUBR'

'SUBR' functions are 'compiled' and therefore will run faster than 'USUBR'

Rustabout

  • Newt
  • Posts: 135
Re: The difference between function and quote
« Reply #10 on: July 11, 2020, 11:42:07 PM »
While we are on the subject of compiling (I don't want to start a new topic), do DCL files 'embed' themselves into the compiled code? Meaning they would become part of the code and not need to be loaded from a specific location? I recall reading something along these lines but honestly can't even remember if it was even to do with LISP. That would be an extra check-mark in the 'compile' column.

baitang36

  • Bull Frog
  • Posts: 213
Re: The difference between function and quote
« Reply #11 on: July 12, 2020, 03:20:09 AM »
baitang36, Very nice explanation. Thank you.

After studying Scheme I developed a habit of writing a lot of my code as:
Code - Auto/Visual Lisp: [Select]
  1. (defun TT (K)
  2.   ( (lambda ()
  3.      (alert K))) )
Would that function body be interpreted as a table as well?

Offset      0  1  2  3  4  5  6  7   8  9 10 11 12 13 14 15

00000000   0D 0A 20 46 41 53 34 2D  46 49 4C 45 20 3B 20 44      FAS4-FILE ; D
00000016   6F 20 6E 6F 74 20 63 68  61 6E 67 65 20 69 74 21   o not change it!
00000032   0D 0A 34 33 0D 0A 34 20  24 14 01 01 01 00 09 02     43  4 $       
00000048   00 5C 00 00 18 03 00 57  0E 00 00 00 14 00 00 00    \     W       
00000064   00 03 02 00 35 01 01 00  03 16
09 03 00 34 00 07       5        4 
00000080   19 01 00 16 24 0D 0A 31  31 37 20 34 20 24 14 01       $  117 4 $ 
00000096   01 01 00 32 00 32 18 2A  39 01 00 5B 54 54 00 00      2 2 *9  [TT 
00000112   01 01 43 00 00 03 00 0A  32 13 32 21 2A 32 00 32     C     2 2!*2 2
00000128   2B 2A 39 02 00 5B 41 4C  45 52 54 00 4B 00 00 5C   +*9  [ALERT K  \
00000144   00 00 32 13 5B 2D 6C 61  6D 62 64 61 2D 00 00 3A     2 [-lambda-  :
00000160   5C 00 00 43 00 00 04 00  0A 5C 00 00 32 00 5B 54   \  C     \  2 [T
00000176   54 00 00 3A 01 43 03 00  01 00 1C 14 01 00 00 00   T  : C         
00000192   09 02 00 0A 57 00 00 00  00 09 03 00 06 01 00 09       W           
00000208   01 00 16 15 00 16 D8 75  04 9D 0A 3B 66 61 73 34         豼   ;fas4
00000224   20 63 72 75 6E 63 68 0A  3B 24 3B 41 37 2F 31 32    crunch ;$;A7/12
00000240   2F 32 30                                                                      /20

Your program compiles like this, you can see that it has been compiled into a function, not a table
red code is lambda