8.16.0.4

3 Racket Expressions from Rhombus🔗ℹ

Using a Racket syntactic form from Rhombus requires a Rhombus macro that expands to the Racket form. A Rhombus macro can build a use of a Racket syntactic form using expr_meta.pack_s_exp, defn_meta.pack_s_exp, or decl_meta.pack_s_exp. Use expr_meta.pack_expr to pack a Rhombus expression for use within a packed S-expression form.

For example, the following shared macro expands to a use of the Racket shared form, which specifically recognizes uses of the Racket cons function.

import:

  rhombus/meta open

  lib("racket/base.rkt").cons

  lib("racket/shared.rkt").shared as rkt_shared

expr.macro 'shared ($(id :: Identifier) = $rhs ...,

                    ...):

              $body

              ...':

  expr_meta.pack_s_exp(['rkt_shared',

                        [[id, expr_meta.pack_expr('$rhs ...')],

                         ...],

                        expr_meta.pack_expr('block:

                                               $body

                                               ...')])

> shared (x = cons(1, y),

          y = cons(2, x)):

    x.rest.rest.rest.first

2