public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Jamison Hope <jrh@theptrgroup.com>
To: Kawa mailing list <kawa@sourceware.org>
Subject: Re: no class-of ?
Date: Fri, 22 Sep 2017 18:29:00 -0000	[thread overview]
Message-ID: <425B3BC8-31F3-4299-ADB1-9E064C1E8D3E@theptrgroup.com> (raw)
In-Reply-To: <a310b637-e22a-4252-632f-14e9b347bf6d@bothner.com>

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

  reply	other threads:[~2017-09-22 18:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-21 11:11 Sonny To
2017-09-21 15:24 ` Per Bothner
2017-09-22 18:29   ` Jamison Hope [this message]
2017-09-22 19:23     ` Per Bothner
2017-09-22 22:18       ` Jamison Hope
2017-09-22 22:26         ` Per Bothner
2017-09-23 14:31           ` Jamison Hope
2017-09-24 21:52             ` Per Bothner
2017-09-25 16:58               ` Jamison Hope
2017-09-25 17:19                 ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=425B3BC8-31F3-4299-ADB1-9E064C1E8D3E@theptrgroup.com \
    --to=jrh@theptrgroup.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).