Lisp macros 3

Power

Macros are one of the things that make Lisp so extensible, because they let you transform arbitrary code into other arbitrary code. This is true for macros in languages like C too, but Common Lisp macros are different because they’re part of the language.

In C you have a layer of macros on top, written in a preprocessor macro language. The macro layer and the language layer are separate from each other, with the macro layer providing one one extra level of abstractive power (which, don’t get me wrong, is certainly useful).

In Common Lisp, you write macros in Common Lisp itself. You can then use those macros to write functions, and use those functions to write more macros. Instead of two stratified layers it’s a feedback loop of abstractive power.

— A Road to Common Lisp

— Steve Losh

.

.

2022.05.22 Sunday ACHK

PhD, 4

GlenTheMachine on Aug 28, 2018 | next [–]

I have a PhD in aerospace engineering. I loved grad school. Loved loved loved it. I wouldn’t give up the worst day I had in grad school for almost anything. And I love having the skills it taught me. I am a much better engineer and researcher than I could possibly have been had I taken almost any other route. I was given freedom in grad school that just would not have been present in most industry jobs. I was given a hardware project – a submersible robot – that I was completely in charge of on day 1. I had to teach myself machining, how to do electrical and electonic works, how to do embedded programming, how to tune a PID loop, how to work with other students, how to give a persuasive presentation, how to come up with my own ideas, how to convince other people that they were worth pursuing, how to quickly become an expert in a topic.

That being said, I am not under any illusions about the financial loss I experienced. I spent ten years making a pauper’s wage, when if I had chosen to go into industry I would have been a software engineer… in the Valley… in 1993.

I also was in a remarkable lab in grad school. It made top-ten lists of “coolest college lab”. And that wasn’t hype. The caliber of student and of professor was off the charts. And they were not only smart, the vast majority of them were good people. A lot of places aren’t like that. And as the article correctly said: a toxic graduate school environment is worse than most toxic work environments. In any practical sense, students don’t have HR protections. If you can’t get your advisor to write you a recommendation, getting into a different program is nearly impossible. You can be worked 100 hours a week. You can be blackballed for getting sick, for taking vacations, for taking maternity or paternity leave (even if it is – and it almost certainly will be – unpaid).

The key is to find an advisor who is doing good work and who is sane and moral. If you can find that you’re golden. If you can’t you may be completely screwed.

— What You Need to Know Before Considering a PhD

— Hacker News

.

.

2022.05.21 Saturday ACHK

十面埋伏

伏線驅動程式 1.6

這段改編自 2010 年 10 月 14 日的對話。

.

我發覺人生,即使愛情以外的範疇,主要的演變都是,身不由己式,依靠伏線來驅動。

.

要影響人生路向,你可以主動做的,就是「十面埋伏」——在多方面埋下伏線,從而提高長遠目標的命中率。

雖然,你不可以刻意去做,直接命中目標,但是,你可以刻意地,「不刻意地」去做;不知不覺地,間中命中目標。

這就是「伏線論」的精粹。

Excellence is an art won by training and habituation. We do not act rightly because we have virtue or excellence, but we rather have those because we have acted rightly. We are what we repeatedly do. Excellence, then, is not an act but a habit.

— Aristotle

— Me@2022-05-20 05:27:41 PM

.

.

2022.05.21 Saturday (c) All rights reserved by ACHK

Quick Calculation 3.5

A First Course in String Theory

.

Show that

\displaystyle{     \begin{aligned}           \text{vol}(B^d)   &= \frac{\pi^{\frac{d}{2}}}{\Gamma \left( 1 + \frac{d}{2} \right)}   \\     \end{aligned} }

~~~

.

Geometric proof

