Posts

Showing posts from July 8, 2012

Why I Hate C

Perm URL with updates: http://xahlee.info/comp/why_i_hate_C_lang.htmlI despise C the language, not because of particular technical aspect, or lacking some functionality such as lacking {automatical memory management, module system, namespace, list/hashtable datatype, complex number datatype, regex, function closure, function as value, OOP support, functional programing support, …}, none of that, but on certain sloppiness that's in the bones of C. (pretty much like unix (they bootstrap each other (it's scam booting scam)))Perhaps the best simple example to illustrate, is its invention of the format function printf. Completely ad hoc, inflexible, cryptic syntax and semantics. When i first learned it (thru Perl. (C/Unix has a knack like virus. Now it's in about every lang.)), i went WTF is this? (i came from Mathematica). The printf can print hex, but with fixed representation of the digits, and can't do arbitrary n-based number system. It can print decimal in several for…

Curiosity: Perl File Extension in Emacs Config

A curiosity question.emacs's “auto-mode-alist” has this value: ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode) the regex there seems a bit wild. If i didn't get it wrong, then its like this . ([pP] ( [Llm] | erl | od ) | al ) so it covers: .pl .perl .pod .pm .al plus SOME case variations. e.g. {.pL , .PL}.what's the “.al” for?is it necessary to include the “.pod”? because the perl-mode doesn't do any coloring with “.pod” files, nor cperl-mode. If there's a mode handing “.pod” file am guessing it won't be perl-mode.also, is the “.perl” there necessary? Is that a accepted perl file suffix? (Just checked it's not in any file bundled with perl v5.10.1.)would it be better if it's just ("\\.\\(p\\([lm]\\)\\)\\'" . perl-mode) ?Emacs: How to Associate a File with a Major Mode?Emacs: Text Pattern Matching (regex) tutorialXah's Perl & Python Tutorial

Tonight I'm Frakking You

Image

emacs lisp: getting current buffer path

In your elisp program, you may call (buffer-file-name) to get the full path of the file, but sometimes the current buffer isn't associated with a file, so your program will fail.Here's a idiom: (or (buffer-file-name) default-directory). This way, if the buffer isn't a file, it'll return the directory path of the buffer. (when a buffer is created, its “default-directory” is typically the same as previous buffer. In the case of temp buffers created by emacs such as {*info*, *scratch*, *Bookmark List*, …}, it's usually home dir.)I just searched all my elisp files for this oversight.(info "(elisp) Buffer File Name")Emacs Lisp Idioms (for writing interactive commands)Common Emacs Lisp Functions

BMW's Sexual Ad

post removed because it might violate Google's ad program policy. See here instead: 〈Xah's Sex Blog〉 http://xahlee.org/sex/blog.html

Gauss's construction of the 17-gon

Image
Gauss's construction of the 17-gon (Heptadecagon). He probably didn't actually draw it, only proved possible.Gauss construction 17-gon (unverified)More info on Wikipedia Constructible polygon

Emacs Lisp: Ways to Exit/Break a Loop

Perm URL with updates: http://ergoemacs.org/emacs/elisp_break_loop.htmlIn many languages, there's “break” or “exit” keywords that you can use to exit a loop. In functional programing, usually you don't do loops or exit loops, but sometimes that's just what you need.In elisp, to exit loop, you can either use a flag (i.e. set a variable to indicate whether to exit.), or use the built-in catch and throw.Using a FlagHere's a pseudo-code for using a flag: (while (and (not found) (< i listLength)) … ; if found, set found (setq i (1+ i)) ) Here's a actual example using a flag: (defunget-new-fpath (ξfPath moveFromToList) "Return a new file full path for ξfPath. moveFromToList is a alist." (let ((ξfoundResult nil) (ξi 0) (ξlen (length moveFromToList)) ) ;; compare to each moved dir. (while (and (not ξfoundResult) (< ξi ξlen)) (when (string-match (concat "\\`" (regexp-quote (car (elt moveFromToList ξi))) ) ξfPath ) (let…

JavaScript: Exclamation Before function

I come across JavaScript code like this today: !function(d,s,id){…}(…); What does that !function mean?Turns out, it is equivalent to this: (function(d,s,id){…})(…); The exclamation makes the function a expression. (it's the boolean “not” operator.) People do this hack to save one character worth of source code file size. Silly.

List of Keyboards with Mechanical Switch

Perm URL with updates: http://xahlee.info/kbd/keyboards_with_mechanical_switch.htmlHere's a quick list of keyboards with mechanical switches. They typically start at $70. Ergonomic ones with fancy shapes usually starts at $200. (If you don't know what Cherry MX means, first see: Guide to Computer Keyboard Key Switch Mechanisms.)Note: Microsoft or Logitech keyboards do not use mechanical switches, even expensive ones.Ergonomic• Truly Ergonomic Keyboard (Cherry MX Brown)• The μTRON Keyboard (hard to buy in USA)• Kinesis Contoured Keyboard (Cherry MX Brown)• Maltron KeyboardDatadesk Tech Smartboard Keyboard. (may be hard to buy) Picture at Ergonomic Keyboards GalleryStandard• Corsair K60, K90 (Cherry MX Red)• Filco Majestouch. Produces many different models, with or without numberical keypad, and also with many switch type: Brown, Black, Blue, or Red. Be sure to read model's spec in detail. (104 keys: amazon) (See: Keyboards Without Numberic Keypad.)• Razer BlackWidow. (Cher…

Wordy English: A Etymology Rhapsody on Spiracle

New Wordy English article: 〈A Etymology Rhapsody on Spiracle〉: spiracle, fan, allophone, camouflage @ http://wordy-english.blogspot.com/2012/07/etymology-rhapsody-on-spiracle.html.Be sure to subscribe Wordy English for literature/writing/vocabulary related articles.

Emacs: Ways to Jump to Points

when coding, there's a common need to jump to a particular place, then return to previous position.There are several ways. Most common standard way are:exchange-point-and-mark 【Ctrl+xCtrl+x】.【Ctrl+uCtrl+Space】I've tried all ways in past years, including custom elisp that push marks. But i found split windows to be the best.e.g. split window. Go to where you wanna be. When done, unsplit. Give split/unsplit a easy key. (➲ Emacs: How to Define Keyboard Shortcuts) e.g. In ErgoEmacs, it's:【Alt+3】 delete-other-windows【Alt+4】 split-window-vertically【Alt+0】 delete-window【Alt+s】 other-windowOn a different note, here's a nice tip when using mouse (thx to Ken Goldman):Middle mouse button on a status bar expands current pane.Right mouse button on a status bar closes current pane.