• Re: CL vs scheme macros, namespaces.

    From B. Pym@21:1/5 to All on Wed Jul 3 11:58:56 2024
    To take a simple example:

    (define-syntax -->
    (syntax-rules ()
    ((_ . original)
    (-->helper () original))))

    (define-syntax -->helper
    (syntax-rules ()
    ((_ pairs (x0 y0 . more))
    (-->helper ((x0 y0) . pairs) more))
    ((_ pairs body)
    (let pairs . body))))



    (defmacro --> (&rest [var-val]*-body)
    `(let ,(loop for (var val) on (butlast [var-val]*-body) by (function cddr)
    collect (list var val))
    ,@(last [var-val]*-body)))

    The helper macro isn't needed.

    Scheme (Gauche and Racket):

    The goal is a let-macro that doesn't need parentheses
    around the bindings. Only one expression is allowed
    after the bindings.


    (define-syntax -->
    (syntax-rules ()
    [ (_ ((k v) ...) expr)
    (let ((k v) ...) expr) ]
    [ (_ ((k v) ...) a b . more)
    (--> ((k v) ... (a b)) . more) ]
    [ (_ a b c more ...)
    (--> () a b c more ...) ]))

    a 2 m 44 z 88 (print (list a m z)))
    ===>
    (2 44 88)

    a 2 m 44 z 88 )
    ===>
    ; stdin:10:0: -->: bad syntax
    ; in: (--> ((a 2) (m 44) (z 88)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Wed Jul 3 14:10:10 2024
    On 2024-07-03, B. Pym <No_spamming@noWhere_7073.org> wrote:
    The helper macro isn't needed.

    Scheme (Gauche and Racket):

    The goal is a let-macro that doesn't need parentheses
    around the bindings. Only one expression is allowed
    after the bindings.

    (define-syntax -->
    (syntax-rules ()
    [ (_ ((k v) ...) expr)
    (let ((k v) ...) expr) ]
    [ (_ ((k v) ...) a b . more)
    (--> ((k v) ... (a b)) . more) ]
    [ (_ a b c more ...)
    (--> () a b c more ...) ]))

    That's stupid; just make it so the wrapping is not allowed,
    rather than optional:

    (defmacro flat (. bindings-and-expr)
    (tree-case bindings-and-expr
    ((expr) expr)
    ((k v . rest) ^(let ((,k ,v)) (flat ,*rest)))
    (x (error "flat: bad syntax"))))

    (flat 3)
    3
    (flat x 1 x)
    1
    (flat x 1 y 2 (+ x y))
    3
    (flat x 1 y 2 4 (+ x y))
    ** flat: bad syntax
    ** during evaluation at expr-1:6 of form (error "flat: bad syntax")
    (flat x 1)
    ** flat: bad syntax
    ** during evaluation at expr-1:6 of form (error "flat: bad syntax")
    (flat)
    ** flat: bad syntax
    ** during evaluation at expr-1:6 of form (error "flat: bad syntax")

    a 2 m 44 z 88 (print (list a m z)))

    (2 44 88)

    a 2 m 44 z 88 )

    ; stdin:10:0: -->: bad syntax
    ; in: (--> ((a 2) (m 44) (z 88)))

    Wut? Your diagnostic is reported against something that the
    user didn't write, because it got normalized into
    the nested let-style syntax, which is supposd to be
    further processed.

    What is the point.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)