0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Emacs Lisp 超初心者がコマンドを作ってみる 〜 代入の評価 〜

Posted at

C言語では代入するとその右辺値を返します。

int a;
int b;
a=1;
b=1;

int a;
int b;
b=(a=1);

と書くことができます。 (もっと言えば代入の場合は右から順に評価されるのでどうせ書くなら b=a=1; )

Emacs Lisp の setq も同様に代入結果を返します。

(setq a 1)
(setq b 1)

(setq b (setq a 1))

と書くことができます、まぁ、まぁわかりやすさのためにこういうのははそれぞれ書きますが、応用例

(setq beg-A (point-min))
(setq end-A (point-max))
(goto-char beg-A)
(push-mark end-A t t)

(goto-char (setq beg-A (point-min)))
(push-mark (setq end-A (point-max)) t t)

としてみました。

なので、 条件式の中に書く事もできます。
C言語だと

while ((c=getchar())!=EOF)

っていうフレーズが有名(K&Rとか)

Emacs Lisp だと、例えば builtin の calcalg2.el より

/usr/share/emacs/29.3/lisp/calc/calcalg2.el
(while (>= (setq num (1- num)) 0)
  (setq expr (list func expr var)))

今回はここまで

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?