writing c with indent based syntax similar to coffeescript or python

part of c programming

by combining wisp with sc, which both only depend on guile, it is possible to write c with indent and with less 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 for indent 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
  • wisp.scm, which can be found in the release archives right at the top-level of the wisp folder
  • wisp.scm be installed in guiles module load path - /usr/share/guile/site/wisp.scm should work in many cases
  • the following guile script in a file wisp2lisp somewhere in your $PATH so that it can be used as a command on the command-line
; example usage:
;   cat t.w | wisp2lisp

(import (wisp) (rnrs io ports))
(display (wisp2lisp (get-string-all (current-input-port))))


take a file with contents that use wisp syntax with sc semantics and compile to standard output with the following shell command:

cat myfile.scw | wisp2lisp | sc

write to file:

cat myfile.scw | wisp2lisp | sc > output.c

formatted with clang-format:

cat myfile.scw | wisp2lisp | sc | clang-format

here is a wisp syntax reference, and information about how sc works with syntax reference is found on its respective homepage.



as the author of sc, i used sc in several c projects and found that with the imperative style of c, each line tends to be a command and with scheme-like syntax that means it starts with a round bracket. this can unfortunately appear syntactically noisy, to the point that it might make things more difficult with all the little commands and declaration and memory-management code overhead in c.

experimental wisp support in sc

the wisp compatibility of sc could be improved though, as there are some syntactical elements that could be represented in simpler wisp. sc now comes with a file other/wisp2sc which uses standard input/output and only changes the way key-value associations are made to require less syntax. this makes it possible to use this in declare and similar forms:

  a 1
  b 2

instead of having to use a dot, since sc on its own currently takes associations as a flat list (key value key value ...)

  . a 1
  . b 2