原来的脚本是这样的:
#lang racket
(for ([i (in-range 3)])
(for ([j (in-range 9)])
(display "X"))
(display "\n"))
(for ([i (in-range 6)])
(for ([j (in-range 3)])
(display " "))
(for ([j (in-range 3)])
(display "X"))
(for ([j (in-range 3)])
(display " "))
(display "\n"))
(for ([i (in-range 3)])
(for ([j (in-range 9)])
(display "X"))
(display "\n"))
输出是:
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
XXX
XXX
XXX
XXX
XXX
XXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
我想知道是否可以使用这样的 DSL 重写它:
(define a
"3 9 X
6 3 b 3 X 3 b
3 9 X")
进而:
(interpret a)
绘制此图。
有谁知道最好的方法是什么?