* How to write specify default values for function arguments?
@ 2002-10-01 18:45 gnuist006
2002-10-01 20:06 ` Tony
0 siblings, 1 reply; 3+ messages in thread
From: gnuist006 @ 2002-10-01 18:45 UTC (permalink / raw)
I am looking for multiple ways for
specifying default values for function arguments
as you can do in C++.
thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to write specify default values for function arguments?
2002-10-01 18:45 How to write specify default values for function arguments? gnuist006
@ 2002-10-01 20:06 ` Tony
2002-10-01 23:37 ` Kevin Rodgers
0 siblings, 1 reply; 3+ messages in thread
From: Tony @ 2002-10-01 20:06 UTC (permalink / raw)
"gnuist006" <gnuist006@hotmail.com> wrote in message
news:b00bb831.0210011045.5f29a1b4@posting.google.com...
> I am looking for multiple ways for
> specifying default values for function arguments
> as you can do in C++.
>
> thanks
use &optional, any parameters left out will be nil.
(defun foo (required-arg &optional opt1 opt2)
(unless opt1 (setq opt1 default-val-1))
(unless opt2 (setq opt2 default-val-2))
...)
-Tony
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to write specify default values for function arguments?
2002-10-01 20:06 ` Tony
@ 2002-10-01 23:37 ` Kevin Rodgers
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2002-10-01 23:37 UTC (permalink / raw)
Tony wrote:
> "gnuist006" <gnuist006@hotmail.com> wrote in message
> news:b00bb831.0210011045.5f29a1b4@posting.google.com...
>
>>I am looking for multiple ways for
>>specifying default values for function arguments
>>as you can do in C++.
>>
>>thanks
>>
>
> use &optional, any parameters left out will be nil.
>
> (defun foo (required-arg &optional opt1 opt2)
> (unless opt1 (setq opt1 default-val-1))
> (unless opt2 (setq opt2 default-val-2))
> ...)
Or do it the Common Lisp way:
(require 'cl)
(defun* foo (required-arg &optional (opt1 default-val-1) (opt2 default-val-2))
...)
--
<a href="mailto:<kevinr@ihs.com>">Kevin Rodgers</a>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-10-01 23:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-01 18:45 How to write specify default values for function arguments? gnuist006
2002-10-01 20:06 ` Tony
2002-10-01 23:37 ` Kevin Rodgers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).