SE701:Screencasts:scar107:OptionalParameters

From Marks Wiki
Revision as of 05:27, 3 November 2008 by Mark (talk | contribs) (3 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Can be downloaded from here. Note - new and improved! Well, kinda. It's still not particularly exciting, but I made the resolution bigger so it's easier to see/read. Ooooh!

Cheatsheet:

  • &optional: specifies that the following unnamed argument is optional
 (defun do-stuff (&optional on-something))
  • &key: specifies that the following argument is named
 (defun do-stuff (&key (thing "hello"))
  (print thing))
 
 (do-stuff :thing "nahhh")
  • &rest: specifies that a variable number of arguments should be assigned to a list in the following argument
 (make-list (&rest args)
  (for i in args do
   (print i)))

Choice!