Den tor. 13. aug. 2020 kl. 21.55 skrev Kevin Forchione <[email protected]>:

> Hi guys,
>
> Pollen makes use of something like this:
>
> (require syntax/parse/define)
>
> (define-simple-macro (#%top . x) 'x)
>
>
> and it comes in handy in some of my projects. But I’m wondering if there’s
> an equivalent for redirecting an application that hasn’t been defined?
>
> In other words, if foo is not a procedure then (foo 1 2 3) would redirect
> to (do-this foo 1 2 3) where do-this is defined?
>
> Any help is appreciated.
>

Hi Kevin,

In Bracket [1] used your idea to produce s-expression, if the first argument
of #%app isn't a function:

; In the BRACKET language an application of
  ; a non-function evaluates to an expression.
  (define-syntax (sym-app stx)
    (syntax-case stx ()
      [(_ op arg ...)
       (quasisyntax/loc stx
         (let ([o op])
           (if (procedure? o)
               #,(syntax/loc stx (#%app o arg ...))
               (if (holdable? o)
                   (cons o '(arg ...))
                   (cons o (list arg ...))))))]))

There is an additional wrinkle - if a function is "holdable" it "holds"
(postpones) the
evaluation of its arguments. This can simply we be removed, if you don't
need it.

More details here:

https://github.com/soegaard/bracket/blob/master/bracket/bracket.rkt#L80


/Jens Axel
https://racket-stories.com

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxOx-v%2BZTMGB2tzxmrvb0PamAs4J%3Dg0ovBMTJT8D1bosw%40mail.gmail.com.

Reply via email to