Tutorial by Examples

In some places in Common Lisp, a series of forms are evaluated in order. For instance, in the body of a defun or lambda, or the body of a dotimes. In those cases, writing multiple forms in order works as expected. In a few places, however, such as the then and else parts of an if expressions, onl...
The general purpose special operator progn is used for evaluating zero or more forms. The value of the last form is returned. For instance, in the following, (print 'hello) is evaluated (and its result is ignored), and then 42 is evaluated and its result (42) is returned: (progn (print 'hello...
Often times, it is helpful to evaluate multiple expressions and to return the result from the first or second form rather than the last. This is easy to accomplish using let and, for instance: (let ((form1-result form1)) form2 form3 ;; ... form-n-1 form-n form1-result) Because...
The special operator block allows grouping of several Lisp forms (like an implicit progn) and it also takes a name to name the block. When the forms within the block are evaluated, the special operator return-from can be used to leave the block. For instance: (block foo (print 'hello) ; e...
For lots of control in a group forms, the tagbody special operator can be very helpful. The forms inside a tagbody form are either go tags (which are just symbols or integers) or forms to execute. Within a tagbody, the go special operator is used to transfer execution to a new location. This type...
When writing macros that expand into forms that might involve grouping, it is worthwhile spending some time considering what grouping construction to expand into. For definition style forms, for instance, a define-widget macro that will usually appear as a top-level form, and that several defuns, d...

Page 1 of 1