6 / 0 ?. # Ignore error 6 / 0 ?: x -> print x # Handle error
Data debugging
let a := (x) -> x + 1 debug a
Mapping operations
# Mapping transformation let data = {a: 1, b: 2, c: 3}
# Transform keys and values simultaneously let result = Map.map( k -> k.to_upper(), # Key transformation function v -> v * 2, # Value transformation function data ) # Result: {A: 2, B: 4, C: 6}
Practical Examples
File Handling:
Find files larger than 5KB modified within the last 24 hours and display in a table:
let a = curl 'https://jsonplaceholder.typicode.com/posts/1/comments' | From.json() a >> data.json # JSON format a | Into.csv() >> data.csv # CSV format a | Into.toml() >> data.toml # TOML format
# a is already a valid Lumesh expression type a # List len(a) # Can perform other regular operations
Operations and Maintenance Scripts
Write a script to let users select mountable disks
# Path operations Fs.exists("/path/to/file") # Check if path exists Fs.is_dir("/path") # Check if it is a directory Fs.canon("./relative/path") # Get absolute path
System Directory Access
# Get system directories letdirs = Fs.dirs() println(dirs.home) # User home directory println(dirs.config) # Configuration directory println(dirs.cache) # Cache directory println(dirs.current) # Current working directory
Detailed File List Information
# ls command options Fs.ls -l # Detailed information Fs.ls -a # Show hidden files Fs.ls -L # Follow symbolic links Fs.ls -u # Show user information Fs.ls -m # Show permission mode Fs.ls -p # Show full path
Common Built-in Functions
Core Functions
# Data operations len(collection) # Get length type(value) # Get type rev("string") # Reverse string/list flatten([[1,2],[3,4]]) # Flatten nested structure
# Execution control eval(expression) # Evaluate expression exec_str("let x = 10") # Execute string code include("script.lm") # Include file into current environment import("module.lm") # Import module into new environment