From: Frank Goenninger DG1SBG
Subject: UNDEFINED-FUNCTION error on calling an interned function name from a string
Date:
Message-ID: <lzlkkud172.fsf@pcsde001.local>
Hi all:
Imagine the following lines of code:
(defun add-msgfield-u16 (msg field-name value)
(%tibrvMsg_AddU16 msg field-name value)) ;; FFI call to libtibrv.dylib
(defun intern$ (&rest strings) ;; courtesy Kenny Tilton ;-)
(intern (apply #'concatenate 'string strings)))
(defmethod add-msgfield ((self tibrv-msg) type name value)
(let ((type-str (subseq type 6)))
(funcall (intern$ "CL-TIBRV:ADD-MSGFIELD-" type-str) (^msg-id) name value)))
Now I want to do a call like
(add-msgfield "TIBRV_U16" 1009 "FIELD1" "1")
But hey, I get the following error:
attempt to call `|CL-TIBRV:ADD-MSGFIELD-U16|' which is an undefined
function.
[Condition of type UNDEFINED-FUNCTION]
I know it must be something simple <g> ! But what ???
Thanks for pointing me in the right direction ...
Frank
Frank Goenninger DG1SBG schrieb:
> Hi all:
>
> Imagine the following lines of code:
>
> (defun add-msgfield-u16 (msg field-name value)
> (%tibrvMsg_AddU16 msg field-name value)) ;; FFI call to libtibrv.dylib
>
> (defun intern$ (&rest strings) ;; courtesy Kenny Tilton ;-)
> (intern (apply #'concatenate 'string strings)))
>
> (defmethod add-msgfield ((self tibrv-msg) type name value)
> (let ((type-str (subseq type 6)))
> (funcall (intern$ "CL-TIBRV:ADD-MSGFIELD-" type-str) (^msg-id) name value)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This string gets interned in the current package. The intern function
takes a package name as second argument. You can define
intern$ then as:
(defun intern$ (package &rest strings)
(intern (apply #'concatenate 'string strings) package))
and use it:
(funcall (intern$ "CL-TIBRV" "ADD-MSGFIELD-" type-str) (^msg-id) name
value)
>
>
> Now I want to do a call like
>
> (add-msgfield "TIBRV_U16" 1009 "FIELD1" "1")
>
> But hey, I get the following error:
>
> attempt to call `|CL-TIBRV:ADD-MSGFIELD-U16|' which is an undefined
> function.
> [Condition of type UNDEFINED-FUNCTION]
>
> I know it must be something simple <g> ! But what ???
> Thanks for pointing me in the right direction ...
>
> Frank
From: Frank Goenninger DG1SBG
Subject: Re: UNDEFINED-FUNCTION error on calling an interned function name from a string
Date:
Message-ID: <lzmz5awhyr.fsf@pcsde001.local>
"hit_the_lights" <··········@gmx.at> writes:
> Frank Goenninger DG1SBG schrieb:
>
>> Hi all:
>>
>> Imagine the following lines of code:
>>
>> (defun add-msgfield-u16 (msg field-name value)
>> (%tibrvMsg_AddU16 msg field-name value)) ;; FFI call to libtibrv.dylib
>>
>> (defun intern$ (&rest strings) ;; courtesy Kenny Tilton ;-)
>> (intern (apply #'concatenate 'string strings)))
>>
>> (defmethod add-msgfield ((self tibrv-msg) type name value)
>> (let ((type-str (subseq type 6)))
>> (funcall (intern$ "CL-TIBRV:ADD-MSGFIELD-" type-str) (^msg-id) name value)))
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This string gets interned in the current package. The intern function
> takes a package name as second argument. You can define
> intern$ then as:
>
> (defun intern$ (package &rest strings)
> (intern (apply #'concatenate 'string strings) package))
>
> and use it:
>
> (funcall (intern$ "CL-TIBRV" "ADD-MSGFIELD-" type-str) (^msg-id) name
> value)
Which, of course, works fine. Thanks!!
Frank
--
Bempflingen
Germany