<commit_before># Getting Started with Gerbil Development

This is a quick start guide to setting up your Gerbil development environment, starting from scratch.

## Install Gambit
* Clone the repo from [github](https://github.com/gambit/gambit)
* Follow the instructions from `gambit/INSTALL.txt` to install configure and install gambit, as the process for building from source tends to change frequently.

I usually configure Gambit for development with the following incantation:
```
 ./configure --prefix=/usr/local/gambit \
             --enable-single-host \
             --enable-multiple-versions \
             --enable-shared \
             --enable-openssl \
             --enable-default-runtime-options=f8,-8,t8 \
             --enable-poll # For Linux and BSD; don't use this on MacOS
```

With this configuration, you need to add `$GAMBIT_PREFIX/current/bin` to your `PATH` and `$GAMBIT_PREFIX/current/lib` to your `LD_LIBRARY_PATH`.

If you are on Linux or BSD, I also recommend using `--enable-poll`, which will use the more
scalable poll-based i/o scheduler (instead of the default select-based one).

If you intend to build static applications for servers, then you should use the following
configuration:
```
./configure --prefix=/usr/local/gambit \
             --enable-single-host \
             --enable-multiple-versions \
             --enable-openssl \
             --enable-default-runtime-options=f8,-8,t8 \
             --enable-poll

```
This removes `--enable-shared`, which will build gambit without shared libraries and thus result in static linkage of Gambit in executables.

I have the following in my `.bashrc`:
```
GAMBIT=/usr/local/gambit/current
add_path $GAMBIT/bin
add_ldpath $GAMBIT/lib
```

with the helper functions defined as:
```
add_path() {
    if [[ ! "$PATH" =~ $1 ]]; then
        export PATH="$PATH:$1"
    fi
}

add_ldpath() {
    if [ -z "$LD_LIBRARY_PATH" ]; then
        export LD_LIBRARY_PATH="$1"
    elif [[ ! "$LD_LIBRARY_PATH" =~ $1 ]]; then
        export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$1"
    fi
}

```

## Install Gerbil
Clone the repo from [github](https://github.com/vyzo/gerbil) and build:
```
$ cd gerbil/src
$ ./build.sh
```

In order to have a fully usable installation, you should export `GERBIL_HOME` and add `$GERBIL_HOME/bin` to your `PATH`. I have the following in my `.bashrc`:
```
export GERBIL_HOME=$HOME/gerbil
add_path $GERBIL_HOME/bin
```

## Write some code
You can get started right away and write a script, but let's do a simple
compiled library module and an executable as it is more relevant for real
world development.

First create your workspace -- I recommend you use a top package for your libs
so that you don't have namespace conflicts.
So let's make our project with you using `myuser` as the top package name, and
your source live in `myproject`. You should of course pick something more
representative  for your top package namespace, like your github user id.

So, let's make a simple library module:
```
$ mkdir -p myproject/src/myuser
$ cd myproject/src/myuser

# Create a gerbil.pkg file for our project
$ cat > gerbil.pkg <<EOF
(package: myuser)
EOF

$ cat > mylib.ss <<EOF
(export #t) ; export all symbols
(def (hello who)
 (displayln "hello " who))
EOF<commit_msg>Add Brew documentation<commit_after># Getting Started with Gerbil Development

This is a quick start guide to setting up your Gerbil development environment, starting from scratch.

## Install Gambit
* Clone the repo from [github](https://github.com/gambit/gambit)
* Follow the instructions from `gambit/INSTALL.txt` to install configure and install gambit, as the process for building from source tends to change frequently.

I usually configure Gambit for development with the following incantation:
```
 ./configure --prefix=/usr/local/gambit \
             --enable-single-host \
             --enable-multiple-versions \
             --enable-shared \
             --enable-openssl \
             --enable-default-runtime-options=f8,-8,t8 \
             --enable-poll # For Linux and BSD; don't use this on MacOS
```

With this configuration, you need to add `$GAMBIT_PREFIX/current/bin` to your `PATH` and `$GAMBIT_PREFIX/current/lib` to your `LD_LIBRARY_PATH`.

If you are on Linux or BSD, I also recommend using `--enable-poll`, which will use the more
scalable poll-based i/o scheduler (instead of the default select-based one).

If you intend to build static applications for servers, then you should use the following
configuration:
```
./configure --prefix=/usr/local/gambit \
             --enable-single-host \
             --enable-multiple-versions \
             --enable-openssl \
             --enable-default-runtime-options=f8,-8,t8 \
             --enable-poll

```
This removes `--enable-shared`, which will build gambit without shared libraries and thus result in static linkage of Gambit in executables.

I have the following in my `.bashrc`:
```
GAMBIT=/usr/local/gambit/current
add_path $GAMBIT/bin
add_ldpath $GAMBIT/lib
```

with the helper functions defined as:
```
add_path() {
    if [[ ! "$PATH" =~ $1 ]]; then
        export PATH="$PATH:$1"
    fi
}

add_ldpath() {
    if [ -z "$LD_LIBRARY_PATH" ]; then
        export LD_LIBRARY_PATH="$1"
    elif [[ ! "$LD_LIBRARY_PATH" =~ $1 ]]; then
        export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$1"
    fi
}

```

## Install Gerbil
Clone the repo from [github](https://github.com/vyzo/gerbil) and build:
```
$ cd gerbil/src
$ ./build.sh
```

In order to have a fully usable installation, you should export `GERBIL_HOME` and add `$GERBIL_HOME/bin` to your `PATH`. I have the following in my `.bashrc`:
```
export GERBIL_HOME=$HOME/gerbil
add_path $GERBIL_HOME/bin
```

## Installation on Macos
Both Gambit and Gerbil are available via homebrew.
```
$ brew install gerbil-scheme
```

To get around some brew specific paths, set the following in your environment
Most likely you'll want to add them to your `~/.bashrc`, `~/.zshrc` for long term use.
```
$ export PATH=/usr/local/opt/gambit-scheme/current/bin:$PATH
$ export GERBIL_HOME=/usr/local/opt/gerbil-scheme/libexec
```

## Write some code
You can get started right away and write a script, but let's do a simple
compiled library module and an executable as it is more relevant for real
world development.

First create your workspace -- I recommend you use a top package for your libs
so that you don't have namespace conflicts.
So let's make our project with you using `myuser` as the top package name, and
your source live in `myproject`. You should of course pick something more
representative  for your top package namespace, like your github user id.

So, let's make a simple library module:
```
$ mkdir -p myproject/src/myuser
$ cd myproject/src/myuser

# Create a gerbil.pkg file for our project
$ cat > gerbil.pkg <<EOF
(package: myuser)
EOF

$ cat > mylib.ss <<EOF
(export #t) ; export all symbols
(def (hello who)
 (displayln "hello " who))
EOF
{'fraction_non_alphanumeric': 0.10638297872340426, 'fraction_numerical': 0.0031627372052903968, 'mean_word_length': 3.302411873840445, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7220796', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2047, 'n_words': 801}