<commit_before>#include <math.h>   // isnan, isinf
#include <stdio.h>  // FILE, fprintf, stderr

#include "value.h"
#include "write.h"

static void write_cons(FILE *f, cons_t *cons) {
    value_t arg, iter;
    SCM_FOREACH (arg, cons, iter) {
        write(f, arg);

        if (IS_NIL(AS_CONS(iter)->cdr)) {
            return;
        } else if (IS_CONS(AS_CONS(iter)->cdr)) {
            fprintf(f, " ");
        } else {<commit_msg>'write' and 'display' now work on circular lists!<commit_after>#include <math.h>   // isnan, isinf
#include <stdio.h>  // FILE, fprintf, stderr

#include "value.h"
#include "write.h"

static void write_cons(FILE *f, cons_t *cons) {
    // First check if the list is circular
    // (we don't want to recurse forever)
    int32_t len = cons_len(PTR_VAL(cons));
    if (len == -1) {
        fprintf(f, "#<circular list>");
        return; 
    }

    value_t arg, iter;
    SCM_FOREACH (arg, cons, iter) {
        write(f, arg);

        if (IS_NIL(AS_CONS(iter)->cdr)) {
            return;
        } else if (IS_CONS(AS_CONS(iter)->cdr)) {
            fprintf(f, " ");
        } else {
{'fraction_non_alphanumeric': 0.15789473684210525, 'fraction_numerical': 0.0026761819803746653, 'mean_word_length': 2.3795180722891565, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1486457', 'n_tokens_mistral': 421, 'n_tokens_neox': 415, 'n_words': 102}