Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard other variables from the effect of setf #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aki2o
Copy link
Collaborator

@aki2o aki2o commented Dec 21, 2014

alistの内容をsetfで変更すると、引数で渡した側の変数の内容も変更されてしまいます。
例えば、以下のようになってしまうので、
現状だと、wmvc:build-bufferに渡す変数をcopy-alistなどで守る必要が出てきます。

(let* ((attrs '((hoge . "aaaa")
                (fuga . "bbbb")))
       (ctx (make-wmvc:context :attributes attrs))
       testv)
  (setq testv attrs)
  (wmvc:context-attr-set ctx 'fuga "cccc")
  attrs                          ; => ((hoge . "aaaa") (fuga . "cccc"))
  testv                          ; => ((hoge . "aaaa") (fuga . "cccc"))
  (wmvc:context-attributes ctx)) ; => ((hoge . "aaaa") (fuga . "cccc"))

仮に、この挙動を把握して実装されていたとしても、
(elispに対しての理解が浅い)ユーザ側に対して優しくない設計だと思うので、
setfによる変更が外部に波及しないようにしました。

wmvc:context-attr-setで、copy-alistを使っていないのは、その方が
論理的に処理に沿っているし、メモリ消費的にも良いのではと思ったので。

@kiwanami
Copy link
Owner

すみません。こっちを #3 より先に見るべきでした。

意図としては#3に書いたとおりで、OOP的メンタルモデルでは、setter系はインスタンスの中身を変えてしまうほうがいいかなと思ってました。

ちょっと考えてみます。(といいつつ時間がたってしまうことが多いので、1日ぐらいで)

@aki2o
Copy link
Collaborator Author

aki2o commented Dec 22, 2014

こちらこそすみません。。 #3 に書きました。

@kiwanami
Copy link
Owner

モデルをイミュータブルにするかについて、ちょっと考えてみましたが、まだ適用例が少なくて判断できない気がしましたので、もう少し様子見したいと思っています。
変更前のデータをどこに持たせるかとか、もう少しユースケースを集めてみたいです。
@aki2o さんの作られているものもちょっと読んでみたいと思います。

@aki2o
Copy link
Collaborator Author

aki2o commented Dec 23, 2014

了解です。とりあえずこのままにしておきます。
僕の利用方法としては、ユーザの変更内容のdiffを取るために、
wmvc:build-bufferattributesオプションに初期モデルを突っ込んでおいて、
submit時とかに比較してます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants