Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to calculate the number of arguments a function takes. (its arity).
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
WJ  
View profile  
 More options Apr 9 2012, 9:22 pm
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 10 Apr 2012 01:22:01 GMT
Local: Mon, Apr 9 2012 9:22 pm
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

> > 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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Apr 10 2012, 4:41 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 10 Apr 2012 08:41:30 GMT
Local: Tues, Apr 10 2012 4:41 am
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kodi...@eurogaran.com  
View profile  
 More options Apr 10 2012, 5:34 am
Newsgroups: comp.lang.lisp
From: kodi...@eurogaran.com
Date: Tue, 10 Apr 2012 02:34:38 -0700 (PDT)
Local: Tues, Apr 10 2012 5:34 am
Subject: Re: How to calculate the number of arguments a function takes. (its arity).
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?

Yes :
(defun cube (x) (* x x x)) -> cube
(second (function-lambda-expression (function cube))) -> (x)
(length (second (function-lambda-expression (function cube)))) -> 1

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ugih li  
View profile  
 More options Apr 10 2012, 7:09 am
Newsgroups: comp.lang.lisp
From: ugih li <free...@gmail.com>
Date: Tue, 10 Apr 2012 04:09:21 -0700 (PDT)
Local: Tues, Apr 10 2012 7:09 am
Subject: Re: How to calculate the number of arguments a function takes. (its arity).
On Apr 10, 5:34 pm, kodi...@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?

> Yes :
> (defun cube (x) (* x x x)) -> cube
> (second (function-lambda-expression (function cube))) -> (x)
> (length (second (function-lambda-expression (function cube)))) -> 1

Cool!
CL is the most COMMON lisp!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Elias Mårtenson  
View profile  
 More options Apr 11 2012, 10:56 am
Newsgroups: comp.lang.lisp
From: Elias Mårtenson <loke...@gmail.com>
Date: Wed, 11 Apr 2012 07:56:07 -0700 (PDT)
Local: Wed, Apr 11 2012 10:56 am
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

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?

> Yes :
> (defun cube (x) (* x x x)) -> cube
> (second (function-lambda-expression (function cube))) -> (x)
> (length (second (function-lambda-expression (function cube)))) -> 1

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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Apr 11 2012, 12:58 pm
Newsgroups: comp.lang.lisp
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Wed, 11 Apr 2012 18:58:10 +0200
Local: Wed, Apr 11 2012 12:58 pm
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

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?

>> Yes :
>> (defun cube (x) (* x x x)) -> cube
>> (second (function-lambda-expression (function cube))) -> (x)
>> (length (second (function-lambda-expression (function cube)))) -> 1

> 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.

Have a look at:
http://www.informatimago.com/develop/lisp/small-cl-pgms/ibcl/index.html

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Apr 22 2012, 6:33 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 22 Apr 2012 10:33:42 GMT
Local: Sun, Apr 22 2012 6:33 am
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

Racket:

> (procedure-arity modulo)

2

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Apr 16, 4:20 pm
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 16 Apr 2013 20:20:51 GMT
Local: Tues, Apr 16 2013 4:20 pm
Subject: Re: How to calculate the number of arguments a function takes. (its arity).

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »