add fancy printing
[lambda.git] / lambda.y
index 1dbcaaf..040d834 100644 (file)
--- a/lambda.y
+++ b/lambda.y
@@ -59,8 +59,6 @@ void decls_prepend(char *ident, struct lambda *value)
        head->next = decls;
        head->ident = strdup(ident);
        head->value = value;
-       printf("Declared %s as ", ident);
-       lambda_print(value, NULL);
        decls = head;
 }
 
@@ -75,6 +73,24 @@ struct lambda *decls_lookup(char *ident)
        return make_ident(ident);
 }
 
+void decls_print()
+{
+       struct decllist *c = decls;
+       unsigned int maxlen = 0, len;
+       while(c != NULL){
+               len = strlen(c->ident);
+               maxlen = maxlen < len ? len : maxlen;
+               c = c->next;
+       }
+
+       c = decls;
+       while(c != NULL){
+               printf("% -*s = ", maxlen, c->ident);
+               lambda_print(c->value, NULL);
+               c = c->next;
+       }
+}
+
 void decls_free()
 {
        struct decllist *t;