Evaluate a Lisp-Like Config Expression Language With Lexical Scopes
Last updated: November 29, 2026
Quick Overview
Write a reader and evaluator for a small S-expression language used in configuration: integers, symbols, (add a b), (mult a b), (if cond then else), and (let v1 e1 v2 e2 ... body) where let bindings are sequential and the innermost binding of a name wins.
0
0
0 solved
Write a reader and evaluator for a small S-expression language used in configuration: integers, symbols, (add a b), (mult a b), (if cond then else), and (let v1 e1 v2 e2 ... body) where let bindings are sequential and the innermost binding of a name wins.
Google has a long history of small configuration languages (GCL, Jsonnet-like tools, Starlark), and this onsite question checks whether you can build a tiny one correctly. The interviewer focuses on separating reading from evaluation, lexical scoping with a scope stack, and cleaning up scopes even when an error is raised.
What the Interviewer Expects
- Separates tokenizing and reading into a nested list from evaluation
- Represents scopes as a stack of dictionaries searched innermost first
- Implements sequential let bindings so later bindings can see earlier ones
- Pops scopes in a finally block so errors do not leak bindings
- Reports syntax errors and unbound variables clearly
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add lambda and function application with closures; what changes in the environment model?
- Detect unbound variables before evaluation with a static pass.
- How would you prevent a malicious config from running forever or using too much memory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Syntax: integers (possibly negative), symbols, and parenthesized lists.
- Forms:
(add a b),(mult a b),(if c t e)(non-zero is true),(let v1 e1 ... body). letevaluates each binding in...
High-Level Design
Tokenize by padding parentheses with spaces and splitting. The reader is recursive: ( starts a list read until ), anything else becomes an int if it parses or a symbol otherwise. Evaluation dispat...