public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@oca.eu>
To: kawa@sourceware.org
Subject: Re: syntax? in kawa/scheme
Date: Tue, 14 May 2024 09:59:35 +0200	[thread overview]
Message-ID: <1606b6e6-89e6-450e-af41-de4e345fd388@oca.eu> (raw)
In-Reply-To: <fe17475e-ffea-496f-8aa8-453e5d7f2178@oca.eu>

i can do a minimal syntax check like this for operator (works also for 
procedures):

;; parse the representation of object to search for #<syntax something>
(define (syntax-check? obj)

   (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 >


#|kawa:57|# (syntax-check? #'cons)
#t
#|kawa:58|# (syntax-check? #'*)
#t
#|kawa:59|# (syntax-check? *)
#f


Le 14/05/2024 à 09:48, Damien Mattei a écrit :
> Ce message provient d’un expéditeur externe à l’université (adresse : 
> kawa-bounces+damien.mattei=unice.fr@sourceware.org). 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
>
> but in fact testing the string representation is enought for me as i 
> need only to test for operators such as #'* #'+....
>
> indeed only Racket has a good syntax? procedure:
>
> Welcome to DrRacket, version 8.12 [cs].
> Language: racket, with debugging; memory limit: 8192 MB.
>
> > (syntax? #'(2 * 3))
> #t
>
> someone answered me about syntax? for Guile being in (system syntax) 
> but it works well only on atomic expression:
>
> scheme@(guile-user)> (use-modules (system syntax))
> scheme@(guile-user)> syntax?
> $1 = #<procedure syntax? (_)>
> scheme@(guile-user)> (syntax? #'(2 * 3))
> $2 = #f
>
>
> this is not the good result (above)
>
> as:
>
> scheme@(guile-user)> #'(2 * 3)
> $3 = (#<syntax:unknown file:6:3 2> #<syntax:unknown file:6:5 *> 
> #<syntax:unknown file:6:7 3>)
> scheme@(guile-user)> (syntax? #'*)
> $4 = #t
>
> scheme@(guile-user)> (syntax? *)
> $6 = #f
>
>
> but if someone explain me how to  'check if an object implements 
> kawa.lang.SyntaxForm' i can do that?
>
> perheaps with an exception....
>
>
> Damien
>
> Le 14/05/2024 à 00:20, Damien Mattei a écrit :
>> Ce message provient d’un expéditeur externe à l’université (adresse : 
>> kawa-bounces+damien.mattei=unice.fr@sourceware.org). 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
>>
>> i modify a SRFI 105  curly infix parser to move some function towards 
>> macro, then to pre-parse the code on the fly at the pre-compil stage 
>> of the macro,then use the pre-parsed code in the expansion phase. 
>> Finally the run-time execution of the generated code will be faster 
>> as no parsing will be done at this run-time phase. (exmple : a 
>> mathematic formula is known and will not change at run-time ,the 
>> infix to prefix operator precedence algorithm can be applied before 
>> runtime) . Prior i parsed s-expr now it will be syntax expression, 
>> the logic is the same but the code will change, instead of procedure 
>> or quoted procedures or form it will be syntax objects. For the 
>> operator precedence i need to be able to compare equality of some 
>> operator in a syntaxic form (like #'*, #'+ etc...) I admit as there 
>> is no native curly-infix srfi 105 in kawa it is already done by a 
>> parser in command line. (this more easy in Guile but very few scheme 
>> implement SRFI 105 anyway so i will reuse this code in the future)
>>
>> Le 13/05/2024 à 23:47, 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 1:36 PM, Damien Mattei wrote:
>>>> but in fact my problem is to test equality for 2 syntax object and 
>>>> i can not use equal? :
>>>
>>> Why? What are you actually trying to do?

      reply	other threads:[~2024-05-14  7:59 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
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 [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=1606b6e6-89e6-450e-af41-de4e345fd388@oca.eu \
    --to=damien.mattei@oca.eu \
    --cc=Damien.MATTEI@univ-cotedazur.fr \
    --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).