From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Per Bothner <per@bothner.com>
Cc: kawa@sourceware.org
Subject: Re: Kawa evaluation process
Date: Tue, 28 Jun 2022 08:17:09 +0200 [thread overview]
Message-ID: <CAMFYt2a+dmZAmgSdLJd6E7SWYCdHxjy0GmdofrUaUTMF+HAJiQ@mail.gmail.com> (raw)
In-Reply-To: <cf5a819e-daa6-2b0a-46cf-5126f3061d25@bothner.com>
Thanks for the quick response!
wt., 28 cze 2022 o 07:20 Per Bothner <per@bothner.com> napisał(a):
>
>
> On 6/27/22 21:54, Panicz Maciej Godek via Kawa wrote:
> > So I've been wondering if there's an option to create a "box" that would
> be
> > transparent to the process of evaluation (possibly with some tweaks to
> > Kawa): that I would have an object that holds a string and a value, and
> > when the evaluator asks it for the value, it would provide whatever value
> > would result from parsing the string?
>
> Wel, we mostly have that. Every atom (almost - see below) appears as the
> car of a cons cell in a list. So we can associate extra information with
> the Pair. Since Pair is a class you can inherit from, you can create
> subclass of Pair with extra information.
This sounds great!
Actually, I already have a subclass of Pair (because Kawa pairs failed to
work with Java's weak hash tables, because of their identity function):
https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/primitive.scm#L33
so what I think I can do is override the getCar and getCdr methods, so that
- if the item held by them is an atom - they would return that atom's
value. (I think it makes sense)
> This is how line number information
> is handled in Kawa - see the PairWithPosition class.
>
> Note a PairWithPosition can specify a range in a sourcefile, which gives
> you
> the actual source string for the atom. The comments in the file hint at
> generalizing the filename/position pair to use a general
> gnu.text.SourceMapper.
> Or you can you can create new subclasses of PairWithPosition.
>
>
That's good to know.
I actually haven't been using PairWithPosition (or subclassing, for that
matter).
Instead, I've been using weak-key hash tables representing spaces before
head, after head,
before (dotted) tail and after tail, and some other properties:
https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/space.scm#L370
I guess that subclassing would result in more efficient code (but I don't
know if I'd be able to change it quickly at this point)
I also wrote my own parser that uses this representation
https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/parse.scm
but I wonder if I could somehow piggyback on your parser to parse atoms?
(I mean something like (call-with-input-string <input> read), but perhaps a
bit more low-level,
because at that point we already know that the thing we're reading isn't a
list)
There are some limitations to the atom/car-of-Pair identity. One is
> in the case of an impure list (dotted pair) - which isn't valid in source
> code
> anyway except inside quotes. Another limitation is for atoms that are
> top-level forms.
> Kawa handles that by wrapping such an atom in a fake begin list - see
> gnu/kawa/lispexpr/LispReader.java line 503.
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>
prev parent reply other threads:[~2022-06-28 6:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 4:54 Panicz Maciej Godek
2022-06-28 5:19 ` Per Bothner
2022-06-28 6:17 ` Panicz Maciej Godek [this message]
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=CAMFYt2a+dmZAmgSdLJd6E7SWYCdHxjy0GmdofrUaUTMF+HAJiQ@mail.gmail.com \
--to=godek.maciek@gmail.com \
--cc=kawa@sourceware.org \
--cc=per@bothner.com \
/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).