xach wrote
on February 17th, 2012 at 02:43 pm

Naming functions with keywords

I used to have a collection of miscellaneous utilities in a project named ZPB (after my initials). They weren't functions I used in actual source code, just little REPL conveniences, inspired in part by Rob Warnock's great suggestion to Use the Lisp environment to make your life easier!!

Even though the package prefix was short (zpb), I typed the stuff often enough that the prefix in the repl was annoying, but I didn't really want inherit everything with use-package, either. What to do?

Lately I've taken to sticking the functions in my startup file and naming them after keywords. For example:

(defun :go (&optional (thing *))
  "View THING with some appropriate viewer."
  ;; On my Mac laptop, I use "open" instead.
  (sb-ext:run-program "gnome-open" (list (princ-to-string thing))
                      :search t)
  thing)

With this in my startup file, I can do something like this:

* (url-of-interest object)
"http://twitter.com/quicklisp"

* (:go)
URL is opened in Chrome
"http://twitter.com/quicklisp"

These functions are short, easy to type, and always available in any REPL context regardless of the editor settings or current package. In addition to :go, I also have :file-string, :file-vector, :file-lines, :bits, :hex, :make-project, and a few others.

Do you define any shortcuts like this?
Tags:

(Read Comments)

No HTML allowed in subject

  
 
   
 

Notice! This user has turned on the option that logs your IP address when posting. 

(will be screened)

September 2014

S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930    
Powered by LiveJournal.com