From: Damien Mattei <damien.mattei@oca.eu>
To: Per Bothner <per@bothner.com>, kawa <kawa@sourceware.org>
Subject: Re: syntax? in kawa/scheme
Date: Mon, 13 May 2024 22:36:28 +0200 [thread overview]
Message-ID: <a1cc2a84-ec29-48ab-9341-889eea2b0cf0@oca.eu> (raw)
In-Reply-To: <a3cdad62-c7ca-4fbc-93a1-f1365a239e06@bothner.com>
yes in kawa there is no difference in this example:
(equal? #'(1 2 3) '(1 2 3))
#t
i had written for scheme (guile) a predicate based on the parsing of
display of an object but it will not work with kawa:
(define (syntax? obj)
(cond ; a syntax object is:
((pair? obj) ; a pair of syntax objects,
(and (syntax? (car obj))
(syntax? (cdr obj))))
((list? obj)
(every syntax? obj))
((vector? obj) ; a vector of syntax objects
(every syntax? (vector->list obj)))
((string? obj) ; as i will use the string representation of object
#f)
;; parse the representation of object to search for #<syntax something>
(else (let* ((str-obj (format #f "~s" obj))
(lgt-str-obj (string-length str-obj))
(str-syntax "#<syntax")
(lgt-str-syntax (string-length str-syntax)))
(and (> lgt-str-obj lgt-str-syntax) ; first, length greater
(string=? (substring str-obj 0 lgt-str-syntax)
str-syntax) ; begin by "#<syntax"
(char=? #\> (string-ref str-obj (- lgt-str-obj 1)))))))) ; last
char is >
but in fact my problem is to test equality for 2 syntax object and i can
not use equal? :
#|kawa:34|# (equal? #'* #'*)
#f
but bound-identifier=?
#|kawa:35|# (bound-identifier=? #'* #'*)
#t
#|kawa:36|# (bound-identifier=? #'* #'-)
#f
my problem is to test equality for operators in a syntax parser
but this does not works for every syntax object:
#|kawa:38|# (bound-identifier=? #'(1 2 3) #'(1 2 3))
java.lang.RuntimeException: bound-identifier-? - argument is not an
identifier
at kawa.standard.syntax_error.error(syntax_error.java:55)
at kawa.lib.prim_imports.reportSyntaxError(prim_imports.scm:249)
at kawa.lib.std_syntax.isBoundIdentifier$Eq(std_syntax.scm:312)
at atInteractiveLevel-37.run(tty:38)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:290)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
at kawa.Shell.run(Shell.java:289)
at kawa.Shell.run(Shell.java:196)
at kawa.Shell.run(Shell.java:183)
at kawa.repl.processArgs(repl.java:724)
at kawa.repl.main(repl.java:830)
so i must check a difference between the syntax object that have in
their string representation #<syntax something > and others
Le 13/05/2024 à 16:59, Per Bothner a écrit :
> Ce message provient d’un expéditeur externe à l’université (adresse :
> per@bothner.com). Ne cliquez pas sur les liens et n’ouvrez pas les
> pièces jointes si vous ne connaissez pas l’expéditeur ou que vous
> n’êtes pas sûr du contenu. En cas de doute, merci de transférer le
> mail à abuse@univ-cotedazur.fr
>
>
> On 5/13/24 5:20 AM, Damien Mattei wrote:
>> hello,
>>
>> any idea for a predicate for syntax object in Kawa/scheme like exist
>> in Racket 'syntax?' ?
>
> One problem is that everything is a syntax object.
>
> You can check if an object implements kawa.lang.SyntaxForm, but other
> objects are
> also allowed in syntax values, if they don't need an explicit
> TemplateScope.
next prev parent reply other threads:[~2024-05-13 20:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-13 12:20 Damien Mattei
2024-05-13 14:59 ` Per Bothner
2024-05-13 20:36 ` Damien Mattei [this message]
2024-05-13 21:47 ` Per Bothner
2024-05-13 22:20 ` Damien Mattei
2024-05-14 7:48 ` Damien Mattei
2024-05-14 7:59 ` Damien Mattei
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=a1cc2a84-ec29-48ab-9341-889eea2b0cf0@oca.eu \
--to=damien.mattei@oca.eu \
--cc=Damien.MATTEI@univ-cotedazur.fr \
--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).