This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: no class-of ?


On a somewhat related note, is there a way to define a macro that can
determine the type of an expression at macro expansion time, without
actually evaluating the expression?

I'd like to be able to do something along the lines of:


(define-syntax (ensure-boolean form)
  (syntax-case form ()
    ((_ expr)
     (let ((the-type (???? #'expr)))
       (cond ((eq? the-type boolean) #'expr)
             ((eq? the-type void)    #'(begin expr #t))
             ((eq? the-type int)     #'(= expr 0))
             (else (syntax-error "unsupported expression type")))))))


to be used as in:

(define (f x::double) ::boolean ...)
(define (g) ::int ...)
(define (h) ::void ...)

(list (ensure-boolean (let ((x 1.0)) (f x)))
      (ensure-boolean (g))
      (ensure-boolean (h)))

=>

(list (let ((x 1.0)) (f x))
      (= (g) 0)
      (begin (h) #t))

> On Sep 21, 2017, at 11:23 AM, Per Bothner <per@bothner.com> wrote:
> 
> On 09/21/2017 04:11 AM, Sonny To wrote:
>> there seems to be class-of function to get the type of the r-value of a symbol.
> 
> You can use the Java getClass method:
>  (VALUE:getClass)
> or:
>  (invoke VALUE 'getClass)
> or the "property" short-hand:
>  VALUE:class
> 
>> I'm not familiar with with the standard libraries of scheme and i'm
>> googling to get documentation and find various scheme documentation
>> from mit-scheme/racket/guile but are not available in kawa.
>> Is there a place where I can find a list of functions built into kawa?
> 
> The Kawa manual attempts to document all the Kawa functions.
> In the past I concentrated on documenting only Kawa extensions/differences
> from standard Scheme (so you needed to also have a copy of R5RS/R7RS), but
> I'm gradually making the Kawa manual more complete and self-contained.
> (There may still be some R7RS procedures missing, though.)
> 
> There are also some implemented SRFIs, not all of which are fully documented
> in the Kawa manual.  See:
>  https://www.gnu.org/software/kawa/Implemented-SRFIs.html
> 
> Of course all of the Java APIs are always available, by using Java
> method calls:
>  https://docs.oracle.com/javase/8/docs/api/overview-summary.html
> That is where you will find getClass documented:
>  https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--
> (the final '--' in the URL seems to be needed.)
> -- 
> 	--Per Bothner
> per@bothner.com   http://per.bothner.com/

--
Jamison Hope
The PTR Group
www.theptrgroup.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]