So, after CLHS browsing and reading and banging my head against the
wall - my wife said I will have to stop that now the kids are about to
go to bed - I am resorting to admit that I just don't get it:
(defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
for SNACK called." )))
( "tile" #'(lambda ()
(format t "~%-> Function for TILE called." )))))
(defun %init-tk ()
(let ((packages-to-load *rwc*))
(dolist (package-load-info packages-to-load)
(let ((package (first package-load-info))
(init-fn (second package-load-info)))
(when package
(format t "~%Should load package \"~A\"." package))
(when init-fn
(pprint init-fn)
(funcall init-fn))))))
CL-USER 10 > (%init-tk)
Should load package "snack".
#'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
NIL (FORMAT T "~%-> Function for SNACK called."))).
Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
Let's test this:
CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
called.")))
FUNCTION
Okay. A Function is not a function. Now I give up. I *know* I am
missing something simple...
I better get some sleep... I just bet I wake up tomorrow morning and
have found a solution myself. -
I am sure I can take those PWUAHHAHAH posts a bit better ;-)
Thx guys! (Do we have any female here on that list anyway? - but that's
another story)
Frank
--
Frank Goenninger
frgo(at)goenninger(dot)net
"Don't ask me! I haven't been reading comp.lang.lisp long enough to
really know ..."
Frank Goenninger <····@goenninger.net> writes:
> So, after CLHS browsing and reading and banging my head against the wall
> - my wife said I will have to stop that now the kids are about to go to
> bed - I am resorting to admit that I just don't get it:
>
> (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
> for SNACK called." )))
The quoting is inhibiting the evaluation of #'
> (format t "~%-> Function for TILE called." )))))
>
> (defun %init-tk ()
> (let ((packages-to-load *rwc*))
> (dolist (package-load-info packages-to-load)
> (let ((package (first package-load-info))
> (init-fn (second package-load-info)))
> (when package
> (format t "~%Should load package \"~A\"." package))
> (when init-fn
> (pprint init-fn)
(type-of init-fn)
> (funcall init-fn))))))
>
> CL-USER 10 > (%init-tk)
>
> Should load package "snack".
> #'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
> Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
> NIL (FORMAT T "~%-> Function for SNACK called."))).
>
> Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
No. It's a LIST, the first element of which is the symbol FUNCTION.
> Let's test this:
>
> CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
> called.")))
> FUNCTION
>
> Okay. A Function is not a function. Now I give up. I *know* I am missing
> something simple...
There's an extra quote in your item above:
(type-of '#'(LAMBDA () (FORMAT T "~%-> Function for SNACK called.")))
of more directly:
(type-of (second '(first #'(lambda (x) x))))
compare with
(type-of (second (list 'first #'(lambda (x) x))))
--
Thomas A. Russ, USC/Information Sciences Institute
Frank Goenninger escribi�:
> So, after CLHS browsing and reading and banging my head against the wall
> - my wife said I will have to stop that now the kids are about to go to
> bed - I am resorting to admit that I just don't get it:
>
> (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
> for SNACK called." )))
> ( "tile" #'(lambda ()
> (format t "~%-> Function for TILE called." )))))
>
> (defun %init-tk ()
> (let ((packages-to-load *rwc*))
> (dolist (package-load-info packages-to-load)
> (let ((package (first package-load-info))
> (init-fn (second package-load-info)))
> (when package
> (format t "~%Should load package \"~A\"." package))
> (when init-fn
> (pprint init-fn)
> (funcall init-fn))))))
>
> CL-USER 10 > (%init-tk)
>
> Should load package "snack".
> #'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
> Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
> NIL (FORMAT T "~%-> Function for SNACK called."))).
>
> Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
> Let's test this:
>
> CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
> called.")))
> FUNCTION
>
> Okay. A Function is not a function. Now I give up. I *know* I am missing
> something simple...
> I better get some sleep... I just bet I wake up tomorrow morning and
> have found a solution myself. -
> I am sure I can take those PWUAHHAHAH posts a bit better ;-)
>
> Thx guys! (Do we have any female here on that list anyway? - but that's
> another story)
>
> Frank
>
Try this:
(defparameter *rwc*
`(( "snack" ,#'(lambda () (format t "~%-> Function for SNACK called." )))
( "tile" ,#'(lambda () (format t "~%-> Function for TILE
called." )))))
Leandro
Frank Goenninger <····@goenninger.net> writes:
> CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
> called.")))
> FUNCTION
>
> Okay. A Function is not a function. Now I give up. I *know* I am
> missing something simple...
aye.
you are asking the type of (FUNCTION (LAMBDA () ...)). the variable
INIT-FN, however, is getting bound to values that could be printed
like this: (QUOTE (FUNCTION (LAMBDA () ...))).
also, using "\"~A\"" in FORMAT in order to print a string is... not
quite stylish.
cheers,
--m
Frank Goenninger <····@goenninger.net> writes:
> (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
> for SNACK called." )))
The problem here is that you have quoted the whole list - so
#'(lambda()...) isn't a function, just a list with FUNCTION as its
first element... Try backquoting and put a comma before the #'!
--
(espen)
In article <···············@news.t-online.com>,
Frank Goenninger <····@goenninger.net> wrote:
> So, after CLHS browsing and reading and banging my head against the
> wall - my wife said I will have to stop that now the kids are about to
> go to bed - I am resorting to admit that I just don't get it:
>
> (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
> for SNACK called." )))
> ( "tile" #'(lambda ()
> (format t "~%-> Function for TILE called." )))))
>
> (defun %init-tk ()
> (let ((packages-to-load *rwc*))
> (dolist (package-load-info packages-to-load)
> (let ((package (first package-load-info))
> (init-fn (second package-load-info)))
> (when package
> (format t "~%Should load package \"~A\"." package))
> (when init-fn
> (pprint init-fn)
> (funcall init-fn))))))
>
> CL-USER 10 > (%init-tk)
>
> Should load package "snack".
> #'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
> Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
> NIL (FORMAT T "~%-> Function for SNACK called."))).
>
> Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
> Let's test this:
>
> CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
> called.")))
> FUNCTION
Others have explained the problem already.
A typical way to investigate those problems is to use
an inspector with the original data. If you type in some
similar data, it might be or might not be the really
helpful.
I would:
a) look at the object in the debugger. call DESCRIBE for
a first impression.
b) inspect the object from the debugger. Easy in LispWorks.
c) describe/inspect the data of the program. Just call
(DESCRIBE *rwc*) or (INSPECT *rwc*)
Here is an example interaction with the LispWorks TTY inspector:
CL-USER 31 > (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function for SNACK called." )))
( "tile" #'(lambda () (format t "~%-> Function for TILE called." )))))
*RWC*
CL-USER 32 > (inspect *rwc*)
(("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))) ("tile" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for TILE called."))))) is a LIST
0 ("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called."))))
1 ("tile" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for TILE called."))))
; just type the number to inspect deeper:
CL-USER 33 : Inspect 1 > 0
("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))) is a LIST
0 "snack"
1 (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
; now we get the FUNCTION form:
CL-USER 34 : Inspect 2 > 1
(FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called."))) is a LIST
0 FUNCTION
1 (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called."))
; it is a list?
; the special variable $ holds the current inspected object
CL-USER 35 : Inspect 3 > $
(FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
; type of the value of $ is?
CL-USER 36 : Inspect 3 > (type-of $)
CONS
; is it a function?
CL-USER 37 : Inspect 3 > (functionp $)
NIL
; return to the top-level loop and leave the inspector loop
CL-USER 38 : Inspect 3 > :q
(FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
From: Ken Tilton
Subject: Re: Easy one for you: Funcall secrets ... Mayday!
Date:
Message-ID: <XWWJi.183$B01.7@newsfe12.lga>
Rainer Joswig wrote:
> In article <···············@news.t-online.com>,
> Frank Goenninger <····@goenninger.net> wrote:
>
>
>>So, after CLHS browsing and reading and banging my head against the
>>wall - my wife said I will have to stop that now the kids are about to
>>go to bed - I am resorting to admit that I just don't get it:
>>
>>(defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
>>for SNACK called." )))
>> ( "tile" #'(lambda ()
>>(format t "~%-> Function for TILE called." )))))
>>
>>(defun %init-tk ()
>> (let ((packages-to-load *rwc*))
>> (dolist (package-load-info packages-to-load)
>> (let ((package (first package-load-info))
>> (init-fn (second package-load-info)))
>> (when package
>> (format t "~%Should load package \"~A\"." package))
>> (when init-fn
>> (pprint init-fn)
>> (funcall init-fn))))))
>>
>>CL-USER 10 > (%init-tk)
>>
>>Should load package "snack".
>>#'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
>>Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
>>NIL (FORMAT T "~%-> Function for SNACK called."))).
>>
>>Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
>>Let's test this:
>>
>>CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
>>called.")))
>>FUNCTION
>
>
> Others have explained the problem already.
But I think (did not really check too closely) they all suggested
backquote, which is fine but for someone struggling with these issues I
would suggest answers moving towards less not more syntax:
(list (list "snack" (lambda () ...yaddayadda)))
Not just in this situation, but as a rule when one gets stuck.
kt
--
http://www.theoryyalgebra.com/
"We are what we pretend to be." -Kurt Vonnegut
Ken Tilton <···········@optonline.net> writes:
> But I think (did not really check too closely) they all suggested
> backquote, which is fine but for someone struggling with these issues
> I would suggest answers moving towards less not more syntax:
>
> (list (list "snack" (lambda () ...yaddayadda)))
>
> Not just in this situation, but as a rule when one gets stuck.
I agree (although the unqouted lambda may or may not contribute to
the confusion). And in such a debugging situation it's also a good
idea to use the "Lego method": Try building up the bits and pieces
by hand, e.g start with the lambda and see what happens, and then
observe the difference:
INTL 38 > (lambda()(princ "I'm the lambda!")(terpri))
#<anonymous interpreted function 200A33AA>
INTL 39 > (funcall *)
I'm the lambda!
NIL
INTL 40 > (list "snack" **)
("snack" #<anonymous interpreted function 200A33AA>)
INTL 41 > '("snack" (lambda()(princ "I'm the lambda!")(terpri)))
("snack" (LAMBDA NIL (PRINC "I'm the lambda!") (TERPRI)))
--
(espen)
From: Ken Tilton
Subject: Re: Easy one for you: Funcall secrets ... Mayday!
Date:
Message-ID: <Dm8Ki.7$hP.3@newsfe12.lga>
Espen Vestre wrote:
> Ken Tilton <···········@optonline.net> writes:
>
>
>>But I think (did not really check too closely) they all suggested
>>backquote, which is fine but for someone struggling with these issues
>>I would suggest answers moving towards less not more syntax:
>>
>> (list (list "snack" (lambda () ...yaddayadda)))
>>
>>Not just in this situation, but as a rule when one gets stuck.
>
>
> I agree (although the unqouted lambda may or may not contribute to
> the confusion).
Well, I was going to add that as a second noob-educational rule: get
them off #'(lambda...) ASAP.
> And in such a debugging situation it's also a good
> idea to use the "Lego method": Try building up the bits and pieces
> by hand, e.g start with the lambda and see what happens, and then
> observe the difference:
Yep. Divide and conquer walk before you run baby steps. kt
>
> INTL 38 > (lambda()(princ "I'm the lambda!")(terpri))
> #<anonymous interpreted function 200A33AA>
>
> INTL 39 > (funcall *)
> I'm the lambda!
> NIL
>
> INTL 40 > (list "snack" **)
> ("snack" #<anonymous interpreted function 200A33AA>)
>
> INTL 41 > '("snack" (lambda()(princ "I'm the lambda!")(terpri)))
> ("snack" (LAMBDA NIL (PRINC "I'm the lambda!") (TERPRI)))
>
--
http://www.theoryyalgebra.com/
"We are what we pretend to be." -Kurt Vonnegut
On 2007-09-25 00:27:31 +0200, Rainer Joswig <······@lisp.de> said:
> In article <···············@news.t-online.com>,
> Frank Goenninger <····@goenninger.net> wrote:
>
>> So, after CLHS browsing and reading and banging my head against the
>> wall - my wife said I will have to stop that now the kids are about to
>> go to bed - I am resorting to admit that I just don't get it:
>>
>> (defparameter *rwc* '(( "snack" #'(lambda () (format t "~%-> Function
>> for SNACK called." )))
>> ( "tile" #'(lambda ()
>> (format t "~%-> Function for TILE called." )))))
>>
>> (defun %init-tk ()
>> (let ((packages-to-load *rwc*))
>> (dolist (package-load-info packages-to-load)
>> (let ((package (first package-load-info))
>> (init-fn (second package-load-info)))
>> (when package
>> (format t "~%Should load package \"~A\"." package))
>> (when init-fn
>> (pprint init-fn)
>> (funcall init-fn))))))
>>
>> CL-USER 10 > (%init-tk)
>>
>> Should load package "snack".
>> #'(LAMBDA () (FORMAT T "~%-> Function for SNACK called."))
>> Error: Argument to apply/funcall is not a function: (FUNCTION (LAMBDA
>> NIL (FORMAT T "~%-> Function for SNACK called."))).
>>
>> Arrghhh ... (FUNCTION ...) is /not/ a function!? Hunh?
>> Let's test this:
>>
>> CL-USER 11 > (type-of #'(LAMBDA () (FORMAT T "~%-> Function for SNACK
>> called.")))
>> FUNCTION
>
> Others have explained the problem already.
Yes. And I couldn't wait until next morning to see what I missed.
Thanks everybody!!!!
As for debugging approaches:
>
> A typical way to investigate those problems is to use
> an inspector with the original data. If you type in some
> similar data, it might be or might not be the really
> helpful.
>
> I would:
>
> a) look at the object in the debugger. call DESCRIBE for
> a first impression.
>
> b) inspect the object from the debugger. Easy in LispWorks.
>
> c) describe/inspect the data of the program. Just call
> (DESCRIBE *rwc*) or (INSPECT *rwc*)
Yes. That's what I did - inspecting it. And I looked at it but, hey, it
was right on the screen in front of me and still I did not see it. Why?
I am seriously asking this myself ...
>
> Here is an example interaction with the LispWorks TTY inspector:
>
> CL-USER 31 > (defparameter *rwc* '(( "snack" #'(lambda () (format t
> "~%-> Function for SNACK called." )))
> ( "tile" #'(lambda () (format t
> "~%-> Function for TILE called." )))))
> *RWC*
>
> CL-USER 32 > (inspect *rwc*)
>
> (("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK
> called.")))) ("tile" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for
> TILE called."))))) is a LIST
> 0 ("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for
> SNACK called."))))
> 1 ("tile" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for TILE
> called."))))
Ok. So far so good. That was known to me. Now for the new ones for me:
> ; just type the number to inspect deeper:
>
> CL-USER 33 : Inspect 1 > 0
>
> ("snack" (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK
> called.")))) is a LIST
> 0 "snack"
> 1 (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
>
>
> ; now we get the FUNCTION form:
>
> CL-USER 34 : Inspect 2 > 1
>
> (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called."))) is a LIST
> 0 FUNCTION
> 1 (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called."))
>
>
> ; it is a list?
> ; the special variable $ holds the current inspected object
>
> CL-USER 35 : Inspect 3 > $
> (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
>
>
> ; type of the value of $ is?
>
> CL-USER 36 : Inspect 3 > (type-of $)
> CONS
And that is what I did never get. I just was inspecting the wrong
place/form. Nice to know that navigation is easy enough in the
inspector.... I will be RTFM - promised.
>
> ; is it a function?
>
> CL-USER 37 : Inspect 3 > (functionp $)
> NIL
functionp now added as a safety measure in the code.
>
> ; return to the top-level loop and leave the inspector loop
>
> CL-USER 38 : Inspect 3 > :q
> (FUNCTION (LAMBDA NIL (FORMAT T "~%-> Function for SNACK called.")))
Thanks, Rainer, and all the others for once again showing in-depth
insight not only in the language but in mastering the tools at hand
also.
Frank - now really going to bed because that code of mine now crashes
somewhere in FFI land ..
--
Frank Goenninger
frgo(at)goenninger(dot)net
"Don't ask me! I haven't been reading comp.lang.lisp long enough to
really know ..."
In article <···············@news.t-online.com>,
Frank Goenninger <····@goenninger.net> wrote:
> As for debugging approaches:
> >
> > A typical way to investigate those problems is to use
> > an inspector with the original data. If you type in some
> > similar data, it might be or might not be the really
> > helpful.
> >
> > I would:
> >
> > a) look at the object in the debugger. call DESCRIBE for
> > a first impression.
> >
> > b) inspect the object from the debugger. Easy in LispWorks.
> >
> > c) describe/inspect the data of the program. Just call
> > (DESCRIBE *rwc*) or (INSPECT *rwc*)
>
> Yes. That's what I did - inspecting it. And I looked at it but, hey, it
> was right on the screen in front of me and still I did not see it. Why?
> I am seriously asking this myself ...
Btw., there is a variable in LispWorks.
LISPWORKS:*INSPECT-THROUGH-GUI*
With NIL you get the TTY inspector, with T you get the window-based
Inspector when you use the INSPECT function.