Emacs Lisp and User:CYD: Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
* added lots more information, including an example
 
mNo edit summary
 
Line 1: Line 1:
I'm a [[Stanford University|college]] student majoring in [[physics]], with interests in [[computer science]], [[mathematics]], and purple [[llama|llamas]]. I'll be working on some articles in physics (particularly in the areas of [[quantum mechanics]], [[quantum field theory]], [[quantum computer|quantum computing]], and the history of 20th century physics.)
<b>Emacs Lisp</b> is a dialect of the [[LISP programming language]] used by the [[Emacs|GNU Emacs]] and [[XEmacs]] editors, which will henceforth be referred to as "Emacs". Emacs Lisp is sometimes also called ''Elisp'', at the risk of confusion with an unrelated dialect of Lisp with the same name.


Unfortunately, I'm caught up in homework and research at the moment, so I won't be able to work on the articles I want to. During the holidays, maybe...
The majority of the editing functionality in Emacs comes from code written in Emacs Lisp; the rest is written in [[C programming language|C]]. Emacs Lisp code can be written by users to customize and extend Emacs.


Articles I write for and edit:
Emacs Lisp is related to the [[MacLisp]] and [[Common Lisp]] dialects of Lisp. It supports [[procedural programming|imperative]] and [[functional programming|functional]] programming methods. Lisp was chosen as the extension language for Emacs because its powerful features, including the ability to treat functions as data.


* [[black hole]]
Writing Emacs Lisp is not the only method of customizing Emacs. Since version 20, Emacs (both GNU Emacs and XEmacs) has included a "Customize" facility which allows users to set common customization variables through a graphical interface. "Customize" works by writing Emacs Lisp code for the user, and is limited to simple customizations. Not every user needs the full degree of extensibility offered by Emacs; for those that do, it is necessary to write one's own Emacs Lisp code.
* [[bra-ket notation]]
* [[classical mechanics]]
* [[Paul Dirac]]
* [[Pauli exclusion principle]]
* [[physics]]
* [[Schrodingers cat]]
* [[quantum mechanics]]
* [[Batman]], [[Emacs]], [[XEmacs]], [[open source movement]], [[RSA]], [[Tunguska]]


Artices I've started, and take an active interest in:
'''An Emacs Lisp Example'''


* [[EPR paradox]]
Here is a simple example of an Emacs extension written in Emacs Lisp. In Emacs, the editing area can be split into separate areas called "windows", each containing a different buffer. A buffer is, roughly speaking, a region of text loaded into Emacs' memory, which can be saved into a text document.
* [[Feynman diagram]]
* [[Grovers algorithm]]
* [[Hamiltonian]]
* [[identical particles]]
* [[Lagrangian]]
* [[no cloning theorem]]
* [[Pauli effect]]
* [[Pauli matrices]]
* [[quantum entanglement]]
* [[Wolfgang Ernst Pauli]]


Things to work on:
The command to open a new window is "<tt>C-x 2</tt>", which runs the lisp function <tt>split-window-vertically</tt>. Normally, when the new window appears, it displays the same buffer as the previous one. Suppose we wish to make it display the next available buffer. In order to do this, the user writes the following Emacs Lisp code, in either an existing Emacs Lisp source file or an empty Emacs buffer:


[[Bell basis]], [[decoherence]], [[Shors algorithm]], [[quantum error correction]], [[quantum cryptography]], [[path integral]], [[spin]], [[perturbation theory]], [[entropy]], [[spinor]], [[Lorentz force]]
(defun my-split-window-function ()
(interactive)
(split-window-vertically)
(set-window-buffer (next-window) (other-buffer)))


----
(global-set-key "C-x2" 'my-split-window-function)


Hi CYD, and welcome! Thanks for you contributions in the physics area. There's a lot to do there :-) --AxelBoldt
The first statement <tt>(defun...)</tt>, defines a new function, <tt>my-split-window-function</tt>, which calls <tt>split-window-vertically</tt> (the old window-splitting function), then tells the new window to display another buffer. The second statement, <tt>(global-set-key...)</tt> re-binds the keys "C-x 2" to the new function.


Hi CYD - I've checked out your work and it's of a very high standard - congrats :) So an extra big welcome to the 'pedia. Regards - ManningBartlett
However, there is an easier way to write this. Emacs Lisp has a powerful feature called ''advice'', which allows the user to create wrappers around existing functions instead of defining their own. Using advice, the above code can be reimplemented as follows:


Hello, CYD and welcome - we need good physicists!
(defadvice split-window-vertically
(after my-window-splitting-advice first () activate)
(set-window-buffer (next-window) (other-buffer)))

This instructs <tt>split-window-vertically</tt> to execute the user-supplied code whenever it is called, before executing the rest of the function.

