atom.c
char* atom_tostring(atom_t* obj, int depth) {
    assert_arg(obj, "atom_tostr");

    char tmp[64];
    char* s;

    switch (obj->type) {
    
    case NIL:
        strcpy(tmp, "<Null object>");
        break;

    case NUMBER:
        sprintf(tmp, "%g", *obj->val.num);
        break;

    case SYMBOL:
        s = malloc(strlen(obj->val.sym) + 1);
        strcpy(s, obj->val.sym);
        return s;
        break;

    case LIST:
        if (depth)
            return list_tostr(obj, depth);
        else
            strcpy(tmp, "(...)");
        break;

    case DICTIONARY:
        if (depth)
            return dict_tostr(obj, depth);
        else
            strcpy(tmp, "{...}");
        break;

    case FUNCTION:
        sprintf(tmp, "<Function at 0x%lx>", (size_t)obj);
        break;

    case STD_OP:
        strcpy(tmp, "<Operator>");
        break;

    default:
        sprintf(tmp, "<Object at 0x%lx>", (size_t)obj);
        break;
    }
    
    s = malloc(strlen(tmp) + 1);
    strcpy(s, tmp);
    return s;
}
/*
--------------------------------------
atom_tostr

    Return a string representing an object.
--------------------------------------
*/
atom_tostr
Return a string representing an object.
atom_tostr Return a string representing an object .
char* atom_tostring(atom_t* obj, int depth) {
    assert_arg(obj, "atom_tostr");
    char tmp[64];
    char* s;
    switch (obj->type) {
    case NIL:
        strcpy(tmp, "<Null object>");
        break;
    case NUMBER:
        sprintf(tmp, "%g", *obj->val.num);
        break;
    case SYMBOL:
        s = malloc(strlen(obj->val.sym) + 1);
        strcpy(s, obj->val.sym);
        return s;
        break;
    case LIST:
        if (depth)
            return list_tostr(obj, depth);
        else
            strcpy(tmp, "(...)");
        break;
    case DICTIONARY:
        if (depth)
            return dict_tostr(obj, depth);
        else
            strcpy(tmp, "{...}");
        break;
    case FUNCTION:
        sprintf(tmp, "<Function at 0x%lx>", (size_t)obj);
        break;
    case STD_OP:
        strcpy(tmp, "<Operator>");
        break;
    default:
        sprintf(tmp, "<Object at 0x%lx>", (size_t)obj);
        break;
    }
    s = malloc(strlen(tmp) + 1);
    strcpy(s, tmp);
    return s;
}
char * atom_tostring ( atom_t * obj , int depth ) { assert_arg ( obj , " " ) ; char tmp [ 64 ] ; char * s ; switch ( obj -> type ) { case NIL : strcpy ( tmp , " " ) ; break ; case NUMBER : sprintf ( tmp , " " , * obj -> val . num ) ; break ; case SYMBOL : s = malloc ( strlen ( obj -> val . sym ) + 1 ) ; strcpy ( s , obj -> val . sym ) ; return s ; break ; case LIST : if ( depth ) return list_tostr ( obj , depth ) ; else strcpy ( tmp , " " ) ; break ; case DICTIONARY : if ( depth ) return dict_tostr ( obj , depth ) ; else strcpy ( tmp , " " ) ; break ; case FUNCTION : sprintf ( tmp , " " , ( size_t ) obj ) ; break ; case STD_OP : strcpy ( tmp , " " ) ; break ; default : sprintf ( tmp , " " , ( size_t ) obj ) ; break ; } s = malloc ( strlen ( tmp ) + 1 ) ; strcpy ( s , tmp ) ; return s ; }
atom_tostr
Return a string representing an object.
atom_tostr Return a string representing an object .