Comfort Lang
Comfort Lang is an early-stage progressively-evolving imperative programming language. Single-file interpreter, Python 3.6+ only, MIT-licensed. It focuses on a clean and pleasant interactive programming experience.
Comfort Lang is not a simplified Python; it re-thinks human-computer interaction. Python is used only as an extension ecosystem. Version: v1.0.1
GitHub RepositoryQuick Start
Clone repository and launch interpreter:
git clone https://github.com/dxiangwiki/comfort-lang.git
cd comfort-lang
python comfort_lang.py
Prompt > means you are inside Comfort Lang REPL. Type exit to quit.
Variable declaration def
Use def to declare multiple variables in batch.
- Declared via
defbut unassigned: returns[None] - Never-declared non-existent variable: returns
[null]
> def a b c
[success]
> a
[None]
> d
[null]
Batch assignment
Comma-separated batch assignment. Commas inside strings or brackets will not be incorrectly split. Escape quotes are supported.
> a=10,b=20
[success]
> a
[10]
> a + b
[30]
> s="he said \"hello\""
[success]
> s
[he said "hello"]
Function definition
Arrow syntax for top-level expression-based functions: function name=(args)=>expression
> function add=(x,y)=>x+y
[success]
> add(a,b)
[30]
> add(50,60)
[110]
# zero-argument function
> function hello=()=>999
[success]
> hello()
[999]
Function environment snapshot
When defining a function, a deep-copy snapshot of current global environment is created. Functions capture variable states at definition time.
Later re-assignments or modifications to mutable objects (list / dict) will not affect already-created functions. Nested-function support will come in future releases.
> def arr
[success]
> arr=[1,2,3]
[success]
> function get_arr=()=>arr
[success]
> get_arr()
[[1, 2, 3]]
> arr.append(99)
[None]
> get_arr()
[[1, 2, 3]]
Full REPL demo
> def a b
[success]
> function add=(x,y)=>x+y
[success]
> a=100,b=200
[success]
> a
[100]
> b
[200]
> a + b
[300]
> add(a,b)
[300]
> exit
π Thank you for using Comfort Lang!
Status markers
[success]: Statement executed successfully[None]: Variable declared but not assigned; some built-in methods return empty result[null]: Variable does not exist / never declared[error]: Syntax error or runtime exception
Built-in functions
Safe Python built-ins can be called directly without import. Dangerous system-related functions are blocked.
> abs(-99)
[99]
> len("Comfort Lang")
[12]
> max(10,20,99)
[99]
> sum([1,2,3,4,5])
[15]
Current Limitations
β Safe for local use: Download and run REPL on your own device. You may clone, Star, Fork, share and iterate publicly.
β Not recommended to deploy as public online backend service: The interpreter uses Python eval for expression evaluation. Even with a dangerous-function blocklist, escape risks from untrusted external input cannot be fully eliminated.
This is an early-stage progressively-iterated project, targeting local interactive development scenarios only. Do not treat it as an online-ready service component. More syntax features will be added in future versions.
functiononly supports top-level definitions. Nested function definitions inside expressions are unsupported; full lexical closure is not implemented yet.- Only REPL interactive mode is available; loading
.clscript files is not supported. - No block syntax
{}, no if / while statements. Only expression evaluation works currently. - Future releases will add statement blocks, conditionals, loops and script-file loading.