These changes take effect when the code is ''evaluated'', using (for instance) the command "<tt>M-x eval-buffer</tt>". It is not necessary to recompile or even restart Emacs, which makes customizing Emacs very convenient. If the code is saved into the Emacs "init file" (usually a file named <tt>.emacs</tt> in the user's home directory), then Emacs will load the extension the next time it starts. Otherwise, the changes will be lost when the user exits Emacs.

'''Source Code and Byte Code'''

Emacs Lisp code is stored as [[plain text]], with the filename suffix <tt>.el</tt> (with the exception of the user init file, <tt>.emacs</tt>, mentioned above.) When the files are loaded, Emacs reads and parses the functions and variables, storing them in memory. They are then available to other editing functions, and to user commands. Functions and variables can be freely altered and re-loaded.

In order to save memory space, much the functionality of Emacs is not loaded until it is needed. The group of Emacs Lisp code providing each set of functionality is called a "library". For example, there is a library for highlighting keywords in program source code, and a library for playing the game of [[Tetris]]. Each library is implemented using one or more Emacs Lisp source files.

Certain functions in Emacs Lisp are known as "primitives", or "built-in functions". These are functions written in C. Although these functions can be called from the Lisp code, they can only be modified by editing the C source files and recompiling the editor. Functions are written as primitives because C code is faster than Emacs Lisp code. However, only those few functions that need to run quickly and efficiently are written as primitives, because they are not as flexible as Emacs Lisp functions. Primitives are not available in libraries; they are stored in the Emacs executable itself.

The performance of Emacs Lisp code can be further increased by "byte-compilation". Emacs contains a [[compiler]] which can translate Emacs Lisp code into a special representation known as [[bytecode]]. Compared to plain Emacs Lisp source files, bytecode loads faster, takes up less memory space when loaded, and runs faster. Although bytecode is still slower than primitives, unlike compiled C code it can be freely modified and re-loaded. In addition, bytecode files can be used on different platforms without recompilation. The standard Emacs Lisp code distributed with Emacs is loaded as bytecode, although the matching source files are usually provided for the user's reference as well. User-supplied extensions are typically not byte-compiled, as they are neither as large nor as computationally intensive.

'''Language Features'''

Emacs Lisp uses [[dynamic scope|dynamic scoping]] instead of [[lexical scope|lexical scoping]]. If a variable is declared within the scope of a function, it is available to subroutines called from within that function. Originally, this was meant to provide greater flexibility for user customizations. However, dynamic binding has several disadvantages. Firstly, it can easily lead to bugs in large programs, due to unintended interactions between variables in different function. Secondly, accessing variables under dynamic scoping is generally slower than under lexical scoping. As a result, plans have been made to convert Emacs Lisp to lexical binding, though this has not yet been done.

----


I removed the text at [[Standard text editor]] as it is a copy of a (admittedly amusing) Usenet post and the original author still holds the copyright. -- [[The Anome]]
'''External Links'''


Would you have an interest in the math behind [[Dyson Sphere]] comparisons against [[Earth]]? I'll stab at it eventually, but as much as tickles your fancy I can fill in more. --[[Romaq]]
* R. Chassell, "Programming in Emacs Lisp, an Introduction" http://www.gnu.org/manual/emacs-lisp-intro/emacs-lisp-intro.html
* B. Lewis, D. LaLiberte, R. Stallman, "GNU Emacs Lisp Reference Manual" http://www.gnu.org/manual/elisp-manual-20-2.5/html_node/elisp_toc.html

Revision as of 23:14, 26 January 2002

I'm a college student majoring in physics, with interests in computer science, mathematics, and purple llamas. I'll be working on some articles in physics (particularly in the areas of quantum mechanics, quantum field theory, quantum computing, and the history of 20th century physics.)

Unfortunately, I'm caught up in homework and research at the moment, so I won't be able to work on the articles I want to. During the holidays, maybe...

Articles I write for and edit:

Artices I've started, and take an active interest in:

Things to work on:

Bell basis, decoherence, Shors algorithm, quantum error correction, quantum cryptography, path integral, spin, perturbation theory, entropy, spinor, Lorentz force


Hi CYD, and welcome! Thanks for you contributions in the physics area. There's a lot to do there :-) --AxelBoldt

Hi CYD - I've checked out your work and it's of a very high standard - congrats :) So an extra big welcome to the 'pedia. Regards - ManningBartlett

Hello, CYD and welcome - we need good physicists!

I removed the text at Standard text editor as it is a copy of a (admittedly amusing) Usenet post and the original author still holds the copyright. -- The Anome

Would you have an interest in the math behind Dyson Sphere comparisons against Earth? I'll stab at it eventually, but as much as tickles your fancy I can fill in more. --Romaq