On 2006-04-28, Stuart Sierra wrote:
> Like a lot of other languages, Common Lisp uses the colon (:) as a
> scope-resolution operator.  FOO:BAR means the symbol named BAR in
> the package named FOO.  But one can also have FOO::BAR (two colons)
> and :BAR.  What's the difference?
>
> A Lisp package is a collection of symbols.  Some of those symbols
> are "exported," meaning they're meant to be used by functions in
> other packages.  Exported symbols are like public methods in an
> object-oriented language.  They're the public API that users of your
> package should follow.  "Unexported" symbols are like private
> methods or private member variables, except that in Lisp they're not
> really private.
>
> If (and only if) a symbol has been exported from a package, you can
> refer to it from another package with a single colon, e.g.
> PACKAGE:SYMBOL.  Trying to use an unexported symbol this way results
> in an error.

Another point about packages, though not specifically about colons: if
you find yourself naming a lot of functions or variables foo-this and
bar-that (e.g. mail-read, mail-send, mail-retrieve), this should
signal to you that these functions belong in their own package:
mail:read, mail:send, mail:retrieve.

I occasionally break this rule for symbols that would otherwise shadow
COMMON-LISP symbols, e.g. in Vim+ECL I have a Lisp function that
invokes a Vim function.  Initially I called it vim:funcall, but
decided that could easily lead to really stupid errors when working in
the VIM package itself, so I renamed it to vim:vim-funcall.

-- Larry


p.s. for you slim-vimmers: it looks like this:

  (in-package #:vim)
  (defun vim-funcall (function-name &rest args)
    (let ((cmd
            (format nil "~:[~A~;~(~A~)~](~#[~:;~{~A~#[~:;,~]~}~])"
                    (symbolp function-name)       ; used by ~:[~]
                    (string function-name)
                    (mapcar #'(lambda (x)
                                (typecase x
                                  (integer x)
                                  (t (format nil "~S" x))))
                            args))))
      ; (format t "vim-funcall: cmd is ~A~%" cmd)
      (expr cmd)
      ))

and allows you to say things like this

    (vim:vim-funcall 'cursor line column)
    (vim:vim-funcall 'search string flags)
    (vim:vim-funcall 'line expr)
    (vim:vim-funcall 'col expr)

Yes, I know, I should put this in my darcs repository.  Sorry.

-- L


_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners

Reply via email to