From: Foxpointe
Subject: Passing through multiple parameters
Date: 
Message-ID: <ArWdnVK3Do-9Q_LZRVn-gQ@comcast.com>
This is something I seem to keep bumping into and wanted to see if 
there's a better way or that's just the way it is: does shorthand exist 
to decompose a list to more directly pass as individual parameters to 
another expression?  For example, assuming a list of parameters, is 
there a more efficient way to do the following without needing 
first/second/third/etc:

(let ((ssparms `("want second item" 5 11)))
   (subseq (first ssparms) (second ssparms) (third ssparms)))

Thanks,
Phil

From: Rob Warnock
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <AKidnSFgiuGjf_LZnZ2dnUVZ_sydnZ2d@speakeasy.net>
Foxpointe  <·········@comcast.net> wrote:
+---------------
| ...is there a more efficient way to do the following without needing 
| first/second/third/etc:
| (let ((ssparms `("want second item" 5 11)))
|    (subseq (first ssparms) (second ssparms) (third ssparms)))
+---------------

Not sure about "more efficient" [that will depend on the specific
implementation, whether your code's compiled, etc.], but a more
idiomatic [and simpler] way, yes:

    (destructuring-bind (string start end)
	`("want second item" 5 11)
      (subseq string start end))


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Foxpointe
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <2vqdnT2Z3-7lcfLZnZ2dnUVZ_sOdnZ2d@comcast.com>
Rob Warnock wrote:
> Not sure about "more efficient" [that will depend on the specific
> implementation, whether your code's compiled, etc.], but a more
> idiomatic [and simpler] way, yes:
> 
>     (destructuring-bind (string start end)
> 	`("want second item" 5 11)
>       (subseq string start end))

I am aware of destructuring-bind but looking for something better as in 
this case it is a wash from an 'efficiency' standpoint (i.e. typing) and 
I had in mind something along the lines of (subseq (parms 3 `("want 
second item" 5 11)))  I suppose put another way, I'm looking for a sort 
of lambda to pass through parameters.

Thanks,
Phil
From: Rob Warnock
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <BdGdnWxY_oD-lu3ZnZ2dnUVZ_vSdnZ2d@speakeasy.net>
Foxpointe  <·········@comcast.net> wrote:
+---------------
| I had in mind something along the lines of (subseq (parms 3 `("want 
| second item" 5 11)))  I suppose put another way, I'm looking for a sort 
| of lambda to pass through parameters.
+---------------

    (apply 'subseq `("want second item" 5 11))


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Wade Humeniuk
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <OjSbg.25222$Fl1.24410@edtnps89>
Foxpointe wrote:
> This is something I seem to keep bumping into and wanted to see if 
> there's a better way or that's just the way it is: does shorthand exist 
> to decompose a list to more directly pass as individual parameters to 
> another expression?  For example, assuming a list of parameters, is 
> there a more efficient way to do the following without needing 
> first/second/third/etc:
> 
> (let ((ssparms `("want second item" 5 11)))
>   (subseq (first ssparms) (second ssparms) (third ssparms)))
> 

That would be apply, as in

CL-USER 1 > (apply 'subseq `("want second item" 5 11))
"second"

CL-USER 2 >

Wade
From: Foxpointe
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <deidnQ73Du73M-3ZRVn-uw@comcast.com>
Wade Humeniuk wrote:

> That would be apply, as in
> 
> CL-USER 1 > (apply 'subseq `("want second item" 5 11))
> "second"
> 
> CL-USER 2 >
> 
> Wade
> 

Ah... hadn't thought using apply for that purpose.  Unfortunately, I 
tried apply only to get an error indicating that the function couldn't 
be called via funcall or apply as I'm calling a function in an external 
library.  Is there a way around this problem?

Phil
From: Pascal Bourguignon
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <87psi79qym.fsf@thalassa.informatimago.com>
Foxpointe <·········@comcast.net> writes:

> Wade Humeniuk wrote:
>
>> That would be apply, as in
>> CL-USER 1 > (apply 'subseq `("want second item" 5 11))
>> "second"
>> CL-USER 2 >
>> Wade
>> 
>
> Ah... hadn't thought using apply for that purpose.  Unfortunately, I
> tried apply only to get an error indicating that the function couldn't
> be called via funcall or apply as I'm calling a function in an
> external library.  Is there a way around this problem?

ENOTENOUGHDATA

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

In a World without Walls and Fences, 
who needs Windows and Gates?
From: Foxpointe
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <_JGdnbFuON0RLO3ZnZ2dnUVZ_vednZ2d@comcast.com>
Pascal Bourguignon wrote:

> 
> ENOTENOUGHDATA
> 

I'm calling various OpenGL calls which are wrapped by reader macros. 
When I attempt to use apply I get the following:

Error in event loop: Special operator or global macro-function 
DARWIN32::|glColor3f| can't be FUNCALLed or APPLYed
From: Barry Margolin
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <barmar-BB8288.15391621052006@comcast.dca.giganews.com>
In article <································@comcast.com>,
 Foxpointe <·········@comcast.net> wrote:

> Pascal Bourguignon wrote:
> 
> > 
> > ENOTENOUGHDATA
> > 
> 
> I'm calling various OpenGL calls which are wrapped by reader macros. 
> When I attempt to use apply I get the following:
> 
> Error in event loop: Special operator or global macro-function 
> DARWIN32::|glColor3f| can't be FUNCALLed or APPLYed

You can only APPLY a function.  You're trying to apply a macro.

-- 
Barry Margolin, ······@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: Wade Humeniuk
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <G15cg.18289$zn1.18015@clgrps13>
Foxpointe wrote:
> Pascal Bourguignon wrote:
> 
>>
>> ENOTENOUGHDATA
>>
> 
> I'm calling various OpenGL calls which are wrapped by reader macros. 
> When I attempt to use apply I get the following:
> 
> Error in event loop: Special operator or global macro-function 
> DARWIN32::|glColor3f| can't be FUNCALLed or APPLYed

It would seem that |glColor3f| is a macro.  Which means you should
go and find the functional equivalent to this macro.  If you macroexpand
an example expression you will see what it is actually doing.  If the
macro is not doing very much you can call the actual function doing the
work of the macro.  I assume in this case |glColor3f| might be
creating a 3-float rgb value?  If this is the case why its a macro
escapes me.  Try the macro expansion to see what you get.

In LW there is an opengl in the examples dir.

(fli:define-foreign-function (gl-color3-f "glColor3f" :source)
     ((red glfloat) (green glfloat) (blue glfloat))
   :result-type :void
   :language :ansi-c)

CL-USER 4 > (describe 'opengl::gl-color3-f)

OPENGL:GL-COLOR3-F is a SYMBOL
NAME          "GL-COLOR3-F"
VALUE         #<unbound value>
FUNCTION      #<function OPENGL:GL-COLOR3-F 211FBF7A>
PLIST         (FLI::DEFINE-FOREIGN-FUNCTION-P T PKG::SYMBOL-NAME-STRING "GL-COLOR3-F")
PACKAGE       #<PACKAGE OPENGL>

CL-USER 5 >

In this case the func is a FFI.  Maybe in your Lisp you cannot funcall a
FFI (or maybe the FFI library you are using changes it to a macro)
To get around it, do

(defun my-glcolor3f (r g b) (darwin32::|glColor3f| r g b))

And then apply your my-glcolor3f to get around it.

Wade
From: Foxpointe
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <Fc6dnarbi6R0Hu_ZRVn-ug@comcast.com>
Wade Humeniuk wrote:

> 
> It would seem that |glColor3f| is a macro.  Which means you should
> go and find the functional equivalent to this macro.  If you macroexpand
> an example expression you will see what it is actually doing.  If the
> macro is not doing very much you can call the actual function doing the
> work of the macro.  I assume in this case |glColor3f| might be
> creating a 3-float rgb value?  If this is the case why its a macro
> escapes me.  Try the macro expansion to see what you get.
> 
> In LW there is an opengl in the examples dir.
> 
> (fli:define-foreign-function (gl-color3-f "glColor3f" :source)
>     ((red glfloat) (green glfloat) (blue glfloat))
>   :result-type :void
>   :language :ansi-c)
> 
> CL-USER 4 > (describe 'opengl::gl-color3-f)
> 
> OPENGL:GL-COLOR3-F is a SYMBOL
> NAME          "GL-COLOR3-F"
> VALUE         #<unbound value>
> FUNCTION      #<function OPENGL:GL-COLOR3-F 211FBF7A>
> PLIST         (FLI::DEFINE-FOREIGN-FUNCTION-P T PKG::SYMBOL-NAME-STRING 
> "GL-COLOR3-F")
> PACKAGE       #<PACKAGE OPENGL>
> 
> CL-USER 5 >
> 
> In this case the func is a FFI.  Maybe in your Lisp you cannot funcall a
> FFI (or maybe the FFI library you are using changes it to a macro)
> To get around it, do
> 
> (defun my-glcolor3f (r g b) (darwin32::|glColor3f| r g b))
> 
> And then apply your my-glcolor3f to get around it.
> 
> Wade

I appreciate everyone's thoughts on this.  For what I want to accomplish 
(a shorthand for transforming a list into parms), apply appears to the 
best bet with the exception of macros which I'll keep typing out.

It would be nice to have a macro perform this transformation in all 
cases but I can't see how that could work.

Phil
From: Thomas A. Russ
Subject: Re: Passing through multiple parameters
Date: 
Message-ID: <ymir72llxqo.fsf@sevak.isi.edu>
Foxpointe <·········@comcast.net> writes:

> This is something I seem to keep bumping into and wanted to see if
> there's a better way or that's just the way it is: does shorthand exist
> to decompose a list to more directly pass as individual parameters to
> another expression?  For example, assuming a list of parameters, is
> there a more efficient way to do the following without needing
> first/second/third/etc:
> 
> 
> (let ((ssparms `("want second item" 5 11)))
>    (subseq (first ssparms) (second ssparms) (third ssparms)))

Yes.  First of all reimplement SSPARMS to return multiple values instead
of a list of parameters.  Then you can use either something like
MULTIPLE-VALUE-BIND or MULTIPLE-VALUE-CALL to use the returned values.

For example:

(multiple-value-call #'subseq (ssparms `("want second item" 5 11)))

(multiple-value-bind (string start end)
     (ssparms `("want second item" 5 11))
  (subseq string start end))


-- 
Thomas A. Russ,  USC/Information Sciences Institute