Re: optional arguments in CLush functions?

Ralf Juengling <[email protected]>
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Wed, 16 Nov 2005, Leon Bottou wrote:
> No the compiler does not support this.
>
>> 1. Is there any way, currently, to do what I want to do?
> Use the 'overload' facility...
> Exemple:
>
> (libload "overload")
> [overload.lsh]
> ? (de f1(a) ((-flt-) a) (* a a )))
> ? (de f2(a b) ((-flt-) a b) (+ (* a a)(* b b))))
> [...]
> ? (f 2)
> = 4
> ? (f 3 4)
> = 25

Thanks. While I've used overload before, it didn't occur to me
to use it for this situation. The downside of this approach
is that you probably need to duplicate code, though.


> Note that <f> compiles, but is slow in interpreted mode
> because it uses lisp code to match its arguments
> and their types.  When <f> is compiled, the
> overload resolution happens in the compiler...
>
>> 2. When you try to create a NULL ptr (a gptr object with
>>     value NULL) in lush, the result is nil. When the CLush
>>     compiler encounters a nil, it considers it a boolean
>>     value rather than a NULL pointer.
> Well, if you declare that the argument is a gptr, it will take it as a null pointer.

Ah, thanks.

> The problem is that you cannot declare that a variable can be either a null gptr, or another object.

Would the following work (I haven't tried)? 
Declare the optional arguments as gptrs. In the function, test if
gptr is NULL, if not NULL, cast to the expected type.


Thanks,
Ralf


> This is a limitation of the type system.  The overload facility suggests how we could
> handle this at compile time, but the type system in the compiler does not support this.
>
>> 3. Would it be possible to change the CLush compiler to
>>     make it accept a NULL ptr as arguments where the
>>     corresponding formal parameter is an object?
> Not without major redesign.
>
>
> - L.
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
> Register for a JBoss Training Course.  Free Certification Exam
> for All Training Attendees Through End of 2005. For more info visit:
> http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
> _______________________________________________
> Lush-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/lush-devel
>


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.