From 8e7d1ab9138ba1153a884690690eb6c4fb663396 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 15 Oct 2017 17:01:03 +0100 Subject: [PATCH] More work on apply, also trying to read dotted pairs. --- src/lispops.c | 4 ++++ src/print.c | 2 +- src/read.c | 13 ++++++++++++- unit-tests/apply.sh | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lispops.c b/src/lispops.c index 783432f..ff2e738 100644 --- a/src/lispops.c +++ b/src/lispops.c @@ -175,6 +175,10 @@ lisp_eval( struct stack_frame *frame, struct cons_pointer env ) { /** * (apply fn args) + * + * Special form. Apply the function which is the result of evaluating the + * first argoment to the list of arguments which is the result of evaluating + * the second argument */ struct cons_pointer lisp_apply( struct stack_frame *frame, struct cons_pointer env ) { diff --git a/src/print.c b/src/print.c index f66cf1b..d978bf0 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ void print_string( FILE * output, struct cons_pointer pointer ) { } /** - * Print a single list cell (cons cell). TODO: does not handle dotted pairs. + * Print a single list cell (cons cell). */ void print_list_contents( FILE * output, struct cons_pointer pointer, diff --git a/src/read.c b/src/read.c index 08e37f1..64cd547 100644 --- a/src/read.c +++ b/src/read.c @@ -67,7 +67,18 @@ struct cons_pointer read_continuation( FILE * input, wint_t initial ) { result = read_string( input, fgetwc( input ) ); break; default: - if ( iswdigit( c ) || c == '.' ) { + if ( c == '.' ) { + wint_t next = fgetwc( input ); + if ( iswdigit( next) ) { + ungetwc( next, input ); + result = read_number( input, c ); + } else if ( iswblank( next ) ) { + result = read_continuation(input, fgetwc( input)); + } else { + read_symbol( input, c ); + } + } + else if ( iswdigit( c ) ) { result = read_number( input, c ); } else if ( iswprint( c ) ) { result = read_symbol( input, c ); diff --git a/unit-tests/apply.sh b/unit-tests/apply.sh index ea90436..3483fb0 100644 --- a/unit-tests/apply.sh +++ b/unit-tests/apply.sh @@ -1,7 +1,7 @@ #!/bin/bash expected='1' -actual=`echo "(apply add '(1))"| target/psse 2> /dev/null | head -1` +actual=`echo "(apply 'add '(1))"| target/psse 2> /dev/null | head -2 | tail -1` if [ "${expected}" = "${actual}" ] then