Prev: Do as the Romans do
Next: managing large table of data
From: Zach Beane on 31 Jan 2010 19:07 slash dot <tyntyfax(a)gmail.com> writes: > On 1 Feb., 00:52, Zach Beane <x...(a)xach.com> wrote: >> slash dot <tynty...(a)gmail.com> writes: >> > lisp is famous for is reflection capabilities >> >> No, it's not. >> >> Zach > > So one cannot inspect a function, is that what's you're > saying, Zach? I'm saying Lisp is not famous for its reflection capabilities, and speculation based on assuming it is is bound to be faulty. Zach
From: slash dot on 31 Jan 2010 19:14 On 1 Feb., 01:07, Zach Beane <x...(a)xach.com> wrote: > slash dot <tynty...(a)gmail.com> writes: > > On 1 Feb., 00:52, Zach Beane <x...(a)xach.com> wrote: > >> slash dot <tynty...(a)gmail.com> writes: > >> > lisp is famous for is reflection capabilities > > >> No, it's not. > > >> Zach > > > So one cannot inspect a function, is that what's you're > > saying, Zach? > > I'm saying Lisp is not famous for its reflection capabilities, and > speculation based on assuming it is is bound to be faulty. > > Zach thanks... I was about to waste more time googling over this...
From: Paul Donnelly on 31 Jan 2010 20:02 slash dot <tyntyfax(a)gmail.com> writes: > lisp is famous for is reflection capabilities, and, > indeed, a function like '10+' is reported to be > > #<FUNCTION 10+ (NUMBER) (DECLARE (SYSTEM::IN-DEFUN 10+)) > (BLOCK 10+ (+ 10 NUMBER))> > > in clisp. > > (Disturbingly, this only works if I bind #'10+ to a variable and > evaluate > the variable, but that's a clisp implementation detail, right? RIGHT?) > > So my question is: how can I inspect functions to find out how > many arguments it has, for example? Isn't that the sort of thing you should already know?
From: Barry Margolin on 31 Jan 2010 20:20 In article <99200608-d39f-47ba-b5b3-35937ae46ba8(a)m16g2000yqc.googlegroups.com>, slash dot <tyntyfax(a)gmail.com> wrote: > lisp is famous for is reflection capabilities, and, > indeed, a function like '10+' is reported to be > > #<FUNCTION 10+ (NUMBER) (DECLARE (SYSTEM::IN-DEFUN 10+)) > (BLOCK 10+ (+ 10 NUMBER))> > > in clisp. > > (Disturbingly, this only works if I bind #'10+ to a variable and > evaluate > the variable, but that's a clisp implementation detail, right? RIGHT?) > > So my question is: how can I inspect functions to find out how > many arguments it has, for example? If (function-lambda-expression #'10+) returns non-NIL, the second element of the list will be the argument list. You'll have to parse the &keywords to turn this into a number of arguments. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal J. Bourguignon on 31 Jan 2010 22:09
slash dot <tyntyfax(a)gmail.com> writes: > lisp is famous for is reflection capabilities, and, > indeed, a function like '10+' is reported to be > > #<FUNCTION 10+ (NUMBER) (DECLARE (SYSTEM::IN-DEFUN 10+)) > (BLOCK 10+ (+ 10 NUMBER))> > > in clisp. > > (Disturbingly, this only works if I bind #'10+ to a variable and > evaluate > the variable, but that's a clisp implementation detail, right? RIGHT?) Wrong. C/USER[18]> (defun 10+ (NUMBER) (+ 10 number)) 10+ C/USER[19]> (function 10+) #<FUNCTION 10+ (NUMBER) (DECLARE (SYSTEM::IN-DEFUN 10+)) (BLOCK 10+ (+ 10 NUMBER))> C/USER[20]> (function-lambda-expression '10+) (LAMBDA (NUMBER) (DECLARE (SYSTEM::IN-DEFUN 10+)) (BLOCK 10+ (+ 10 NUMBER))) ; #(NIL NIL NIL NIL ((DECLARATION ALSO-USE-PACKAGES XLIB::CLX-VALUES VALUES OPTIMIZE DECLARATION))) ; 10+ C/USER[21]> (compile '10+) 10+ ; NIL ; NIL C/USER[22]> (function-lambda-expression '10+) (LAMBDA (NUMBER) (+ 10 NUMBER)) ; T ; 10+ C/USER[23]> (load (compile-file "/tmp/10.lisp")) ;; Compiling file /tmp/10.lisp ... ;; Wrote file /tmp/10.fas 0 errors, 0 warnings ;; Loading file /private/tmp/10.fas ... WARNING: DEFUN/DEFMACRO: redefining function 10+ in /private/tmp/10.fas, was defined in top-level ;; Loaded file /private/tmp/10.fas T C/USER[24]> (function-lambda-expression '10+) NIL ; T ; 10+ C/USER[25]> > So my question is: how can I inspect functions to find out how > many arguments it has, for example? 1 - As Zach indicated, it is not. 2 - As Barry indicated, the standard function to "inspect" functions is FUNCTION-LAMBDA-EXPRESSION, but since it's allowed to return NIL, see point 1. 3- However, thanks to the homoiconicity of lisp, you can easily implement the needed bookmarking yourself. See: http://www.informatimago.com/develop/lisp/small-cl-pgms/ibcl/ -- __Pascal Bourguignon__ |