I've written a blog article about the layout of closures in SBCL. Not so sure about the correctness of the content.
Related comments are always welcome!!
2011-04-08
2011-04-07
on Lisp being the string representation of AST
Lisp uses the string representation of AST as its syntax.
The good thing derived from this is: you have the whole AST available for massage, to transform it to whatever form. That's exactly what a control statement does.
But in languages like C, you cannot easily have the AST ready for the exact corresponding code you're writing now, which means it's hard, though not impossible , to transform or operate the AST using the code you are writing now. One might argue he does not need new control statement, but the ability to add new control statement matters for expressiveness and ease of generating DSLs.
The good thing derived from this is: you have the whole AST available for massage, to transform it to whatever form. That's exactly what a control statement does.
But in languages like C, you cannot easily have the AST ready for the exact corresponding code you're writing now, which means it's hard, though not impossible , to transform or operate the AST using the code you are writing now. One might argue he does not need new control statement, but the ability to add new control statement matters for expressiveness and ease of generating DSLs.
My thinking about Lisp's Macros
Macro is just let over lambda with prameterable bindings or body. Both being parameterable makes a macro-writing macro template: once given one, a macro is generated which expects another part. Again, this is just lamda with two parameters, two variables.
Macro and lambda differ in that the evaluation system treats them differently: macro has access to raw lambda list, unevaluated.
Macro is just lambda that has the chance given by the evaluation system to manipulate the raw lambda list and writes out new lists to replace itself. The unique and unified syntax of lisp renders the difficulty of writing them to be near to zero.
Macro and lambda differ in that the evaluation system treats them differently: macro has access to raw lambda list, unevaluated.
Macro is just lambda that has the chance given by the evaluation system to manipulate the raw lambda list and writes out new lists to replace itself. The unique and unified syntax of lisp renders the difficulty of writing them to be near to zero.
2010-10-26
remove the ".exe" suffix of commands in bash on Cygwin when completing
Because I think the extra ".exe" takes too much space when multiple pipelines are used in a one-liner task.
Basically it's a small change to the file lib/readline/complete.c in bash's source code.
Find the definition of the function "make_quoted_replacement" and change the line
to
Then recompile it to deploy.
Basically it's a small change to the file lib/readline/complete.c in bash's source code.
Find the definition of the function "make_quoted_replacement" and change the line
replacement = match;
to
if(strstr(match, ".exe") != NULL) {
replacement = (char *) xmalloc(strlen(match) - 4 + 1);
memset(replacement, 0, strlen(match) - 4 + 1);
strncpy(replacement, match, strlen(match) -4);
} else {
replacement = match;
}
Then recompile it to deploy.
2010-03-30
change the case sensitivity of pathname completion in bash
I don't like bash being case-sensitive when cd to different directories because when there are upper-case letters in directory names usually either the capslock or the shift key has to be pressed which slows speed of switching paths. Thus in all my boxes where bash exists(linux machines, cygwin on windows boxes & my macbook running Snow Leopard) I have set up the ~/.inputrc file to contain this line to turn off the case-sensitivity:
But there were cases that I'm using somebody else's bash shell instead of my own, which does not disable that case-sensitivity and would cause inconvenience for me(yes, to some extent). And today an idea occurred to me that bash may very likely support some kind of volatile switching this feature on and off. So I tried `man bash` and found a rather ugly solution:
1. create a tmp file, let's say "/tmp/inputrc" and type that line above in it.
2. in this bash shell, set the $iNPUTRC env variable by type in the command `export INPUTRC=/tmp/inputrc`
3. also in this bash shell, press the keybinding C-x C-r(which runs the readline command "re-read-init-file") to load the setting just typed in.
and now this bash shell is enabled with case-insensitivy.
It's rather a tedious and ugly solution.
PS: I tried to run this command
in the bash shell as described in this cyberciti page. But it proved no effect at all.
set completion-ignore-case on
But there were cases that I'm using somebody else's bash shell instead of my own, which does not disable that case-sensitivity and would cause inconvenience for me(yes, to some extent). And today an idea occurred to me that bash may very likely support some kind of volatile switching this feature on and off. So I tried `man bash` and found a rather ugly solution:
1. create a tmp file, let's say "/tmp/inputrc" and type that line above in it.
2. in this bash shell, set the $iNPUTRC env variable by type in the command `export INPUTRC=/tmp/inputrc`
3. also in this bash shell, press the keybinding C-x C-r(which runs the readline command "re-read-init-file") to load the setting just typed in.
and now this bash shell is enabled with case-insensitivy.
It's rather a tedious and ugly solution.
PS: I tried to run this command
set completion-ignore-case on
in the bash shell as described in this cyberciti page. But it proved no effect at all.
2009-10-23
first try on cl-cont's continuation
(defun pn (n)
(cl-cont:with-call/cc
(cond ((eq 0 n) (format t "~A "'DONE))
(t (cl-cont:call/cc (lambda (k)
(funcall k (pn (- n 1)))
(format t "~A " n)))))))
2009-09-19
fix the M-. behavior in iTerm under Snow Leopard
I found that one of my favorite keyboard shortcuts refused to work, after my MB has been upgraded to the Snow Leopard. That striking keybinding is "M-.", which used to bring the last argument of the most recently committed bash command to the cursor's very position on bash's input line(thanks to libreadline, which provides this feature and other which are similar to those keybinding in Emacs[God's editor, yes]), now will introduce a "≥" symbol instead in iTerm.
iTerm is more user-friendly than the Terminal.app which is originally contained in Leopard and Snow Leopard. For example I can use Command+1, Command+2 to switch to different tabs in iTerm(and I know that GNU Screen can sometimes make the tabs useless and unnecessary, but consider that what if I'm connected to several remote hosts via ssh?), which may not be possible(or at least not easy to do so) in Terminal.app. And that's why I feel that life sucks when forced to use the Terminal.
I had thought that it's because the iTerm is too old to work with SL, because that version was released in April, 2009 and it indeed worked smoothly in Leopard. So I decided to wait for a newer version of iTerm. And today when the newer version comes. I can't help to upgrade it, with full expectation that it will solve that problem(M-. does not work as it did). But, I was made disappointed because, it DOES NOT work like that!
OK. Maybe I have to turn to some other dirty way. I first tried to use the mapping function in iTerm to deceive bash that whenever the M-. is pressed it should be taken as the right keycode to bring up the last argument of the last bash command. but I failed because, the "xev" program reported the same keycodes in both iTerm and Terminal(remember that M-. works as _I_ expected in Terminal).
Then, I remembered that I had once made some customized keybindings in bash via the ~/.inputrc file under Linux, which controls mappings between keyboard inputs and what bash see. With even no expectation that it will work, I put this line:
"≥": yank-last-arg
into my ~/.inputrc.
After iTerm's relaunch, M-. succeeds to just emit the last argument... which I have longed for about 4 weeks.
标签:
bash,
keyboard,
keymap,
last argument,
osx,
snow leopard
2009-07-19
[Small Pieces In Emacs] Copy the name or path of the current buffer's file, if any.
(defun zs-copy-current-file-name-to-system-clipboard (&optional full-path-p)
"copy, if the current buffer accesses a file, the name or file path(given a
prefix argument) to the system clipboard(if under X) and append to the killing
ring."
(interactive "P")
(if (buffer-file-name)
(if full-path-p
;; (x-select-text (buffer-file-name))
(kill-new (buffer-file-name))
;; (x-select-text (file-name-nondirectory (buffer-file-name)))
(kill-new (file-name-nondirectory (buffer-file-name)))
)))
2009-03-30
Strange svn behavior when specifying username
It seems that the --username option is totally ignored by svn when you later try to update or commit (or any operations that have to be performed interactively with the svn server) if the svn+ssh protocol was used to check out the code initially _AND_ at that same time you did not specify a username directly in the svn+ssh url(which is often later provided when the server asks for it). According to this mailing list thread this problem only happens to the svn+sshl combination.
Then, how this problem be by-passed? It's easy with the help of svn's "switch --relocate" facility. Let's say the original svn+ssh url is "svn+ssh://svn.example.com/path/to/repos"(which you can find in each .svn directory's entries file), then the username can be add to the url after you've changed the current directory to the local svn copy's root directory by:
That's a simple one-liner command. Do remember to replace the "username" with your real username used and don't forget the final dot "." which means the current directory.
Then, how this problem be by-passed? It's easy with the help of svn's "switch --relocate" facility. Let's say the original svn+ssh url is "svn+ssh://svn.example.com/path/to/repos"(which you can find in each .svn directory's entries file), then the username can be add to the url after you've changed the current directory to the local svn copy's root directory by:
svn switch --relocate svn+ssh://svn.example.com/path/to/repos svn+ssh://username@svn.example.com/path/to/repos .
That's a simple one-liner command. Do remember to replace the "username" with your real username used and don't forget the final dot "." which means the current directory.
2009-01-16
Meaning of "Functional" as in "Functional Programming"
What functional programming is confused me for rather a long time. SICP says(as I was reading it this morning after getting up):
So long as we do not use assignments, two evaluations of the same procedure with the same arguments will produce the same result, so that procedures can be viewed as computing mathematical functions. Programming without any use of assignments, as we did throughout the first two chapters of this book, is accordingly known as functional programming.
That is, the "functional" as in "functional programming" means the style and properties which functions in mathematics possess, namely, "mathematically functional"(instead of functions or methods in programming languages).
Now, I finally fully comprehend the meaning of the definition of functional programming on wikipedia, which I didn't quite understand formerly:
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.
And it also says in Wikipedia that:
The characteristic property of a function in the most abstract sense is that it relates exactly one output to each of its admissible inputsPlease forgive my ignorance!
2008-12-26
a coarse classification of naming conventions(patterns) within the Emacs ecosystem
syntactic : char, word, line, sentence, paragraph, region, page,
sexp, list, defun,
emacs-specific : register, rect, buffer, mode, frame, window,
font : face, font
filesystem : file, dir,
location and direction : beginning, end, forward, backward, next, previous, up, down,
action : search, goto, kill, delete, mark, insert, yank, fill, indent, find, view, describe, change, set,
misc : case, what, default.
2008-12-16
a native simple wc in Emacs Lisp
I googled "count words emacs" and read several articles, "Counting words in Emacs" and "Emacs Tip: Word counting with a regular expression". The first uses a loop and a regular expression to count only words in a region, and the latter uses the emacs built-in function "how-many" to count words in the whole current buffer. So I combined them to the following `wc` function which count in the whold buffer when no region is active and in the region otherwise.
(defun wc ()
"a simple mimic of the linux command `wc`"
(interactive)
(message "Word count: %s"
(how-many "\\w+"
(or (and (region-active-p) (region-beginning)) (point-min))
(or (and (region-active-p) (region-end)) (point-max)))))
2008-12-02
Beautiful Code真是被BC group翻译得糟蹋了
按照本人一贯的态度,是不看国内人翻译的英文计算机类书籍的。因为这帮人粗制滥造得多,而且技艺不精,多是会在windows xp下用鼠标左点右点就觉得自己东计算机科学了。但是碰巧今年早些时候,china pub说有beautiful code的预定,当时也没多想,就订了。没想到到手竟然是中文版,而且是一个叫BC group的团队翻译的。
拿到书很久,因为先入为主的想法,所以没有翻过。今晚因为眼睛不舒服,所以不用电脑,改为翻看这翻译的中文版的第一章,是关于正则表达式的。看到把notation翻译成“记法(notation)”,翻译者还特意在“记法“后加了括号说明原版中的用词,不知道是怕阅读者看不懂”记法“呢,还是自己翻译得没底。我觉得这个翻译为”记法“比较脑残,翻译成“表示法”会更容易明白些,也更接近正则表达式的真正精神。
然后反倒第一章的第二页(全书第10页),赫然发现第四个非空白行上把grep写成了grpe,惨不忍睹,不知道是以什么样的态度来审阅书稿,显然是相当粗糙。
所以我觉得BC group应该是“白痴小组”的意思。真是心疼那买书的66块钱。
拿到书很久,因为先入为主的想法,所以没有翻过。今晚因为眼睛不舒服,所以不用电脑,改为翻看这翻译的中文版的第一章,是关于正则表达式的。看到把notation翻译成“记法(notation)”,翻译者还特意在“记法“后加了括号说明原版中的用词,不知道是怕阅读者看不懂”记法“呢,还是自己翻译得没底。我觉得这个翻译为”记法“比较脑残,翻译成“表示法”会更容易明白些,也更接近正则表达式的真正精神。
然后反倒第一章的第二页(全书第10页),赫然发现第四个非空白行上把grep写成了grpe,惨不忍睹,不知道是以什么样的态度来审阅书稿,显然是相当粗糙。
所以我觉得BC group应该是“白痴小组”的意思。真是心疼那买书的66块钱。
2008-11-07
A great alternative for OpenOffice, MS Office, the "永中Office"
永中Office, which is produced by this company called "Evermore Software"(www.evermoresw.com.cn) located in Wuxi, China, has announced its personal edition as free (as in free lunch), both for the Linux and the Windows platform, which you can download from here. Java is used to produce this software.
永中Office has a similar look as MS office and is almost 100% compitable with most of M$'s office document formats(In fact, Word, Excel and PPT). But it *CAN NOT* parse OpenOffice's ODF, which is sad news for the FOSS community.
This free(as in free lunch, again) personal edition offers functions to create word processing, electric table and slides documents.
The reason I switched from OpenOffice just now to 永中Office is that the later have a much more faster loading and processing speed than the former, although 永中Office is written using the same language as OpenOffice. Speed means time, which dominates.
PS: this software can't show its window and dialogs normally when compiz is running. But it can be fixed by editing the startup script which is usually "/usr/bin/eio" by changing it to:
Note the line
which is newly added to choose the correct AWT TOOLKIT when compiz is running, thanks to the post at here.
永中Office has a similar look as MS office and is almost 100% compitable with most of M$'s office document formats(In fact, Word, Excel and PPT). But it *CAN NOT* parse OpenOffice's ODF, which is sad news for the FOSS community.
This free(as in free lunch, again) personal edition offers functions to create word processing, electric table and slides documents.
The reason I switched from OpenOffice just now to 永中Office is that the later have a much more faster loading and processing speed than the former, although 永中Office is written using the same language as OpenOffice. Speed means time, which dominates.
PS: this software can't show its window and dialogs normally when compiz is running. But it can be fixed by editing the startup script which is usually "/usr/bin/eio" by changing it to:
#!/bin/bash
if test -n "$(grep "Ubuntu" /proc/version)"; then
export AWT_TOOLKIT=MToolkit
else
export AWT_TOOLKIT=XToolkit
fi
pidof compiz >/dev/null&& export AWT_TOOLKIT=MToolkit
exec 4<&0 0<&4 $line1/EIOffice.bin ${@:+"$@"} 2>/dev/null
Note the line
"pidof compiz >/dev/null&& export AWT_TOOLKIT=MToolkit"
which is newly added to choose the correct AWT TOOLKIT when compiz is running, thanks to the post at here.
2008-10-13
A great tutorial to Emacs editor
That tutorial is available at http://www.gnu.org/software/emacs/tour/ .
I learned some new features, such as `wdired-change-to-wdired-mode' which enables one to change filenames(use C-x C-s or C-c C-c to save, or C-c C-k to abord changes). Also, that tutorial reminds me how to move in units of sentences(`M-a', `M-e', still not used to the former, though); how to stop isearch at the place found(namely, leaving point there) by press the
BTW, I have bound `C-2' to call the command `set-mark-command`, so it unifies the set mark action in both the X system and the console environment: I just have to type `C-2', though in X it's interpreted as Ctrl+2 but in console environment as Ctrl+@.
I learned some new features, such as `wdired-change-to-wdired-mode' which enables one to change filenames(use C-x C-s or C-c C-c to save, or C-c C-k to abord changes). Also, that tutorial reminds me how to move in units of sentences(`M-a', `M-e', still not used to the former, though); how to stop isearch at the place found(namely, leaving point there) by press the
key.
BTW, I have bound `C-2' to call the command `set-mark-command`, so it unifies the set mark action in both the X system and the console environment: I just have to type `C-2', though in X it's interpreted as Ctrl+2 but in console environment as Ctrl+@.
2008-10-06
using thunderbird's lightning: difference between events and tasks
Copied verbatim from mozilla's FAQ:
That is, an event is scheduled at a specific time and a task spans a period of time
The following definitions are from the calendar help glossary:
event - A calendar entry that represents something that will happen whether you take action or not. For example, meetings and birthdays are events.
task - A calendar entry that represents some action by you. For example, writing a report and visiting a client are tasks.
In general, an event is something you schedule on the calendar, and it happens at a specific time and place. A task occurs over time, and while it may need to be started at a specific time or completed by a specific time, the task itself does not.
Finally, it should be noted that tasks can only be displayed in the main calendar in certain views. (ie. multiweek)
Example: A staff meeting is an event; it happens at 9:00am on the 10th.
Calling everyone on staff to review the agenda for the meeting is a task; it must be completed by 5pm on the 9th.
That is, an event is scheduled at a specific time and a task spans a period of time
2008-10-01
Let emms to remember the last directory
It causes a little trouble to me each time to find the target directory in directory when using the fantastic Emacs Multimedia System(emms), because I have to start to locate the target directory from the default directory which is specified in `emms-source-file-default-directory'(BTW, I bound the key `' to `emms-play-find').
So I'm wondering why not to make emms remember the last target directory? Then it's easy to switch other directories around the current targeted one(I tend to listen to albums with the same genre). So after digging into emms's source code, I changed the definition of `emms-play-find' a little(in fact that function is defined via a macro called `define-emms-source'):
And that's it. After reloading emms, use `emms-play-find' to find a target directory, it simply remembers that directory which ease the next operation for me.
And here is the patch file:
So I'm wondering why not to make emms remember the last target directory? Then it's easy to switch other directories around the current targeted one(I tend to listen to albums with the same genre). So after digging into emms's source code, I changed the definition of `emms-play-find' a little(in fact that function is defined via a macro called `define-emms-source'):
;;;###autoload (autoload 'emms-play-find "emms-source-file" nil t)
;;;###autoload (autoload 'emms-add-find "emms-source-file" nil t)
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
(interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
emms-source-file-default-directory
emms-source-file-default-directory
t))
(regex (read-from-minibuffer "Find files matching: ")))
(setq emms-source-file-default-directory directory-name)
(list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))
(emms-playlist-insert-track
(emms-track 'file file))))
(emms-source-file-directory-tree dir regex)))
And that's it. After reloading emms, use `emms-play-find' to find a target directory, it simply remembers that directory which ease the next operation for me.
And here is the patch file:
--- /tmp/emms-3.0/emms-source-file.el 2007-06-30 00:16:24.000000000 +0800
+++ elisp/emms/emms-source-file.el 2008-10-01 14:14:40.000000000 +0800
@@ -150,12 +150,13 @@
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
- (interactive (list
- (emms-read-directory-name "Find in directory: "
- emms-source-file-default-directory
- emms-source-file-default-directory
- t)
- (read-from-minibuffer "Find files matching: ")))
+ (interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
+ emms-source-file-default-directory
+ emms-source-file-default-directory
+ t))
+ (regex (read-from-minibuffer "Find files matching: ")))
+ (setq emms-source-file-default-directory directory-name)
+ (list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))
2008-01-18
Sick
Tired
Exhausted
Whom can I talk to?
What's wrong with my life?
It's already several days that I can't have good sleep. Feel tired even I when wake up in the morning.
Is what I'm chasing really what I need???
Exhausted
Whom can I talk to?
What's wrong with my life?
It's already several days that I can't have good sleep. Feel tired even I when wake up in the morning.
Is what I'm chasing really what I need???
2008-01-15
Switching from ubuntu to Arch linux
Because compared to ubuntu, arch linux is :
- lightweight.
- optimized for i686
- more faster to connect to its mirrors.
- lightweight.
- optimized for i686
- more faster to connect to its mirrors.
2008-01-10
订阅:
博文 (Atom)