> On Oct 18, 2017, at 12:53 AM, Konrad Hinsen <konrad.hin...@fastmail.net> > wrote: > > I needed to remove the first > element and add it in front of the others. On a plain list, I could do > this half asleep. But with the list wrapped in a syntax object, even > after considerable thought I am not sure what the best approach would > be. > > Unwrap (syntax->datum), apply list functions, rewrap? The resulting code > is not very readable, the wrapping stuff being much more visible than > the code that does the real work. Pattern match against (a b c ...)? OK > for this particular case, but not for the next case I knew I would > have to deal with.
The fandango associated with switching between syntaxed lists and lists of syntax can indeed be wearying. But this seems less like an issue intrinsic to `syntax-parse` and more like the irreducible complexity of living in a world where syntax objects are distinct things. (See also strings vs. paths and strings vs. symbols). If your goal is readable code, why not add some sugar? #lang racket/base (require (prefix-in rb: racket/base) rackunit) (define (length x) (cond [(and (syntax? x) (syntax->list x)) => length] [else (rb:length x)])) (check-equal? (length '(1 2 3)) 3) (check-equal? (length #'(1 2 3)) 3) (check-exn exn:fail:contract? (λ () (length 42))) (check-exn exn:fail:contract? (λ () (length #'42))) More broadly, it feels like there's plenty of room for new macro-definition and syntax-processing forms that suit different ergonomic needs: readability, automatic error messages, debugging, and so on. Interesting question why more of them don't exist. For `#lang br` I made a set that were designed for simplicity and readability. [1] [1] http://docs.racket-lang.org/br/index.html?q=br%2Fdefine#%28form._%28%28lib._br%2Fdefine..rkt%29._define-macro%29%29 <http://docs.racket-lang.org/br/index.html?q=br/define#(form._((lib._br/define..rkt)._define-macro))> -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.