> > Is there a portable way to calculate a function's arity in CL? I've > > skimmed the CLtL2 book without success. I suppose it can't be done > > because a function can take optional arguments... I'm I missing > > something obvious?
> No, no portable way, but you could look at the source code of SLIME > and there at the definition of the ARGLIST function for the various > Lisps supported by SLIME. All of them provide one way or another to > access the lambda list of a function.
Since CL is not a Lisp, there is no portable way to do that.
Let's try it in a Lisp (NewLisp):
: (define (foo a b c) (* a b c))
(lambda (a b c) (* a b c))
: (nth 0 foo)
(a b c)
: (length (nth 0 foo))
3
Paul Graham, May 2001:
A hacker's language is terse and hackable. Common Lisp is not.
The good news is, it's not Lisp that sucks, but Common Lisp.
Historically, Lisp has been good at letting hackers have their
way. The political correctness of Common Lisp is an aberration.
Early Lisps let you get your hands on everything.
WJ wrote:
> > > Is there a portable way to calculate a function's arity in CL? I've > > > skimmed the CLtL2 book without success. I suppose it can't be done > > > because a function can take optional arguments... I'm I missing > > > something obvious?
> > No, no portable way, but you could look at the source code of SLIME > > and there at the definition of the ARGLIST function for the various > > Lisps supported by SLIME. All of them provide one way or another to > > access the lambda list of a function.
> Since CL is not a Lisp, there is no portable way to do that.
> Let's try it in a Lisp (NewLisp):
> : (define (foo a b c) (* a b c))
> (lambda (a b c) (* a b c))
> : (nth 0 foo)
> (a b c)
> : (length (nth 0 foo))
> 3
> Paul Graham, May 2001:
> A hacker's language is terse and hackable. Common Lisp is not.
> The good news is, it's not Lisp that sucks, but Common Lisp.
> Historically, Lisp has been good at letting hackers have their
> way. The political correctness of Common Lisp is an aberration.
> Early Lisps let you get your hands on everything.
Clojure:
user=> (defn f [a b c] (list c b a))
#'user/f
user=> (:arglists (meta #'f))
([a b c])
user=> (count (first (:arglists (meta #'f))))
3
El martes, 10 de abril de 2012 03:22:01 UTC+2, WJ escribió:
> > > Is there a portable way to calculate a function's arity in CL? I've > > > skimmed the CLtL2 book without success. I suppose it can't be done > > > because a function can take optional arguments... I'm I missing > > > something obvious?
> El martes, 10 de abril de 2012 03:22:01 UTC+2, WJ escribió:
> > > > Is there a portable way to calculate a function's arity in CL? I've
> > > > skimmed the CLtL2 book without success. I suppose it can't be done
> > > > because a function can take optional arguments... I'm I missing
> > > > something obvious?
On Tuesday, 10 April 2012 17:34:38 UTC+8, kod...@eurogaran.com wrote:
> El martes, 10 de abril de 2012 03:22:01 UTC+2, WJ escribió:
> > > > Is there a portable way to calculate a function's arity in CL? I've > > > > skimmed the CLtL2 book without success. I suppose it can't be done > > > > because a function can take optional arguments... I'm I missing > > > > something obvious?
Except of course that it's not portable, as an implementation has the right to let FUNCTION-LAMBDA-EXPRESSION always return NIL,T,NIL for any function.
Elias Mårtenson <loke...@gmail.com> writes:
> On Tuesday, 10 April 2012 17:34:38 UTC+8, kod...@eurogaran.com wrote:
>> El martes, 10 de abril de 2012 03:22:01 UTC+2, WJ escribió:
>> > > > Is there a portable way to calculate a function's arity in CL? I've >> > > > skimmed the CLtL2 book without success. I suppose it can't be done >> > > > because a function can take optional arguments... I'm I missing >> > > > something obvious?
> Except of course that it's not portable, as an implementation has the right to let FUNCTION-LAMBDA-EXPRESSION always return NIL,T,NIL for any function.
WJ wrote:
> > > Is there a portable way to calculate a function's arity in CL? I've > > > skimmed the CLtL2 book without success. I suppose it can't be done > > > because a function can take optional arguments... I'm I missing > > > something obvious?
> > No, no portable way, but you could look at the source code of SLIME > > and there at the definition of the ARGLIST function for the various > > Lisps supported by SLIME. All of them provide one way or another to > > access the lambda list of a function.
> Since CL is not a Lisp, there is no portable way to do that.
> Let's try it in a Lisp (NewLisp):
> : (define (foo a b c) (* a b c))
> (lambda (a b c) (* a b c))
> : (nth 0 foo)
> (a b c)
> : (length (nth 0 foo))
> 3
> Paul Graham, May 2001:
> A hacker's language is terse and hackable. Common Lisp is not.
> The good news is, it's not Lisp that sucks, but Common Lisp.
> Historically, Lisp has been good at letting hackers have their
> way. The political correctness of Common Lisp is an aberration.
> Early Lisps let you get your hands on everything.
WJ wrote:
> > > Is there a portable way to calculate a function's arity in CL? I've > > > skimmed the CLtL2 book without success. I suppose it can't be done > > > because a function can take optional arguments... I'm I missing > > > something obvious?
> > No, no portable way, but you could look at the source code of SLIME > > and there at the definition of the ARGLIST function for the various > > Lisps supported by SLIME. All of them provide one way or another to > > access the lambda list of a function.
> Since CL is not a Lisp, there is no portable way to do that.
> Let's try it in a Lisp (NewLisp):
> : (define (foo a b c) (* a b c))
> (lambda (a b c) (* a b c))
> : (nth 0 foo)
> (a b c)
> : (length (nth 0 foo))
> 3
> Paul Graham, May 2001:
> A hacker's language is terse and hackable. Common Lisp is not.
> The good news is, it's not Lisp that sucks, but Common Lisp.
> Historically, Lisp has been good at letting hackers have their
> way. The political correctness of Common Lisp is an aberration.
> Early Lisps let you get your hands on everything.
Instead of CL, tCL.
% proc foo {a b c d} {puts ok}
% foo 2 3 4 5
ok
% info args foo
a b c d