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 inputs
Please 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块钱。

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:

#!/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
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:

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'):


;;;###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???