DELAPARRA
Index
Color
NL
Category: Programming paradigms

Quote / Eval

Explained by Updated

What is Quote / Eval?

Quote / Eval: quote prevents an expression from being evaluated (treat it as data); eval takes data and runs it as code. In Lisp, quote and eval are two sides of treating code as data. quote stops an expression from being run, so you get the expression itself as a list. eval does the opposite: it takes such a list and runs it as code.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Quote / Eval

How is Quote / Eval used in practice?

This is what makes Lisp macros and code generation so natural. A program can build an expression as data, inspect or change it, then evaluate it.

What should you keep in mind with Quote / Eval?

Many other languages have an eval function too, including PHP and JavaScript, but there it usually means running a string of code. That is risky: if any part of the string comes from user input, an attacker can run their own code on your server. In everyday application code, avoid eval entirely. There is almost always a safer alternative, such as a lookup table or a callback.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with Q

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.