TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: baitang36 on March 25, 2020, 01:03:30 AM
-
First look at the source code:
(defun aa nil
(setq a 88)
(set 'a 88)
(princ (read "bb"))
(set (read "bb") 88)
)
Through experiments, (setq a 88) and (set 'a 88) are completely equivalent. Setq is set quote.
After compiling to fas, the code looks like this:
14 00 00 00 00 Instruction 20, the function starts
32 58 06 05 00 (setq a 88)
09 05 00 32 58 35 02 04 00 03 0A (set 'a 88)
09 03 00 35 01 02 00 03 35 01 01 00 03 0A (princ (read "bb"))
09 03 00 35 01 02 00 03 32 58 35 02 04 00 03 (set (read "bb") 88)
16 Instruction 22, the function ends
String used:
05 / A
04 / SET
03 / "bb"
02 / READ
01 / PRINC
It can be seen that (setq a 88) was compiled into an instruction, and the function was completed directly with instruction no. 6
(set 'a 88) is compiled to call function SET, which takes two arguments, one with the symbol a (05) and the other with 88
In conclusion, setq does not need to call functions, it is faster, and the compiled code is shorter and more concise.
-
Through experiments, (setq a 88) and (set 'a 88) are completely equivalent. Setq is set quote.
hi nice research but..
set only accepts single sym+expr whereas setq (set quote) accepts multiple symbols & expressions
(setq a
1 b
"2" ) ; (mapcar 'set '(a b) '(1 "2"))
(set a
1 b
"2" ) ; too many arguments (set 'a
"1" 'b
"2" ) ; too many arguments
-
(mapcar 'set '(x y z) '(1.0 2.0 3.0))
-
Useful if one wants to swap var values in one go:
(setq a 1 b 2)
!a >> 1
!b >> 2
(mapcar 'set '(a b) (list b a))
!a >> 2
!b >> 1
-
Useful if one wants to swap var values in one go:
(setq a 1 b 2)
!a >> 1
!b >> 2
(mapcar 'set '(a b) (list b a))
!a >> 2
!b >> 1
8)
-
:)