Here's a slightly re-factored version of g that will be easier to unit
test.
(def '*PunctChars* (chop ".,;:?!\"'_-{[]}"))
(de is-$variable$? (Arg)
(let (ChopArg (chop Arg)
ChopArgTail (tail 2 ChopArg))
(cond ((not (= "$" (car ChopArg)))
NIL)
(# Arg is (strictly) surrounded by $ chars.
(= "$" (last ChopArg))
(list NIL Arg))
(# Arg is surrounded by $ chars, but also ends in a legal
# punctuation mark.
(and (= (car ChopArgTail) "$")
(member (last ChopArgTail) *PunctChars*))
(list (last ChopArgTail) (pack (head -1 ChopArg))))
NIL)))
(de eval-$variable$ (Arg)
(val
(intern
(pack
(tail -1 (head -1 (chop Arg)))))))
# Test for `eval-$variable$`
(test "Hi!"
(let hello "Hi!"
(eval-$variable$ "$hello$")))
(de ensure-escape-quote (S)
(if (str? S)
(pack "\"" S "\"")
S))
# Punchline (uses `if-let`! :)
(de g Args
(glue " "
(recur Args
(mapcar '((Arg)
(if (atom Arg)
(if-let (Punct Arg) (is-$variable$? Arg)
(pack (ensure-escape-quote (eval-$variable$ Arg))
Punct)
(ensure-escape-quote Arg))
(recurse Arg)))
Args))))
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe