From 7fc2885fad881b323a23f2e70bc915d251c6364a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 22 Jan 2014 21:20:13 +0900 Subject: [PATCH] replace list impl by scheme with impl by C --- piclib/built-in.scm | 14 +------------- src/pair.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 9009a157..6a5c4e62 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -35,8 +35,6 @@ (define-library (picrin bootstrap-tools) (import (scheme base)) - (define (list . args) args) - (define (caar p) (car (car p))) (define (cadr p) (car (cdr p))) (define (cdar p) (cdr (car p))) @@ -51,14 +49,7 @@ (cons (f (car list)) (map f (cdr list))))) - (define (append xs ys) - (if (null? xs) - ys - (cons (car xs) - (append (cdr xs) ys)))) - - (export list map append - caar cadr cdar cddr + (export map caar cadr cdar cddr cadar caddr cdddr)) ;;; core syntaces @@ -475,9 +466,6 @@ (list? (cdr obj)) #f))) -(define (list . args) - args) - (define (caar p) (car (car p))) diff --git a/src/pair.c b/src/pair.c index 8607f94c..e6a5255c 100644 --- a/src/pair.c +++ b/src/pair.c @@ -290,6 +290,17 @@ pic_pair_null_p(pic_state *pic) return pic_bool_value(pic_nil_p(v)); } +static pic_value +pic_pair_list(pic_state *pic) +{ + size_t argc; + pic_value *argv; + + pic_get_args(pic, "*", &argc, &argv); + + return pic_list_from_array(pic, argc, argv); +} + static pic_value pic_pair_length(pic_state *pic) { @@ -358,6 +369,7 @@ pic_init_pair(pic_state *pic) pic_defun(pic, "set-car!", pic_pair_set_car); pic_defun(pic, "set-cdr!", pic_pair_set_cdr); pic_defun(pic, "null?", pic_pair_null_p); + pic_defun(pic, "list", pic_pair_list); pic_defun(pic, "length", pic_pair_length); pic_defun(pic, "append", pic_pair_append); pic_defun(pic, "reverse", pic_pair_reverse);