public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: spellcard199 <spellcard199@protonmail.com>
To: "kawa@sourceware.org" <kawa@sourceware.org>
Subject: How to get the return type kawa would infer for an expression?
Date: Tue, 13 Aug 2019 20:48:00 -0000	[thread overview]
Message-ID: <WkbUUT3cN3h5rRCKbsS_jLkqIwVGXqnbENV_GjA_TrC14ae6Eka6SgBHD23y8AgVP4-px-n21rJJuT3jMyOkrEBwtesejj0CSW8iXGAQzhE=@protonmail.com> (raw)

Hello. I'm a beginner trying to make an emacs library called "geiser" to work with kawa and having access to the kawa's type inference could be useful for java completion and method arglist.

Is there a simple way to get the return type the compiler would infer for an expression? In the end I would like to obtain something like `(which-return-type-would-you-tell-for-this '(....))`.

I read in a past thread in the mailing list archive that the kind of type inference the kawa compiler does is based on "optimistic", not static type checking, but I think that's ok if the user is aware of it.

The reason I'm trying to avoid plain reflection on the sexp, like =(*:getMethods (*:getClass '(...)))=, is that the (...) form could have side effects the programmer may not want to trigger just to get completions.

P.S.

While I was trying to find this by myself I wrote the following copy/pasting from kawa source code and noticed that after `(gnu.expr.ModuleExp:evalToClass comp #!null)`
type warnings appear in the sourceMessages, so the compiler has to know something about types at that point. Maybe the answer to my question is near there?

#+BEGIN_SRC scheme
(let* ((code-str "(define (foobar x) (x:concat \"foobar\"))")
       (inp       (gnu.kawa.io.CharArrayInPort code-str))
       (messages  (gnu.text.SourceMessages))
       (s         (kawa.standard.Scheme))
       (env       (s:getEnvironment))
       (lexer     (s:getLexer inp messages))
       (ctx       (gnu.mapping.CallContext:getInstance))
       (out       (gnu.kawa.io.CharArrayOutPort))
       (opts      gnu.expr.Language:PARSE_IMMEDIATE)
       (comp      (s:parse lexer opts #!null)))

  ;; type warnings are not yet produced
  (display "msg-dbg-1:\n")
  (messages:printAll out 999)
  (out:flush)
  (display (java.lang.String (out:toCharArray)))
  (newline)

  (gnu.expr.ModuleExp:evalToClass comp #!null)

  ;; type warnings present
  (display "msg-dbg-2:\n")
  (messages:printAll out 999)
  (out:flush)
  (display (java.lang.String (out:toCharArray)))
  (newline))
#+END_SRC

                 reply	other threads:[~2019-08-13 20:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='WkbUUT3cN3h5rRCKbsS_jLkqIwVGXqnbENV_GjA_TrC14ae6Eka6SgBHD23y8AgVP4-px-n21rJJuT3jMyOkrEBwtesejj0CSW8iXGAQzhE=@protonmail.com' \
    --to=spellcard199@protonmail.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).