Skip to content

A defn.macro that creates bindings with generated names #297

Answered by sorawee
kiranandcode asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, I debugged by removing that _name and forgot to add it back.

(Edited: use Syntax.make)

Here's a version with _name:

#lang rhombus

import:
  rhombus/meta open

import:
  lib("racket/syntax.rkt"):
    meta
    as racket

defn.macro 'variable $name $vl':
  def name_stx: Syntax.make('$name')
  def gen_name : racket.#{format-id}(name_stx, "~a_name", name_stx)
  'def $gen_name: $vl
   def $name: $gen_name'

variable hello 10

hello_name
hello

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sorawee
Comment options

Answer selected by kiranandcode
@kiranandcode
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants