From 0f33c8a9cbabda257c4dd73009266a4cf5f857a7 Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 18 Aug 2018 18:44:14 +0300 Subject: steps towards list --- src/cklist.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/cklist.c') diff --git a/src/cklist.c b/src/cklist.c index d22ee49..e1ca7d8 100644 --- a/src/cklist.c +++ b/src/cklist.c @@ -137,16 +137,16 @@ cklist* list_copy_part(cklist *ckl, int from, int until) { return _ckl; } -void list_print_lisp(cklist *ckl) { +void print_list_enclose_in(cklist *ckl, const char before, const char after) { if (ckl->size > 0) { list_rewind(ckl); - printf("( \"%s\"", list_get(ckl)); + printf("%c \"%s\"", before, list_get(ckl)); if (ckl->size == 1) { - printf(" )\n"); + printf(" %c\n", after); } while (list_next(ckl)) { if (ckl->pos == ckl->size-1) { - printf(", \"%s\" )\n", list_get(ckl)); + printf(", \"%s\" %c\n", list_get(ckl), after); } else { printf(", \"%s\"", list_get(ckl)); @@ -156,9 +156,18 @@ void list_print_lisp(cklist *ckl) { } } +void list_print_lisp(cklist *ckl) { + print_list_enclose_in(ckl, '(', ')'); +} + +void list_print_python(cklist *ckl) { + print_list_enclose_in(ckl, '[', ']'); +} + void list_print(cklist *ckl) { if (ckl->size > 0) { list_rewind(ckl); + printf("%s\n", list_get(ckl)); while (list_next(ckl)) { printf("%s\n", list_get(ckl)); } -- cgit v1.2.3