# NOT RUN {
q1 <- quote(1)
is_expr(q1)
is_syntactic_literal(q1)
q2 <- quote(x)
is_expr(q2)
is_symbol(q2)
q3 <- quote(x + 1)
is_expr(q3)
is_lang(q3)
# Atomic expressions are the terminating nodes of a call tree:
# NULL or a scalar atomic vector:
is_syntactic_literal("string")
is_syntactic_literal(NULL)
is_syntactic_literal(letters)
is_syntactic_literal(quote(call()))
# Parsable literals have the property of being self-quoting:
identical("foo", quote("foo"))
identical(1L, quote(1L))
identical(NULL, quote(NULL))
# Like any literals, they can be evaluated within the empty
# environment:
eval_bare(quote(1L), empty_env())
# Whereas it would fail for symbolic expressions:
# eval_bare(quote(c(1L, 2L)), empty_env())
# Pairlists are also language objects representing argument lists.
# You will usually encounter them with extracted formals:
fmls <- formals(is_expr)
typeof(fmls)
# Since they are mostly an internal data structure, is_expr()
# returns FALSE for pairlists, so you will have to check explicitly
# for them:
is_expr(fmls)
is_pairlist(fmls)
# Note that you can also extract call arguments as a pairlist:
lang_tail(quote(fn(arg1, arg2 = "foo")))
# }
Run the code above in your browser using DataLab