Proxy Information
Original URL
gemini://idiomdrottning.org/sexpc
Status Code
Success (20)
Meta
text/gemini; lang=en # sexpc sexpc is a tiny li’l Unix filter that reads one sexp from stdin and outputs the same expression in C syntax, using foof’s fmt-c combinators. (The percent signs didn’t make sense to me so I made them optional.) It’s like three lines, since foof did all the heavy lifting (and that tree library I wrote a few years back), it’s just a toy. The cool part is that you can use it in Emacs. Put this in your Emacs once you have the sexpc binary in your path: ```Code (defun sexpc () (interactive) (shell-command-on-region (progn (beginning-of-defun) (point)) (save-excursion (end-of-defun) (point)) "sexpc" nil t)) ``` Here’s an example. Someone sends you a file and you wanna hack in it, but, it’s C instead of a normal sexp language. Let’s say you wanna add a fib function. You type: ```Code (fun #f fib (n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) ``` Easy enough with Paredit and friends. Then, with your cursor anywhere in the sexp, you call sexpc (via M-x or via a binding), and it’s replaced by: ```Code int fib (int n) { if (n <= 1) { return 1; } else { return fib(n - 1) + fib(n - 2); } } ``` ## Roadmap Of course, down the line we’d wanna figure out a way to do macros, quasiquoting etc, and support other C-like languages like JavaScript or Golang. That might require a setup beyond just reading one sexp. But sometimes cool stuff can grow from what starts as just a toy. ## Source code ```Code git clone https://idiomdrottning.org/sexpc ``` => http://synthcode.com/scheme/fmt Combinator Formatting
Capsule Response Time
545.385528 milliseconds
Gemini-to-HTML Time
0.016518 milliseconds

This content has been proxied by September (3851b).