[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: syntax? in scheme/Guile
From: |
Damien Mattei |
Subject: |
Re: syntax? in scheme/Guile |
Date: |
Mon, 13 May 2024 23:02:52 +0200 |
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
>
>
>
> -
>
>