The relations \displaystyle{V_{n+1}(R)={\frac {R}{n+1}}A_{n}(R)} and \displaystyle{A_{n+1}(R)=(2\pi R)V_{n}(R)} and thus the volumes of n-balls and areas of n-spheres can also be derived geometrically. As noted above, because a ball of radius \displaystyle{R} is obtained from a unit ball \displaystyle{B_{n}} by rescaling all directions in \displaystyle{R} times, \displaystyle V_{n}(R) is proportional to \displaystyle{R^{n}}, which implies \displaystyle{{\frac {dV_{n}(R)}{dR}}={\frac {n}{R}}V_{n}(R)}.

Also, \displaystyle{A_{n-1}(R)={\frac {dV_{n}(R)}{dR}}} because a ball is a union of concentric spheres and increasing radius by \displaystyle{\epsilon} corresponds to a shell of thickness \displaystyle{\epsilon}. Thus, \displaystyle{V_{n}(R)={\frac {R}{n}}A_{n-1}(R)}; equivalently, \displaystyle{V_{n+1}(R)={\frac {R}{n+1}}A_{n}(R)}.

— Wikipedia on Volume of an n-ball

.

\displaystyle{  \begin{aligned}    V &= \int_0^R S dr \\    V(B^d) &= \int_0^R V(S^{d-1}) dR \\     &= \frac{2 \pi^{\frac{d}{2}}}{\Gamma(\frac{d}{2})} \int_0^R r^{d-1} dr \\     &= \frac{2 \pi^{\frac{d}{2}}}{\Gamma(\frac{d}{2})} \frac{1}{d} R^{d} \\     \end{aligned}}

— Me@2022-05-18 09:08:11 AM

.

.

2022.05.19 Thursday (c) All rights reserved by ACHK

Physically-indistinguishable mathematical states

… that’s not totally correct, because a macroscopic state, even in principle, cannot be a superposition of macroscopic eigenstates.

— Me@2012.12.31

.

A macrosopic state is an actual physical state.

A macrosopic state, by definition, cannot be a superposition of different macroscopic states. A superposition must be of different macroscopically-indistinguishable microscopic states.

In other words, a physical state, by definition, cannot be a superposition of different physically-distinguishable physical states. A superposition must be of different physically-indistinguishable mathematical states.

— Me@2022-05-17

.

.

2022.05.17 Tuesday (c) All rights reserved by ACHK

地獄篇 10.1.2

外在世界是地獄,心中宇宙是天堂;把知識和想像化成現實,就是把地獄天堂化。

— Me@2011.10.05

.

Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something.

— Richard Stallman

.

Name: Jimmy “Jimbo” Wales
Job: Founder, Wikipedia
Passion: Information for everyone
Turning Point: An operation that saved his daughter’s life taught him the need to stockpile rare knowledge such as her doctor’s

He wipes it off and begins haltingly.

“At the end of the procedure, I realized how precious the doctor’s knowledge was. It occurred to me that no one other than this doctor would ever know about this whole thing. There had to be a way.” And that is how Wikipedia came about.

— Daddy has Kira to Thank

— by Subroto Bagchi | Jun 5, 2009

.

.

2022.05.17 Tuesday ACHK

以右攻左

這段改編自 2021 年 12 月 13 日的對話。

.

The whole notion of being “left wing” or “right wing” is silly.

Almost no one initially agrees with the semi-random collection of policies associated with each wing.

They only support those policies after they join the left or right mind tribe.

— 12:27 AM · May 13, 2022

— Elon Musk

.

大概而言,美國左派的目標是「兼善天下」,美國右派的目標是「獨善其身」。

「兼善天下」(大乘)這目標固然是好,但就大到執行不到。

「獨善其身」(小乘)這目標則執行得到,但是就小到,其實沒有大用。如果是僅是「小乘」而已,人生沒有多大意義。試想想,假如,你可以「獨善其身」,生活富足,但是沒有愛人,沒有朋友,你會被迫,思考人生的意義。

「被迫思考人生意義」,可以簡稱「抑鬱」。

