N Best Programming Techniques
From Compsci.ca Wiki
(Difference between revisions)
(→Erlang) |
(→Common Lisp (destructuring-bind)) |
||
| Line 21: | Line 21: | ||
==Common Lisp (destructuring-bind)== | ==Common Lisp (destructuring-bind)== | ||
| + | |||
| + | <pre>[1]> (defun foo (a-list) | ||
| + | (destructuring-bind (a &rest b) a-list | ||
| + | (list a b))) | ||
| + | FOO | ||
| + | [2]> (foo '(1 2 3 4)) | ||
| + | (1 (2 3 4)) | ||
| + | [3]></pre> | ||
| + | |||
==Erlang== | ==Erlang== | ||
<pre>-module(example). | <pre>-module(example). | ||
Revision as of 04:17, 9 July 2006
Ten best programming techniques you're (probably) not using.
Contents |
Pattern matching
Common Lisp (destructuring-bind)
[1]> (defun foo (a-list)
(destructuring-bind (a &rest b) a-list
(list a b)))
FOO
[2]> (foo '(1 2 3 4))
(1 (2 3 4))
[3]>
Erlang
-module(example).
-export(hello/1]).
hello("wtd") ->
io:format("Hello, ~s!~n", [Name]);
hello(Name) ->
io:format("Get out!!~n", []).