* syntax? in scheme/Guile
@ 2024-05-13 8:42 Damien Mattei
2024-05-13 21:02 ` Damien Mattei
2024-05-13 23:42 ` Thompson, David
0 siblings, 2 replies; 4+ messages in thread
From: Damien Mattei @ 2024-05-13 8:42 UTC (permalink / raw)
To: guile-user
hello,
any idea for a predicate for syntax object in Guile/scheme like exist in
Racket 'syntax?' ?
i'm started writing something but i do not understand this part of R6RS:
https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.2
what examples can be done for :
-
-a nonpair, nonvector, nonsymbol value, or
-
-a wrapped syntax object.
- what is a wrapped syntax object?
Damien
-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: syntax? in scheme/Guile
2024-05-13 8:42 syntax? in scheme/Guile Damien Mattei
@ 2024-05-13 21:02 ` Damien Mattei
2024-05-13 23:42 ` Thompson, David
1 sibling, 0 replies; 4+ messages in thread
From: Damien Mattei @ 2024-05-13 21:02 UTC (permalink / raw)
To: guile-user
possible solution:
(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 >
;; scheme@(guile-user)> (syntax? #'(1 . 3))
;; $30 = #t
;; scheme@(guile-user)> (syntax? #'(1 2 3))
;; $28 = #t
;; scheme@(guile-user)> (syntax? #'*)
;; $23 = #t
;; scheme@(guile-user)> (syntax? 3)
;; $24 = #f
;; scheme@(guile-user)> (syntax? "")
;; $25 = #f
On Mon, May 13, 2024 at 10:42 AM Damien Mattei <damien.mattei@gmail.com>
wrote:
> hello,
>
> any idea for a predicate for syntax object in Guile/scheme like exist in
> Racket 'syntax?' ?
>
> i'm started writing something but i do not understand this part of R6RS:
>
> https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.2
>
> what examples can be done for :
>
> -
>
> -a nonpair, nonvector, nonsymbol value, or
> -
>
> -a wrapped syntax object.
> - what is a wrapped syntax object?
>
>
> Damien
>
>
>
> -
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: syntax? in scheme/Guile
2024-05-13 8:42 syntax? in scheme/Guile Damien Mattei
2024-05-13 21:02 ` Damien Mattei
@ 2024-05-13 23:42 ` Thompson, David
2024-05-14 7:39 ` Damien Mattei
1 sibling, 1 reply; 4+ messages in thread
From: Thompson, David @ 2024-05-13 23:42 UTC (permalink / raw)
To: Damien Mattei; +Cc: guile-user
Hi Damien,
On Mon, May 13, 2024 at 4:43 AM Damien Mattei <damien.mattei@gmail.com> wrote:
>
> any idea for a predicate for syntax object in Guile/scheme like exist in
> Racket 'syntax?' ?
This predicate is in the (system syntax) module in Guile.
> - what is a wrapped syntax object?
Syntax objects are part of the syntax-case procedural macro system. A
syntax object wraps a value with things like lexical context and
source location (when available).
For example:
scheme@(guile-user)> (call-with-input-string "(1 2 3)" read-syntax)
$16 = #<syntax:unknown file:1:0 (#<syntax:unknown file:1:1 1>
#<syntax:unknown file:1:3 2> #<syntax:unknown file:1:5 3>)>
See 6.8.3 Support for the ‘syntax-case’ System in the manual.
Hope this helps,
- Dave
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: syntax? in scheme/Guile
2024-05-13 23:42 ` Thompson, David
@ 2024-05-14 7:39 ` Damien Mattei
0 siblings, 0 replies; 4+ messages in thread
From: Damien Mattei @ 2024-05-14 7:39 UTC (permalink / raw)
To: Thompson, David; +Cc: guile-user
thank you Dave,
syntax? is enough for the operators like #'* #'+ etc that i need to test
(even if some complex syntax object are returned #f) :
scheme@(guile-user)> (use-modules (system syntax))
scheme@(guile-user)> syntax?
$1 = #<procedure syntax? (_)>
scheme@(guile-user)> (syntax? #'(2 * 3))
$2 = #f
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 *)
$5 = #<syntax:unknown file:8:8 *>
scheme@(guile-user)> (syntax? *)
$6 = #f
regards,
damien
On Tue, May 14, 2024 at 1:43 AM Thompson, David <dthompson2@worcester.edu>
wrote:
> Hi Damien,
>
> On Mon, May 13, 2024 at 4:43 AM Damien Mattei <damien.mattei@gmail.com>
> wrote:
> >
> > any idea for a predicate for syntax object in Guile/scheme like exist in
> > Racket 'syntax?' ?
>
> This predicate is in the (system syntax) module in Guile.
>
> > - what is a wrapped syntax object?
>
> Syntax objects are part of the syntax-case procedural macro system. A
> syntax object wraps a value with things like lexical context and
> source location (when available).
>
> For example:
>
> scheme@(guile-user)> (call-with-input-string "(1 2 3)" read-syntax)
> $16 = #<syntax:unknown file:1:0 (#<syntax:unknown file:1:1 1>
> #<syntax:unknown file:1:3 2> #<syntax:unknown file:1:5 3>)>
>
> See 6.8.3 Support for the ‘syntax-case’ System in the manual.
>
> Hope this helps,
>
> - Dave
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-14 7:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-13 8:42 syntax? in scheme/Guile Damien Mattei
2024-05-13 21:02 ` Damien Mattei
2024-05-13 23:42 ` Thompson, David
2024-05-14 7:39 ` Damien Mattei
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).