所以上次說,情況有如行路,要左右腳配合,才會暢順。如果你竟然,堅持只用左腳,或者只用右腳走路的話,你自然會感到,人生悲慘。

而今次多一個細節,就是「以右攻左」。成功「獨善其身」,才有能力「兼善天下」。「兼善天下」是目標,「獨善其身」是執行方法。

「兼善天下」是最終目標,永不達到,但可以不斷走近。 「獨善其身」則是起點。千里之行,始於足下。沒有起點,就沒有旅程。

— Me@2022.05.16 06:48:36 PM

.

.

2022.05.16 Monday (c) All rights reserved by ACHK

Watermelon

1990s, 19

.

(package-initialize)

(custom-set-variables
 '(cua-mode t nil (cua-base))
 '(custom-enabled-themes (quote (leuven))))
(custom-set-faces
 )

(set-register ?e '(file . "~/.emacs"))

(prefer-coding-system 'utf-8)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun backup-dot-emacs ()
  (interactive)

  (save-buffer)

  (setq backup-path (format "%s%s%s" 
              "/path_to_the_backup_folder/ubuntu_dot_emacs_" 
              (format-time-string "%Y_%m_%d_%I_%M_%S_%p")  
              ".el"))
  
  (write-file backup-path 'confirm)

  (setq original-cursor (point))

  (kill-buffer) 
  (find-file "~/.emacs")

  (goto-char original-cursor)
)

(global-set-key (kbd "C-`") 'backup-dot-emacs)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(set-register ?d '(file . "/path_to_the_blog_folder/dialogue59.txt"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun backup-blogging-tray ()
  (interactive)
  (save-buffer)

  (setq return-file-name (buffer-file-name))

  (setq backup-path (format "%s%s%s" 
                "/path_to_the_backup_folder/blogging_tray_" 
                (format-time-string "%Y_%m_%d_%I_%M_%S_%p")  
                ".txt"))

  (write-file backup-path 'confirm)

  (setq original-cursor (point))

  (kill-buffer) 

  (find-file return-file-name)

  (goto-char original-cursor)
 
)

(global-set-key (kbd "C-x C-a") 'backup-blogging-tray)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

— Me@2022.05.14 05:10:49 PM

.

.

2022.05.14 Saturday (c) All rights reserved by ACHK

Ex 1.25 Properties of Dt, 2

Structure and Interpretation of Classical Mechanics

.

Demonstrate that …

b. \displaystyle{D_t (c F) = c D_t F}

c. \displaystyle{D_t (F G) = F D_t G + (D_t F) G}

~~~

\displaystyle{  \begin{aligned}  &D_t (c F) \circ \Gamma[q] (t) \\  \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \partial_0 \left[c F(t, q, v, a, ...) \right]     + \partial_1 \left[c F(t, q, v, a, ...) \right] v(t)     + \partial_2 \left[c F(t, q, v, a, ...) \right] a(t) + ... \end{aligned}  }

\displaystyle{  \begin{aligned}      &= c \partial_0 F(t, q, v, a, ...) + c \partial_1 F(t, q, v, a, ...) v(t) + c \partial_2 F(t, q, v, a, ...) a(t) + ... \end{aligned}  }

\displaystyle{  \begin{aligned}      &= c \left[ \partial_0 F(t, q, v, a, ...) + \partial_1 F(t, q, v, a, ...) v(t) + \partial_2 F(t, q, v, a, ...) a(t) + ... \right] \end{aligned}  }

\displaystyle{  \begin{aligned}  &= c D_t F \circ \Gamma[q] (t) \\  \end{aligned}  }

.

\displaystyle{  \begin{aligned}  &D_t (FG) \circ \Gamma[q] (t) \\  \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \partial_0 \left[ F(t, q, v, a, ...) G(t, q, v, a, ...) \right] \\   &+ \partial_1 \left[ F(t, q, v, a, ...) G(t, q, v, a, ...) \right] v(t) \\   &+ \partial_2 \left[ F(t, q, v, a, ...) G(t, q, v, a, ...) \right] a(t) + ... \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \left[ \partial_0 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) + F(t, q, v, a, ...) \partial_0 G(t, q, v, a, ...) \\   &+ \left\{ \left[ \partial_1 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) + F(t, q, v, a, ...) \partial_1 G(t, q, v, a, ...) \right\} v(t) \\   &+ \left\{ \left[ \partial_2 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) + F(t, q, v, a, ...) \partial_2 G(t, q, v, a, ...) \right\} a(t) + ... \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &=    \left[ \partial_0 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) \\    &+ \left[ \partial_1 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) v(t) \\   &+ \left[ \partial_2 F(t, q, v, a, ...) \right] G(t, q, v, a, ...) a(t) + ... \\ \\    &+ F(t, q, v, a, ...) \partial_0 G(t, q, v, a, ...) \\   &+ F(t, q, v, a, ...) \partial_1 G(t, q, v, a, ...) v(t) \\   &+ F(t, q, v, a, ...) \partial_2 G(t, q, v, a, ...) a(t) + ... \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &=    \left[ \partial_0 F(t, q, v, a, ...)   + \partial_1 F(t, q, v, a, ...) v(t)    + \partial_2 F(t, q, v, a, ...) a(t) + ... \right] G(t, q, v, a, ...) \\     &+ F(t, q, v, a, ...) \left[ \partial_0 G(t, q, v, a, ...) + \partial_1 G(t, q, v, a, ...) v(t) + \partial_2 G(t, q, v, a, ...) a(t) + ... \right] \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \left\{  D_t F \circ \Gamma[q] (t) \right\} G(t, q, v, a, ...) + F(t, q, v, a, ...) D_t G \circ \Gamma[q] (t) \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \left\{  D_t F \circ \Gamma[q] (t) \right\} G \circ \Gamma[q] (t) + F \circ \Gamma[q] (t) D_t G \circ \Gamma[q] (t) \\     \end{aligned}  }

The meaning of \displaystyle{\delta_\eta (fg)[q]} is

\displaystyle{\delta_\eta (f[q]g[q])}

\displaystyle{  \begin{aligned}  &D_t (FG) \circ \Gamma[q] (t) \\  \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \left\{  D_t F \circ \Gamma[q] (t) \right\} G \circ \Gamma[q] (t) + F \circ \Gamma[q] (t) D_t G \circ \Gamma[q] (t) \\     \end{aligned}  }

\displaystyle{  \begin{aligned}      &= \left[  (D_t F) G + F D_t G \right] \circ \Gamma[q] (t) \\     \end{aligned}  }

.

\displaystyle{  \begin{aligned}      D_t (FG) \circ \Gamma[q] (t) &= \left[  (D_t F) G + F D_t G \right] \circ \Gamma[q] (t) \\ \\    D_t (FG) &= (D_t F) G + F D_t G \\     \end{aligned}  }

— Me@2022.05.12 07:02:30 PM

.

.

2022.05.14 Saturday (c) All rights reserved by ACHK

難得有情人

形上情人 2.2 | 冰心鎖 2.2 | 超時空接觸 3.4

.

認為愛情是要找到「條件最好的那一位」的人,不會從一而終,因為永遠可能有,亦必定有,條件更好的另一位。

— Me@2022-02-08 11:50:35 PM

你不是找「條件最好」的人,做你的另一半。你是要找「條件最適合你」的人。留意,「她最適合你」並不保證,你最適合她。所以,準確一點的講法是:

「你是要找『條件最適合你』的人,如果你剛巧又,最適合她的話。」

.

你不是找「條件最好」的人,做你的另一半。你是要找「與感情至深」之人。

留意,「你對她有情」並不保證,她對你有情。「她是與你感情至深的人」並不代表,你是與她感情至深之人。「她是你的蘇眉」並不意味,你也是她的蘇眉。

Today I found my soulmate; she didn’t.

所以,準確一點的講法是:

「你是要找『與感情最深』之人,如果你剛巧也是,『與她感情最深』之人。」

.

只有一見鍾愛,沒有一見鍾情。

愛是感覺,只需零時無知、一時誤會、兩時消失。

一見可以生愛,日久才能生情。

情需要時間,情需要空間。情是「超時空接觸」。

.

愛可以替代;情不可以。

.

「情人」的重點在於情。

情者,情境也。

情人者,情境之人也。

愛人可以替代;情人不可以,因為情境不可以。

時常有愛人,難得有情人。

.

感情者,感受到相同之情境也。

情人者,與爾有共同經歷之人也。

.

你要找的,不是所謂「外在條件最好」的人,而是「感情至深」之人。

你要找的,不是「條件人」,亦不是「有緣人」,而是「有情人」。

— Me@2022.05.11 07:07:43 PM

.

.

2022.05.12 Thursday (c) All rights reserved by ACHK

伏線驅動程式 1.5

冰心鎖 2 | 形上情人 2

這段改編自 2010 年 10 月 14 日的對話。

.

我發覺人生,即使愛情以外的範疇,主要的演變都是,身不由己式,依靠伏線來驅動。

.

既然那樣,你就有心理準備,你的人生目標夢想,例如愛情,最終還有一個可能性是,伏來伏去伏不到。「伏線」的意思正正包括,不受你控制,有時伏到有時伏不到。

即使伏得到的話,伏到什麼,你也不會事前知道。

例如,你可能覺得,因為你的條件好,所以最終會找到,你的另一半。但是,雖然受條件影響,但愛情不是純粹的「條件運算」。正如友情一樣,很多時,和你最要好的朋友,並不是所謂「條件最好」的朋友。

認為愛情是要找到「條件最好的那一位」的人,不會從一而終,因為永遠可能有,亦必定有,條件更好的另一位。

— Me@2022-02-08 11:50:35 PM

你不是找「條件最好」的人,做你的另一半。你是要找「條件最適合」的人。留意,「她最適合你」並不保證,你最適合她。所以,準確一點的講法是:

「你是要找『條件最適合』的人,如果你剛巧又最適合她的話。」

.

我在自己的筆記中寫過,「Find a Metaphysical Lover」(尋找形上的情人)。後來,我發現在李生的著作中,也有類似的想法。他著作中其中一句的大概是,「愛情應該始於外在條件,成於形上。」

— Me@2014.09.07

.

即使假設,愛情是條件運算——找條件最好的那一位,你亦只能透過自我提升,工作上進,提高「找到另一半」的機會率。但是,那個機會率,永不會是百分之一百。

首先,你沒法保證,你是你心上人的可能對象中,條件最好的一個。

另外,即使是,可能正正是因為你條件太好,沒有人覺得,可以匹配到你。又或者,正正是因為你條件太好,有心人也以為,你已名花有主,不感示好。

— Me@2022.05.10 05:23:26 PM

.

.

2022.05.11 Wednesday (c) All rights reserved by ACHK

Junkions

output = system.exec_command("date +%Y.%m.%d")
output += " "
output += system.exec_command("date +%I:%M:%S")
output += " "
output += system.exec_command("date +%p")

clipboard.fill_clipboard(output.upper())
keyboard.send_keys("<ctrl>+v")

output = system.exec_command("date +%Y.%m.%d")
output += " "
output += system.exec_command("date +%A")
output += " (c) All rights reserved by "

clipboard.fill_clipboard(output)
keyboard.send_keys("<ctrl>+v")

.

output = system.exec_command("date +_%Y_%m_%d_")
output += system.exec_command("date +_%H_%M_%S_%p")

clipboard.fill_clipboard(output.upper())
keyboard.send_keys("<ctrl>+v")

— Me@2022.05.07 11:27:28 AM

.

.

2022.05.07 Saturday (c) All rights reserved by ACHK

The Lisp debugger

oo101 7 days ago [-]

There are a few ways in which the shared objects method you suggest does not match the full power of Lisp debugging.

First of all, when a C program crashes, it just crashes. There is no REPL. There is only a core dump. So any live-debugging you plan to do is after the fact. After you have seen a crash, you would now begin to prepare for the next crash by launching your process via GDB or restarting your process and attaching a GDB to it. Whether a similar crash would occur again or not or when it would occur again depends on the nature of the bug. Now contrast this with Lisp debugging when your program crashes, it stops there and offers you an REPL to interact with the program right then. There is no need to wait for the next crash.

Secondly, when you debug with GDB, you would be dealing with syntaxes: The syntax of C that we are so familiar with. The GDB syntax to investigate the problem that we may be less familiar with. When the Lisp debugger offers the REPL to you, you are working with Lisp again. Your compiler, debugger, program, etc. all are part of the same unified environment where you just execute Lisp code to debug your issue.

Finally, putting your code in shared objects and reloading them requires you to go through the complete write-build-test-debug cycle. And then what do you do if your shared object itself crashes? With Lisp you skip the write-build-test part when all you want to do is debug an error. You jump straight to the debug part of the cycle and begin investigating the runtime state. And it works the same in a uniform manner whether your main program crashes or a dependency crashes.

— A Road to Common Lisp

— Hacker News

.

.

2022.05.05 Thursday ACHK

數學教育 7.5.1

Genius 4.2.1 | A Fraction of Algebra, 2.1

這段改編自 2010 年 4 月 24 日的對話。

.

另外,他提的另一個,有關學習數學的要點是,即使假設你在大學中,學到的數學,在日常生活中沒有用,單單是為獲取,那些嶄新的元素概念本身,就已經能夠令你有超能力;令你有一些,常人沒有的思考工具、比喻語言。

.

(安:但是,這個講法可能有一個問題。

雖然,你剛才列舉了數個例子,來示範如何將高深數學,間接應用到人生處世,但是,一般人未必有那種能力。所以我想問,你又是如何去跨過這個難關呢?)

.

什麼難關?

.

(安:去翻譯那些抽象數學概念,到其他範疇,或者日常生活。)

.

那不是「難關」。你的意思是,一般人也沒有那個能力,而我有。所以,那是超能力;我當年一定是,用了一些秘技,才獲取之。

天才之道,點滴累積。其實並沒有所謂的「秘技」。只要一步一步地,學習數學,就自然建構出,一個相對接近完整的數學思考體系,生成「翻譯抽象數學概念到其他範疇」等能力。

所以,我猜想你的疑問是,其實我所講的「點滴累積」,或者「一步一步地」,雖然理想上是,基本的要求,但是現實中是,大部人也做不到。那就代表著,大部人可能也會遇到,一個共通的「難關」。那個「難關」究竟是什麼?我又是如何克服它,而做到「一步一步地」「點滴累積」的呢?

.

你問題的最簡化版本是:「如何學習數學,開創人生?」

有起碼以下三個先決條件:

1. 對數學(及其他學問人生),有極大興趣;

2. 遇到合理的老師和書籍:

重點是,數學概念或運算上的主要步驟,亳無違漏。支節可免,但主旨必須。細節可以無師自通,大節必靠前人指點。平地自己行,斜地靠梯級。平地可跳步,梯不可跳級。

3. 極超大量的背誦和練習:

數學是理科,所以其背誦方法,不是「死背」零碎隨機的資料,而是「生背」息息相關的訊息。融匯貫通地背誦的唯一方法是,極超大量的操練。

.

你所講的「難關」,就是以上的第二點。老師有分好老師和差老師。大部分也是差老師。而差老師再分兩類:不懂數學和不懂教學。

— Me@2022.05.02 11:48 PM

.

.

2022.05.03 Tuesday (c) All rights reserved by ACHK