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.



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:

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 inputs
Please forgive my ignorance!