From ed86a8e28d81043aa0950a36804873f652067f84 Mon Sep 17 00:00:00 2001 From: OGINO Masanori Date: Mon, 22 Sep 2014 20:24:31 +0900 Subject: [PATCH 1/5] Add (picrin optional). The library provides some macros to handle optional arguments. The macros are compatible with those in Chicken, Gauche, etc. Signed-off-by: OGINO Masanori --- contrib/10.optional/CMakeLists.txt | 9 +++++++++ contrib/10.optional/piclib/optional.scm | 24 ++++++++++++++++++++++++ contrib/10.optional/t/test.scm | 15 +++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 contrib/10.optional/CMakeLists.txt create mode 100644 contrib/10.optional/piclib/optional.scm create mode 100644 contrib/10.optional/t/test.scm diff --git a/contrib/10.optional/CMakeLists.txt b/contrib/10.optional/CMakeLists.txt new file mode 100644 index 00000000..c6a60a8a --- /dev/null +++ b/contrib/10.optional/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB OPTIONAL_FILES ${PROJECT_SOURCE_DIR}/contrib/10.optional/piclib/*.scm) +list(APPEND PICLIB_CONTRIB_LIBS ${OPTIONAL_FILES}) +add_custom_target(test-optional + for test in ${PROJECT_SOURCE_DIR}/contrib/10.optional/t/*.scm \; + do + bin/picrin "$$test" \; + done + DEPENDS repl) +set(CONTRIB_TESTS ${CONTRIB_TESTS} test-optional) diff --git a/contrib/10.optional/piclib/optional.scm b/contrib/10.optional/piclib/optional.scm new file mode 100644 index 00000000..362f7fe0 --- /dev/null +++ b/contrib/10.optional/piclib/optional.scm @@ -0,0 +1,24 @@ +(define-library (picrin optional) + (import (scheme base)) + + (define-syntax optional + (syntax-rules () + ((_ args default) + (let ((t args)) + (if (null? t) default (car t)))))) + + (define-syntax let-optionals* + (syntax-rules () + ((_ args () body ...) + (begin body ...)) + ((_ args ((var default) . tail) body ...) + (let* ((t args) + (var (if (null? t) default (car t))) + (remain (if (null? t) '() (cdr t)))) + (let-optionals* remain tail body ...))) + ((_ args rest body ...) + (let ((rest args)) + body ...)))) + + (export optional + let-optionals*)) diff --git a/contrib/10.optional/t/test.scm b/contrib/10.optional/t/test.scm new file mode 100644 index 00000000..5ac0b45c --- /dev/null +++ b/contrib/10.optional/t/test.scm @@ -0,0 +1,15 @@ +(import (scheme base) + (picrin optional) + (picrin test)) + +(test 0 (optional '() 0)) +(test 1 (optional '(1) 0)) + +(test '(0 0) (let-optionals* '() ((a 0) (b 0)) (list a b))) +(test '(1 0) (let-optionals* '(1) ((a 0) (b 0)) (list a b))) +(test '(1 2) (let-optionals* '(1 2) ((a 0) (b 0)) (list a b))) +(test '(1 1) (let-optionals* '(1) ((a 0) (b a)) (list a b))) + +(test '(0 ()) (let-optionals* '() ((a 0) . r) (list a r))) +(test '(1 ()) (let-optionals* '(1) ((a 0) . r) (list a r))) +(test '(1 (2)) (let-optionals* '(1 2) ((a 0) . r) (list a r))) From c4c87abe1a254e2ac2266f29b328f6d9b7757653 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 27 Sep 2014 08:20:56 -0700 Subject: [PATCH 2/5] update benz (remove type-punning) --- extlib/benz | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extlib/benz b/extlib/benz index a22eef10..458511e2 160000 --- a/extlib/benz +++ b/extlib/benz @@ -1 +1 @@ -Subproject commit a22eef106077850db7dd2d9da5703a4d0b3b9ffe +Subproject commit 458511e2310d2882da5271c5b5a85759b855647c From fc873c5559eeeb75e7c4fce7116c0f20751efc5d Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 27 Sep 2014 08:25:52 -0700 Subject: [PATCH 3/5] update benz (suppress more warnings) --- extlib/benz | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extlib/benz b/extlib/benz index 458511e2..15889a5f 160000 --- a/extlib/benz +++ b/extlib/benz @@ -1 +1 @@ -Subproject commit 458511e2310d2882da5271c5b5a85759b855647c +Subproject commit 15889a5feb515bd67ee7dc2c6419d16703151a54 From 2e0fab5a26de47e30d4994e64c021e6c1257b87d Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 30 Sep 2014 21:21:59 +0900 Subject: [PATCH 4/5] make repl tty sensitive --- contrib/20.repl/CMakeLists.txt | 2 ++ contrib/20.repl/repl.c | 25 +++++++++++++++++++++++++ contrib/20.repl/repl.scm | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 contrib/20.repl/repl.c diff --git a/contrib/20.repl/CMakeLists.txt b/contrib/20.repl/CMakeLists.txt index c0a24065..91bec1b8 100644 --- a/contrib/20.repl/CMakeLists.txt +++ b/contrib/20.repl/CMakeLists.txt @@ -1 +1,3 @@ list(APPEND PICLIB_CONTRIB_LIBS ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.scm) +list(APPEND PICRIN_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.c) +list(APPEND PICRIN_CONTRIB_INITS repl) \ No newline at end of file diff --git a/contrib/20.repl/repl.c b/contrib/20.repl/repl.c new file mode 100644 index 00000000..bdc54e65 --- /dev/null +++ b/contrib/20.repl/repl.c @@ -0,0 +1,25 @@ +#include "picrin.h" +#include "picrin/data.h" +#include "picrin/pair.h" +#include "picrin/string.h" +#include "picrin/cont.h" + +#include + + +static pic_value +pic_repl_tty_p(pic_state *pic) +{ + + pic_get_args(pic, ""); + + return pic_bool_value((isatty(STDIN_FILENO))); +} + +void +pic_init_repl(pic_state *pic) +{ + pic_deflibrary (pic, "(picrin repl)") { + pic_defun(pic, "tty?", pic_repl_tty_p); + } +} diff --git a/contrib/20.repl/repl.scm b/contrib/20.repl/repl.scm index 2b9d4812..bed94d0e 100644 --- a/contrib/20.repl/repl.scm +++ b/contrib/20.repl/repl.scm @@ -11,7 +11,7 @@ (else (begin (define (readline str) - (display str) + (if (tty?) (display str)) (read-line)) (define (add-history str) #f)))) From 086495706163a8db90d8511741212727c6c3030f Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Tue, 30 Sep 2014 21:23:22 +0900 Subject: [PATCH 5/5] cosmetic change --- contrib/20.repl/CMakeLists.txt | 2 +- contrib/20.repl/repl.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/contrib/20.repl/CMakeLists.txt b/contrib/20.repl/CMakeLists.txt index 91bec1b8..7fc3bf06 100644 --- a/contrib/20.repl/CMakeLists.txt +++ b/contrib/20.repl/CMakeLists.txt @@ -1,3 +1,3 @@ list(APPEND PICLIB_CONTRIB_LIBS ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.scm) list(APPEND PICRIN_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/contrib/20.repl/repl.c) -list(APPEND PICRIN_CONTRIB_INITS repl) \ No newline at end of file +list(APPEND PICRIN_CONTRIB_INITS repl) diff --git a/contrib/20.repl/repl.c b/contrib/20.repl/repl.c index bdc54e65..1398a202 100644 --- a/contrib/20.repl/repl.c +++ b/contrib/20.repl/repl.c @@ -1,8 +1,4 @@ #include "picrin.h" -#include "picrin/data.h" -#include "picrin/pair.h" -#include "picrin/string.h" -#include "picrin/cont.h" #include