From 202747cfbb16f1db2e8607a092c6b2eeb58a4c42 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 1 Feb 2023 20:09:03 -0800 Subject: [PATCH] Print list. --- implementations/C/joy.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/implementations/C/joy.c b/implementations/C/joy.c index 14b2928..bd1f748 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -129,7 +129,6 @@ text_to_expression(char *text) if (diff) { /* Allocate space and copy out the substring. */ - current_list_node = make_symbol_node(text, diff); if (head) { head->tail = current_list_node; @@ -163,6 +162,33 @@ text_to_expression(char *text) } +void +print_node(struct JoyType j) +{ + switch (j.kind) { + case joySymbol: + printf("%s", j.value.symbol); + break; + default: + printf("wtf"); + } +} + + +void +print_list(struct list_node* el) +{ + while (NULL != el) { + print_node(el->head); + el = el->tail; + if (NULL != el) { + printf(" "); + } + } + printf("\n"); +} + + int main(void) { @@ -184,7 +210,7 @@ main(void) el = push_integer_from_str("3141592653589793238462643383279502884", 0); el = text_to_expression("char *te xt"); - + print_list(el); /*sexpr i = new_int();*/ /*mpz_add(i.i, pi, pi);*/ /*gmp_printf ("%Zd\n", i.i);*/