Lee Mac 发表于 2022-7-6 10:43:38

 
绝对不过分-考虑一下如何在不使用位操作的情况下执行相同的任务(即打开额外的OSNAP,同时保留已打开的OSNAP)。。。
 
此外,在使用这些工具时,您可以对值进行更多的控制(例如,请参阅我创建切换的示例),并且使用设计用于操作这些值的函数来控制位编码值是有意义的。
 

The Buzzard 发表于 2022-7-6 10:47:16

 
我看到了这些很好的例子,我不会对此进行争辩,但在莱森的上述代码中,他使用的方式与您的切换示例不同。

Lee Mac 发表于 2022-7-6 10:49:04

 
谢谢-
 
但是我解释Laison代码的方式是,他希望启用这些快照(1 2 4 32 128 8192)除了当前的OSnap设置之外,我很好奇除了logior之外还有什么更好的方法来实现这一点。
 
旁白——我并不是说莱森的代码在整体上是正确的,但如果我对其目的的理解是正确的,我想找到一种更好的方法来编写OSnap部分。
 
编辑:快速编写了这个函数,我希望它执行相同的操作,但没有使用位包含或函数(例如logior)-只是为了进行比较。
 

(defun _SnapSetting ( n / _GetBits os )

;; This is not a practical example in
;; any way, as the easiest way to accomplish
;; this task would be to IOR the existing
;; snap value with that which is desired -
;; however, I am trying to demonstrate a possible
;; method to accomplish the same operation *without*
;; the use of bit-wise inclusive OR function.

(defun _GetBits ( x )

   ;; This function returns a list of all the bits
   ;; that make up a bit coded value 'x'.

   (defun _GetBits ( x i )
   (if (< 0 x)
       (if (= i (logand x i))
         (cons i (_GetBits (- x i) (lsh i 1)))
         (_GetBits x (lsh i 1))
       )
   )
   )

   (_GetBits x 1)
)

;; Split n into its constituent bits and get the current
;; OSMODE value for comparison.

(setq n (_GetBits n) os (getvar 'OSMODE))

;; Now we do the operation that a bit-wise inclusive
;; OR would do in one step: If the bits constituting
;; our value 'n' do not appear in the current OSMODE
;; value, then add them to it.

(foreach bit n
   (if (zerop (logand bit os))
   (setq os (+ os bit))
   )
)

(setvar 'OSMODE os)
)

The Buzzard 发表于 2022-7-6 10:52:40

我正在看你关于osmode设置和使用logior的帖子。我的目标是只使用这些设置。
 
显然,如果我是正确的,我必须关闭osnaps,而不是设置osmode设置。此外,当我设置osmode设置时,如果我要使用超过1,我应该将它们相加。
 
这是我从帖子里得到的吗?

Lee Mac 发表于 2022-7-6 10:56:16

 
从您最初的帖子判断,您当前使用的代码是在已经设置的OSMODE设置之外设置这些OSMODE设置。
 
要仅设置这些设置,您可以存储当前设置,然后用所需的设置覆盖它,即:
 
然后在代码末尾(以及错误处理程序中)恢复旧设置:
 

(setq os (getvar 'OSMODE))

(setvar 'OSMODE (+ 1 2 4 32 128 8192))
 
另一方面,(boole 5 os(+1 2 4 32 128 8192))将给出相同的结果。

Lee Mac 发表于 2022-7-6 11:00:21

我想我毕竟没有偏离目标。
 
(setvar 'OSMODE os)
 

(setq os (getvar "OSMODE")) ;Save User Object Snaps

 
9

laisonalbarado 发表于 2022-7-6 11:01:58

无论如何,我很喜欢这个帖子中的偏差,我希望我之前的帖子不会被浪费。

Lee Mac 发表于 2022-7-6 11:07:45

The Buzzard 发表于 2022-7-6 11:09:33

I guess I was not off the mark afterall.
 

(setq os (getvar "OSMODE")) ;Save User Object Snaps
 

(setvar "OSMODE" Your new setting here) ; Add-on to your orginal object snap setting
 

(setvar "OSMODE" os) ;Restore your Saved User Object Snaps

Lee Mac 发表于 2022-7-6 11:12:27

In any case, I have enjoyed the deviation in this thread, and I hope my earlier posts aren't wasted.
页: 1 [2]
查看完整版本: Lisp文件需要一些帮助。