Re: syntax? in scheme/Guile

Damien Mattei <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <CADEOadcbcHjXvCL1BXb00CWKxkJx3_DjoYN6GYtnGst1eop_pw@mail.gmail.com>
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 <[email protected]>
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
>
>
>
>    -
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.