(let* ((yin ((lambda (foo) (newline) foo)
(call-with-current-continuation (lambda (bar) bar))))
(yang ((lambda (foo) (write-char #\*) foo)
(call-with-current-continuation (lambda (bar) bar)))))
(yin yang))
Dec 31, 2007
dc -e 9534175522489273769672731388983542309678957P
Jan 15, 2008
ASDF is to Lisp what Make is to C.
Jan 16, 2008
Common Lisp's FORMAT function is--along with the extended LOOP
macro--one of the two Common Lisp features that inspires a strong
emotional response in a lot of Common Lisp users. Some love it; others
hate it.^1
Jan 16, 2008
CL-USER> (format nil "~:d" 100000000)
"100,000,000"
CL-USER> (format nil "~,,'.,4:d" 100000000)
"1.0000.0000"
Jan 16, 2008
CL-USER> (format nil "~R file~:P" 1)
"one file"
CL-USER> (format nil "~R file~:P" 11)
"eleven files"
Jan 16, 2008
(format nil "~{~a~^, ~}" (list 1 2 3))
CL-USER> "1, 2, 3"
Jan 16, 2008
CL-USER> (format nil "~{~s~*~^ ~}" '(:a 10 :b 20))
":A :B"
Jan 16, 2008
(tagbody
a (print 'a) (if (zerop (random 2)) (go c))
b (print 'b) (if (zerop (random 2)) (go a))
c (print 'c) (if (zerop (random 2)) (go b)))
Jan 16, 2008
CL-USER> '(((((((((((((((((((((((((((())))))))))))))))))))))))))))
(((((((((((((((((((((((((((NIL)))))))))))))))))))))))))))
Jan 16, 2008
CL-USER> (setf (values *x* *y*) (floor (/ 57 34)))
1
23/34
Jan 16, 2008
CL-USER> (cl:defparameter *passwd* (sb-posix:getpwuid
(sb-posix:getuid)) "REPL generated global variable.")
*PASSWD*
CL-USER> (loop for s in '("dir" "gecos" "gid" "name" "passwd" "shell"
"uid") collect
(let* ((symbol-name (string-upcase (concatenate 'string "passwd-" s)))
(func (find-symbol symbol-name (find-package :sb-posix))))
(when func
(funcall func *passwd*))))
("/home/luanma" "Xiaohong Zhao,,," 1000 "luanma" "x" "/bin/bash" 1000)
Jan 17, 2008
CL-USER> (cl:defparameter *random* (loop repeat 1000 collect (random
1000)) "REPL generated global variable.")
*RANDOM*
CL-USER> (loop for r in *random*
counting (oddp r) into odds
counting (evenp r) into evens
summing r into sum
maximizing r into max
minimizing r into min
finally (return (list odds evens sum max min)))
(494 506 516910 998 0)
Jan 17, 2008
CL-USER> (loop 'hello)
Jan 17, 2008
The function LDB,
whose name stands for load byte, can be used to extract and set (with
SETF) any number of contiguous bits from
an integer.
Jan 18, 2008
If your program gets this function name 'from outside', you'd
better make very sure that you're not funcalling the function
FORMAT-MY-HARD-DRIVE-AND-SEND-SOME-MISSILES-TO-CHINA...
Feb 11, 2008
Lighty & nginx
Feb 11, 2008
static long binary_decode(const char *s) {
long x=0;
while(*s!=0 && (*s=='1' || *s=='0')) {
x<<=1;
x+=*s-'0';
s++;
}
return x;
}
Feb 15, 2008
_, space_count = string.gsum(s, " ", " ")
Feb 15, 2008
s = "Deadline is 30/05/1999, firm"
date = "%d%d/%d%d/%d%d%d%d"
print(string.sub(s, string.find(s, date)))
Feb 15, 2008
pair = "name = value"
_, _, key, value = string.find(pair, "(%a+)%s*=%s*(%a+)")
print(key, value)
Feb 15, 2008
date = '17/7/1999'
_, _, d, m, y = string.find(date, "(%d+)/(%d+)/(%d+)")
print(d, m, y)
Feb 15, 2008
s = [[then he said: "that's all right!"]]
_, _, c, quotedPart = string.find(s, "([\"'])(.-)%1")
print(quotedPart)
print(c)
Feb 15, 2008
print(string.gsub("hello, lua!", "(%a)", "%1-%1"))
Feb 15, 2008
print(string.gsub("hello, lua!", "(.)(.)", "%2%1"))
Feb 15, 2008
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
Feb 16, 2008
-- typical usage: lua -e N=1000 sieve.lua | column
Feb 17, 2008
Check: A unit test framework for C programs.
Feb 17, 2008
NAME
tree - list contents of directories in a tree-like format.
Feb 17, 2008
$ autoreconf --install
$ ./configure
$ make
(`autoreconf' determines which commands are needed in order for
`configure' to be created or brought up to date. Previously one would
use a script called `autogen.sh' or `bootstrap', but that practice is
unnecessary now.)
Feb 21, 2008
plugin_LTLIBRARIES = guile.la
guile_la_SOURCES = guile.c
guile_la_CFLAGS = $(GUILE_CFLAGS) $(GLIB2_CFLAGS)
guile_la_LDFLAGS = -avoid-version -module
guile_la_LIBADD = $(GUILE_LDFLAGS) $(GLIB2_LIBS)
Feb 21, 2008
dnl Check for guile
GUILE_FLAGS
GUILE_SITE_DIR
Feb 21, 2008
dnl Check for glib2
PKG_CHECK_MODULES(GLIB2,glib-2.0 >= 2.4
gthread-2.0,HAVE_GLIB2=yes,HAVE_GLIB2=no)
AC_SUBST(GLIB2_LIBS)
AC_SUBST(GLIB2_CFLAGS)
if test "x$HAVE_GLIB2" = "xno"; then
AC_MSG_ERROR([XChat Guile requires GLib2 to compile.])
fi
Feb 21, 2008
AUTOMAKE_OPTIONS = dist-bzip2 dist-zip
Feb 21, 2008
What is SunUO?
--------------
SunUO is a free Ultima Online server, based on RunUO.
Getting SunUO
-------------
You can download SunUO on the home page:
http://www.sunuo.org/
Feb 21, 2008
To generate the project files you must download premake 3.1 from:
http://sourceforge.net/project/showfiles.php?group_id=71616
and place the executable (premake.exe) in this directory.
First you should edit config.lua to make sure you get what you need.
After this is done you should run the .bat files corresponding to your version
of 'Microsoft Visual C++' (MSVC). This will generate a solution in
this directory.
You can run clean.bat to clean up the project files in case you want to switch
to another version of MSVC.
Feb 21, 2008
# Checks for libraries.
AC_CHECK_LIB([dl], [main])
AC_CHECK_LIB([pthread], [main],, AC_MSG_ERROR([cannot find pthread library]))
PKG_CHECK_MODULES(freetype2, freetype2 >= 0.15.0)
AC_SUBST(freetype2_CFLAGS)
AC_SUBST(freetype2_LIBS)
PKG_CHECK_MODULES(pcre, libpcre >= 5.0)
AC_SUBST(pcre_CFLAGS)
AC_SUBST(pcre_LIBS)
Feb 21, 2008
AM_INIT_AUTOMAKE([1.9 no-dist-gzip dist-bzip2])
Feb 22, 2008
AC_CANONICAL_HOST
Feb 22, 2008
gettextize
Feb 22, 2008
make tags
Feb 24, 2008
latex-cjk-chinese-arphic-bkai00mp
latex-cjk-chinese-arphic-bsmi00lp
latex-cjk-chinese-arphic-gbsn00lp
latex-cjk-chinese-arphic-gkai00mp
Feb 25, 2008
fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
Feb 25, 2008
For OCaml, use tuareg-mode
Feb 26, 2008
iota count [start step]
This procedure takes its name from the APL primitive.
Feb 26, 2008
(let loop () (loop))
Feb 26, 2008
(let loop () (begin (sleep 2) (loop)))
Feb 26, 2008
(pp
(map (lambda (n)
(let* ((str (make-string n #\g))
(url (string-append str ".com")))
(cons url (host url)))) (iota 38 2)))
(("gg.com" . "80.93.161.15")
("ggg.com" . "66.98.154.24")
("gggg.com" . "67.18.104.18")
("ggggg.com" . "82.98.86.161")
("gggggg.com" . "216.102.246.27")
("ggggggg.com" . "209.85.84.167")
("gggggggg.com" . "72.51.27.51")
("ggggggggg.com" . "72.51.27.51")
("gggggggggg.com" . "208.73.212.12")
("ggggggggggg.com" . "72.30.33.102")
("gggggggggggg.com" . "72.30.33.102")
("ggggggggggggg.com" . "72.30.33.102")
("gggggggggggggg.com" . "72.30.33.102")
("ggggggggggggggg.com" . "72.30.33.102")
("gggggggggggggggg.com" . "69.46.228.45")
("ggggggggggggggggg.com" . "72.51.27.51")
("gggggggggggggggggg.com" . "72.51.27.51")
("ggggggggggggggggggg.com" . "66.45.254.245")
("gggggggggggggggggggg.com" . "72.51.27.51")
("ggggggggggggggggggggg.com" . "72.51.27.51")
("gggggggggggggggggggggg.com" . "66.45.254.244")
("ggggggggggggggggggggggg.com" . "72.51.27.51")
("gggggggggggggggggggggggg.com"
.
"208.73.212.12")
("ggggggggggggggggggggggggg.com"
.
"69.46.228.41")
("gggggggggggggggggggggggggg.com"
.
"8.15.231.215")
("ggggggggggggggggggggggggggg.com"
.
"72.51.27.51")
("gggggggggggggggggggggggggggg.com"
.
"208.73.212.12")
("ggggggggggggggggggggggggggggg.com"
.
"72.51.27.51")
("gggggggggggggggggggggggggggggg.com"
.
"8.15.231.215")
("ggggggggggggggggggggggggggggggg.com"
.
"216.188.26.235")
("gggggggggggggggggggggggggggggggg.com"
.
"8.15.231.214")
("ggggggggggggggggggggggggggggggggg.com"
.
"8.15.231.219")
("gggggggggggggggggggggggggggggggggg.com"
.
"216.188.26.235")
("ggggggggggggggggggggggggggggggggggg.com"
.
"38.97.225.135")
("gggggggggggggggggggggggggggggggggggg.com"
.
"66.45.254.245")
("ggggggggggggggggggggggggggggggggggggg.com"
.
"216.188.26.235")
("gggggggggggggggggggggggggggggggggggggg.com"
.
"69.46.228.56")
("ggggggggggggggggggggggggggggggggggggggg.com"
.
"8.15.231.213"))
#unspecified
Feb 27, 2008
"Class precedence list" is often abbreviated, in documentation and
Scheme variable names, to "cpl".
Feb 27, 2008
Description: Enhanced Implementation of Emacs Interpreted Objects
EIEIO is an Emacs lisp program which implements a controlled
object-oriented programming methodology following the CLOS
standard. EIEIO also has object browsing functions, and custom widget
types. It has a fairly complete manual describing how to use it.
.
EIEIO is now a part of CEDET (Collection of Emacs Development
Environment Tools).
Feb 27, 2008
EIEIO is a CLOS (Common Lisp Object System) compatibility layer.
Feb 28, 2008
(define-class <complex> (<number>)
(r #:init-value 0 #:getter get-r #:setter set-r! #:init-keyword #:r)
(i #:init-value 0 #:getter get-i #:setter set-i! #:init-keyword #:i))
Feb 28, 2008
(define-class <complex> (<number>)
(r #:init-value 0 #:accessor real-part #:init-keyword #:r)
(i #:init-value 0 #:accessor imag-part #:init-keyword #:i))
Feb 28, 2008
(define-class <complex> (<number>)
;; True slots use rectangular coordinates
(r #:init-value 0 #:accessor real-part #:init-keyword #:r)
(i #:init-value 0 #:accessor imag-part #:init-keyword #:i)
;; Virtual slots access do the conversion
(m #:accessor magnitude #:init-keyword #:magn
#:allocation #:virtual
#:slot-ref (lambda (o)
(let ((r (slot-ref o 'r)) (i (slot-ref o 'i)))
(sqrt (+ (* r r) (* i i)))))
#:slot-set! (lambda (o m)
(let ((a (slot-ref o 'a)))
(slot-set! o 'r (* m (cos a)))
(slot-set! o 'i (* m (sin a))))))
(a #:accessor angle #:init-keyword #:angle
#:allocation #:virtual
#:slot-ref (lambda (o)
(atan (slot-ref o 'i) (slot-ref o 'r)))
#:slot-set! (lambda(o a)
(let ((m (slot-ref o 'm)))
(slot-set! o 'r (* m (cos a)))
(slot-set! o 'i (* m (sin a)))))))
Feb 28, 2008
Class precedence list (CPL)
Rule 1: Each class is more specific than its superclasses.
Rule 2: For a given class, superclasses listed earlier are more
specific than those listed later.
Feb 28, 2008
(use-modules (logging logger)
(logging rotating-log)
(logging port-log)
(oop goops))
Feb 28, 2008
sudo apt-get source bnetd armagetronad-dedicated bzflag-server
conquest-server crossfire-server cyphesis-cpp fceu-server
freeciv-server ggz-game-servers ggz-txt-client ggzd imazesrv koalamud
libatlas-cpp-0.6-1 libgrapple-dev liquidwar-server monopd mordor
nexuiz-server openarena-server pennmush-mysql pvpgn pybridge-server
python-2play python-poker-network python-poker2d python-tofu
tetrinet-server tetrinetx xtux-server alien-arena-server
sauerbraten-server teamspeak-server tremulous-server warsow-server
Feb 28, 2008
Coroutines are a very simple cooperative multitasking environment
where the switch from one task to another is done explicitly by a
function call. Coroutines are a lot faster than processes or threads
switch, since there is no OS kernel involvement for the operation.
Feb 28, 2008
PCL(3) Portable Coroutine Library
PCL(3)
NAME
co_create, co_call, co_resume, co_delete, co_exit_to, co_exit,
co_current - C coroutine management
SYNOPSIS
#include <pcl.h>
coroutine_t co_create(void *func, void *data, void *stack, int
stacksize);
void co_delete(coroutine_t co);
void co_call(coroutine_t co);
void co_resume(void);
void co_exit_to(coroutine_t co);
void co_exit(void);
coroutine_t co_current(void);
Feb 28, 2008
static long tvcmp(struct timeval *a, struct timeval *b) {
if (a->tv_sec - b->tv_sec)
return a->tv_sec - b->tv_sec;
return a->tv_usec - b->tv_usec;
}
Feb 28, 2008
static int co_ctx_sdir(unsigned long psp) {
int nav = 0;
unsigned long csp = (unsigned long) &nav;
return psp > csp ? -1: +1;
}
static int co_ctx_stackdir(void) {
int cav = 0;
return co_ctx_sdir((unsigned long) &cav);
}
Feb 29, 2008
Atlas-C++
Welcome to Atlas-C++, the C++ reference implementation of the Atlas protocol.
This library implements the Atlas protocol, for use in client-server
game applications. This library is suitable for linking to either
clients or servers.
Feb 29, 2008
Grapple supports simple development of networked applications using both
TCP/IP and UDP/IP. Grapple keeps track of connections to a server, relays
messages from client to client, all without the need to understand any
complicated network code. Grapples feature list is as follows
Simple client-server networking
Keeps all clients aware of all other clients
Network messenging by either a push or a pull model, or a mixture of both
Unlimited connections to multiple servers.
Multiple methods of querying users
Data transfer via TCP, UDP, or reliable UDP
Passworded servers
User Groups for client bandwidth saving
Server security - server can disconnect any client
Network load reacting data transmission and retransmission
Background pinging to monitor network states
A fuly functional lobby system (see README.lobby)
Feb 29, 2008
poker-network includes a poker server, a client library, an abstract
user interface library and a client based on it.
The server deals the cards and checks the user actions using a poker
game engine (poker-engine). It listens on a TCP/IP port and
understands a poker-network specific protocol. The persistent
informations (accounts, hand history etc.) are stored in a MySQL
database. The server was designed and tested to gracefully handle 1000
simultaneous players on a single machine also running the MySQL
server.
Feb 29, 2008
p + k is defined to be &p[k]
Feb 29, 2008
static double identityMatrix[3][3] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 }
};
Feb 29, 2008
Almost every wise saying has an oppsite one, no less wise, to banance it.
-- Goerge Santayana
Feb 29, 2008
The world is concurrent.
Things in the world don't share data.
Things communicate with messages.
Things fail.
Feb 29, 2008
Erlang is characterized by the following features:
* Concurrency - Erlang has extremely lightweight processes whose memory
requirements can vary dynamically. Processes have no shared memory and
communicate by asynchronous message passing. Erlang supports
applications with very large numbers of concurrent processes. No
requirements for concurrency are placed on the host operating system.
* Distribution - Erlang is designed to be run in a distributed
environment. An Erlang virtual machine is called an Erlang node. A
distributed Erlang system is a network of Erlang nodes (typically one
per processor). An Erlang node can create parallel processes running
on other nodes, which perhaps use other operating systems. Processes
residing on different nodes communicate in exactly the same was as
processes residing on the same node.
* Robustness - Erlang has various error detection primitives which can
be used to structure fault-tolerant systems. For example, processes
can monitor the status and activities of other processes, even if
these processes are executing on other nodes. Processes in a
distributed system can be configured to fail-over to other nodes in
case of failures and automatically migrate back to recovered nodes.
* Soft real-time - Erlang supports programming "soft" real-time systems,
which require response times in the order of milliseconds. Long
garbage collection delays in such systems are unacceptable, so Erlang
uses incremental garbage collection techniques.
* Hot code upgrade - Many systems cannot be stopped for software
maintenance. Erlang allows program code to be changed in a running
system. Old code can be phased out and replaced by new code. During
the transition, both old code and new code can coexist. It is thus
possible to install bug fixes and upgrades in a running system without
disturbing its operation.
* Incremental code loading - Users can control in detail how code is
loaded. In embedded systems, all code is usually loaded at boot time.
In development systems, code is loaded when it is needed, even when
the system is running. If testing uncovers bugs, only the buggy code
need be replaced.
* External interfaces - Erlang processes communicate with the outside
world using the same message passing mechanism as used between Erlang
processes. This mechanism is used for communication with the host
operating system and for interaction with programs written in other
languages. If required for reasons of efficiency, a special version of
this concept allows e.g. C programs to be directly linked into the
Erlang runtim
Feb 29, 2008
average(X) -> sum(X) / len(X).
sum([H|T]) -> H + sum(T);
sum([]) -> 0.
len([_|T]) -> 1 + len(T);
len([]) -> 0.
Feb 29, 2008
double([H|T]) -> [2*H|double(T)];
double([]) -> [].
member(H, [H|_]) -> true;
member(H, [_|T]) -> member(H, T);
member(_, []) -> false.
Feb 29, 2008
average(X) -> average(X, 0, 0).
average([H|T], Length, Sum) ->
average(T, Length + 1, Sum + H);
average([], Length, Sum) ->
Sum / Length.
Feb 29, 2008
Tail recursive = the last thing the function does is to call itself.
Feb 29, 2008
luanma@yueliang:~$ gcc -Os -S hello.c -o -
.file "hello.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $16, %esp
pushl $.LC0
call puts
movl -4(%ebp), %ecx
xorl %eax, %eax
leave
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)"
.section .note.GNU-stack,"",@progbits
Feb 29, 2008
luanma@yueliang:~$ strace hello
execve("./hello", ["hello"], [/* 36 vars */]) = 0
uname({sys="Linux", node="yueliang", ...}) = 0
brk(0) = 0x80be000
brk(0x80becb0) = 0x80becb0
set_thread_area({entry_number:-1 -> 6, base_addr:0x80be830,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1}) = 0
brk(0x80dfcb0) = 0x80dfcb0
brk(0x80e0000) = 0x80e0000
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 5), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7fa6000
write(1, "Hello, world!\n", 14Hello, world!
) = 14
exit_group(0) = ?
Process 15734 detached
Mar 1, 2008
loop(W, Bit, State) ->
receive
{gs,quit,_,_,_} -> true;
{gs,W,keypress,[],[b|_]} -> move(left, W, Bit, State);
{gs,W,keypress,[],[n|_]} -> move(rot, W, Bit, State);
{gs,W,keypress,[],[m|_]} -> move(right, W, Bit, State);
drop_block -> move(down, W, Bit, State);
{gs,W,keypress,[],[space|_]} -> move(drop, W, Bit, State);
{gs,W,keypress,[],[d|_]} -> move(down, W, Bit, State);
{gs,W,keypress,[],[question|_]} ->
io:format("b -- left\nn -- rotate\nm -- right\nspace -- drop\n"),
loop(W, Bit, State);
Any ->
io:format("? for help\n"),
loop(W, Bit, State)
end.
Mar 14, 2008
CS is not C and Java.
Mar 14, 2008
F#
Mar 14, 2008
Functional programming is based on a simple computation model with
three constructions: variables, function
definitions, and applications of a function to an argument. This model
is called the l-calculus and it was
introduced by Alonzo Church in 1932, thus before the first computer.
It was created to offer a general
theoretical model of the notion of computability. In the l-calculus,
all functions are values which can be
manipulated. They can be used as arguments to other functions, or
returned as the result of a call to another
function. The theory of l-calculus asserts that everything which is
computable (i.e., programmable) can be
written in this formalism. Its syntax is too limited to make its use
as a programming language practical, so
primitive values (such as integers or character strings), operations
on these primitive values, control
structures, and declarations which allow the naming of values or
functions and, in particular, recursive
functions, have all been added to the l-calculus to make it more palatable.
Mar 14, 2008
Unit
The unit type describes a set which possesses only a single element,
denoted: ().
# () ;;
- : unit = ()
Mar 14, 2008
# 1 :: 2 :: 3 :: [] ;;
- : int list = [1; 2; 3]
Mar 14, 2008
# [ 1 ] @ [ 2 ; 3 ] ;;
- : int list = [1; 2; 3]
Mar 14, 2008
# if 3=4 then 0 else "4";;
Characters 20-23:
This expression has type string but is here used with type int
Mar 14, 2008
A local declaration is an expression and can thus be used to construct
other expressions:
# (let x = 3 in x * x) + 1 ;;
- : int = 10
Mar 14, 2008
The number of arguments of a function is called its arity.
Mar 14, 2008
Closure
Objective CAML treats a function expression like any other expression
and is able to compute its value. The
value returned by the computation is a function expression and is
called a closure. Every Objective CAML
expression is evaluated in an environment consisting of name-value
bindings coming from the declarations
preceding the expression being computed. A closure can be described as
a triplet consisting of the name of the
formal parameter, the body of the function, and the environment of the
expression. This environment needs to be
preserved because the body of a function expression may use, in
addition to the formal parameters, every other
variable declared previously. These variables are said to be ``free''
in the function expression. Their values
will be needed when the function expression is applied.
Mar 14, 2008
# let g = function x -> function y -> 2*x + 3*y ;;
val g : int -> int -> int = <fun>
# let g = function x y -> 2*x + 3*y ;;
val g : int -> int -> int = <fun>
Mar 14, 2008
# ( + ) ;;
- : int -> int -> int = <fun>
# let succ = ( + ) 1 ;;
val succ : int -> int = <fun>
# succ 3 ;;
- : int = 4
Mar 14, 2008
# let ( ++ ) c1 c2 = (fst c1)+(fst c2), (snd c1)+(snd c2) ;;
val ++ : int * int -> int * int -> int * int = <fun>
# let c = (2,3) ;;
val c : int * int = 2, 3
# c ++ c ;;
- : int * int = 4, 6
Mar 14, 2008
There is an important limitation on the possible operators. They must
contain only symbols (such as *, +, @,
etc. ) and not letters or digits. Certain functions predefined as
infixes are exceptions to the rule. They are
listed as follows: or mod land lor lxor lsl lsr asr.
Mar 14, 2008
In Objective CAML, variables are statically bound. The environment
used to execute the application of a closure
is the one in effect at the moment of its declaration (static scope)
and not the one in effect at the moment of
application (dynamic scope).
Mar 14, 2008
Objective CAML generates parameterized types for every function which
doesn't use the form of its arguments.
This polymorphism is called parametric polymorphism.
Mar 14, 2008
# let mk_mult_fun_list n =
let rec mmfl_aux p =
if p = n then [ ( * ) n ]
else (( * ) p) :: (mmfl_aux (p+1))
in (mmfl_aux 1) ;;
val mk_mult_fun_list : int -> (int -> int) list = <fun>
Mar 14, 2008
# let rec fold_left f a l =
if null l then a
else fold_left f ( f a (List.hd l)) (List.tl l) ;;
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
# let sum_list = fold_left (+) 0 ;;
val sum_list : int list -> int = <fun>
# sum_list [2;4;7] ;;
- : int = 13
# let concat_list = fold_left (^) "" ;;
val concat_list : string list -> string = <fun>
# concat_list ["Hello "; "world" ; "!"] ;;
- : string = "Hello world!"
Mar 14, 2008
# let is_a_vowel c = match c with
'a' | 'e' | 'i' | 'o' | 'u' | 'y' -> true
| _ -> false ;;
val is_a_vowel : char -> bool = <fun>
Mar 14, 2008
# let eq_rat cr = match cr with
((_,0),(_,0)) -> true
| ((_,0),_) -> false
| (_,(_,0)) -> false
| ((n1,1), (n2,1)) when n1 = n2 -> true
| ((n1,d1), (n2,d2)) when ((n1 * d2) = (n2 * d1)) -> true
| _ -> false;;
val eq_rat : (int * int) * (int * int) -> bool = <fun>
Mar 16, 2008
/* Now for the BIG LOOP. */
Mar 21, 2008
Install PostgreSQL on Ubuntu 7.10
This quick walk-through are my notes for installing the PostgreSQL
database server and the PgAdmin administration application on Ubuntu
Linux, and also set up the server so it allows access to other PC's on
your network.
Before we move on, this guide was tested on the current release of
Ubuntu Linux, (7.10 - Gutsy Gibbon) and PostgreSQL 8.2, but it should
also be applicable to older versions (of Ubuntu and PostgreSQL) and
other Debian based distros.
Right for the basic installation, at the command-line, enter the
following commands (or search for the listed packages in synaptic if
you prefer that way of working):
$ sudo apt-get install postgresql postgresql-client postgresql-contrib
$ sudo apt-get install pgadmin3
This installs the database server/client, some extra utility scripts
and the pgAdmin GUI application for working with the database.
Now we need to reset the password for the 'postgres' admin account for
the server, so we can use this for all of the system administration
tasks. Type the following at the command-line (substitute in the
password you want to use for your administrator account):
$ sudo su postgres -c psql template1
template1=# ALTER USER postgres WITH PASSWORD 'password';
template1=# \q
That alters the password for within the database, now we need to do
the same for the unix user 'postgres':
$ sudo passwd -d postgres
$ sudo su postgres -c passwd
Now enter the same password that you used previously.
Then, from here on in we can use both pgAdmin and command-line access
(as the postgres user) to run the database server. But before you jump
into pgAdmin we should set-up the PostgreSQL admin pack that enables
better logging and monitoring within pgAdmin. Run the following at the
command-line:
$ sudo su postgres -c psql < /usr/share/postgresql/8.2/contrib/adminpack.sql
Finally, we need to open up the server so that we can access and use
it remotely - unless you only want to access the database on the local
machine. To do this, first, we need to edit the postgresql.conf file:
$ sudo gedit /etc/postgresql/8.2/main/postgresql.conf
Now, to edit a couple of lines in the 'Connections and Authentication' section…
Change the line:
#listen_addresses = 'localhost'
to
listen_addresses = '*'
and also change the line:
#password_encryption = on
to
password_encryption = on
Then save the file and close gedit.
Now for the final step, we must define who can access the server. This
is all done using the pg_hba.conf file.
$ sudo gedit /etc/postgresql/8.2/main/pg_hba.conf
Comment out, or delete the current contents of the file, then add this
text to the bottom of the file:
1 # DO NOT DISABLE!
2 # If you change this first entry you will need to make sure that the
3 # database
4 # super user can access the database using some other method.
5 # Noninteractive
6 # access to all databases is required during automatic maintenance
7 # (autovacuum, daily cronjob, replication, and similar tasks).
8 #
9 # Database administrative login by UNIX sockets
10 local all postgres ident sameuser
11 # TYPE DATABASE USER CIDR-ADDRESS METHOD
12
13 # "local" is for Unix domain socket connections only
14 local all all md5
15 # IPv4 local connections:
16 host all all 127.0.0.1/32 md5
17 # IPv6 local connections:
18 host all all ::1/128 md5
19
20 # Connections for all PCs on the subnet
21 #
22 # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
23 host all all [ip address] [subnet mask] md5
and in the last line, add in your subnet mask (i.e. 255.255.255.0) and
the IP address of the machine that you would like to access your
server (i.e. 138.250.192.115). However, if you would like to enable
access to a range of IP addresses, just substitute the last number for
a zero and all machines within that range will be allowed access
(i.e. 138.250.192.0 would allow all machines with an IP address
138.250.192.x to use the database server).
That's it, now all you have to do is restart the server:
$ sudo /etc/init.d/postgresql-8.2 restart
And all should be working.
没有评论:
发表评论
没事儿就省省吧, 有事儿请给我发邮件.