Browse Source

init

audio
Lukas F. Hartmann 3 months ago
commit
88a0fde4ce
4 changed files with 83 additions and 0 deletions
  1. +36
    -0
      README.md
  2. +2
    -0
      build.sh
  3. +12
    -0
      init.scm
  4. +33
    -0
      interscheme.c

+ 36
- 0
README.md View File

@@ -0,0 +1,36 @@
# Interscheme

A pixel graphics and sound playground using SDL2 and chibi-scheme.

WIP.

See also: http://synthcode.com/scheme/chibi/#h3_QuickStart

## Build

First, build and install chibi-scheme:

```
git clone https://github.com/ashinn/chibi-scheme.git
cd chibi-scheme
make -j$(nproc)
sudo make install
```

This will yield `libchibi-scheme.so` in `/usr/local/lib` and `/usr/local/include/chibi` header files. You might need to do `ldconfig /usr/local/lib` once.

It will also make a scheme REPL called `chibi-scheme`.

Then, in this here repo:

```
./build.sh
```

## Run

Edit `init.scm` to your liking.

```
./interscheme
```

+ 2
- 0
build.sh View File

@@ -0,0 +1,2 @@
gcc -o interscheme interscheme.c -lchibi-scheme


+ 12
- 0
init.scm View File

@@ -0,0 +1,12 @@
(define (sierpinski n)
(for-each
(lambda (x) (display (list->string (append x (list #\return)))))
(let loop ((acc (list (list #\*))) (spaces (list #\ )) (n n))
(if (zero? n)
acc
(loop
(append
(map (lambda (x) (append spaces x spaces)) acc)
(map (lambda (x) (append x (list #\ ) x)) acc))
(append spaces spaces)
(- n 1))))))

+ 33
- 0
interscheme.c View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <chibi/sexp.h>

void dostuff(sexp ctx) {
/* declare and preserve local variables */
sexp_gc_var2(obj1, obj2);
sexp_gc_preserve2(ctx, obj1, obj2);

/* load a file containing Scheme code */
obj1 = sexp_c_string(ctx, "./init.scm", -1);
sexp_load(ctx, obj1, NULL);

/* eval a C string as Scheme code */
sexp_eval_string(ctx, "(sierpinski 7)", -1, NULL);

/* construct a Scheme expression to eval */
obj1 = sexp_intern(ctx, "my-procedure", -1);
obj2 = sexp_cons(ctx, obj1, SEXP_NULL);
sexp_eval(ctx, obj2, NULL);

/* release the local variables */
sexp_gc_release2(ctx);
}

int main(int argc, char** argv) {
sexp ctx;
sexp_scheme_init();
ctx = sexp_make_eval_context(NULL, NULL, NULL, 0, 0);
sexp_load_standard_env(ctx, NULL, SEXP_SEVEN);
sexp_load_standard_ports(ctx, NULL, stdin, stdout, stderr, 1);
dostuff(ctx);
sexp_destroy_context(ctx);
}

Loading…
Cancel
Save