2025-08-15

writing c with indent-based syntax similar to coffeescript or python

part of c programming

by combining wisp syntax with sc, which only depends on guile, it is possible to write c with indent semantics, and fewer brackets, similar to coffeescript or python.

sc is a scheme-like notation for c. it can be used on its own to write c.

wisp, whitespace to lisp, is a notation for scheme expressions that allows indentation in-place of round brackets.

how it looks

pre-include "stdio.h"

define (main argc argv) : int int char**
  declare i int
  printf "the number of program arguments passed is %d\n" argc
  for : (set i 0) (< i argc) (set+ i 1)
    printf "argument %d is %s\n" (+ i 1) (array-get argv i)
  return 0

what you need

  • gnu guile, which is usually available in package repositories or already installed
  • sc

usage examples

given a file with contents in wisp syntax with sc semantics, the following shell examples demonstrate usage via standard standard input/output.

display c code

sc myfile.scw

write to file

sc myfile.scw > output.c

display formatted c using clang-format

sc myfile.scw | clang-format

motivation

as the author of sc, i use sc in several c projects and found that with the imperative style of c, most lines tend to be simple operations, in what is like a column of commands. translated to scheme-like syntax, many lines start with a round bracket and have a nesting scope that ends on the same line, which can appear syntactically noisy.

interesting links