From a8a56aa34ebe012b48230429f4e0cbb27586d553 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 15 Jun 2014 00:36:38 +0900 Subject: [PATCH] add dictionary-size --- src/dict.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dict.c b/src/dict.c index d23204eb..7ad254ec 100644 --- a/src/dict.c +++ b/src/dict.c @@ -40,7 +40,7 @@ pic_dict_dict_ref(pic_state *pic) e = xh_get_int(&dict->hash, key); if (! e) { - return pic_none_value(); + pic_errorf(pic, "element not found for a key: ~s", pic_sym_value(key)); } return xh_val(e, pic_value); } @@ -72,6 +72,16 @@ pic_dict_dict_del(pic_state *pic) return pic_none_value(); } +static pic_value +pic_dict_dict_size(pic_state *pic) +{ + struct pic_dict *dict; + + pic_get_args(pic, "d", &dict); + + return pic_int_value(dict->hash.count); +} + void pic_init_dict(pic_state *pic) { @@ -81,5 +91,6 @@ pic_init_dict(pic_state *pic) pic_defun(pic, "dictionary-ref", pic_dict_dict_ref); pic_defun(pic, "dictionary-set!", pic_dict_dict_set); pic_defun(pic, "dictionary-delete", pic_dict_dict_del); + pic_defun(pic, "dictionary-size", pic_dict_dict_size); } }