1
/*===========================================================================
2
* FileName : module-srfi8.c
3
* About : SRFI-8 receive: Binding to multiple values
5
* Copyright (C) 2005-2006 Jun Inoue
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
13
* 1. Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in the
17
* documentation and/or other materials provided with the distribution.
18
* 3. Neither the name of authors nor the names of its contributors
19
* may be used to endorse or promote products derived from this software
20
* without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
23
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
26
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
===========================================================================*/
37
/*=======================================
39
=======================================*/
41
/*=======================================
43
=======================================*/
44
#include "sigscheme.h"
45
#include "sigschemeinternal.h"
47
/*=======================================
48
File Local Struct Declarations
49
=======================================*/
51
/*=======================================
52
File Local Macro Declarations
53
=======================================*/
55
/*=======================================
57
=======================================*/
58
#include "functable-srfi8.c"
60
/*=======================================
61
File Local Function Declarations
62
=======================================*/
64
/*=======================================
65
Function Implementations
66
=======================================*/
68
scm_initialize_srfi8(void)
70
scm_register_funcs(scm_srfi8_func_info_table);
74
scm_s_srfi8_receive(ScmObj formals, ScmObj expr, ScmObj body,
75
ScmEvalState *eval_state)
77
scm_int_t formals_len, actuals_len;
79
DECLARE_FUNCTION("receive", syntax_variadic_tailrec_2);
81
env = eval_state->env;
84
* (receive <formals> <expression> <body>)
87
formals_len = scm_validate_formals(formals);
88
if (SCM_LISTLEN_ERRORP(formals_len))
89
ERR_OBJ("bad formals", formals);
91
/* FIXME: do we have to extend the environment first? The SRFI-8
92
* document contradicts itself on this part. */
94
* In my recognition, the description in SRFI-8 "The environment in which
95
* the receive-expression is evaluated is extended by binding <variable1>,
96
* ..." does not mean that the environment is extended for the evaluation
97
* of the receive-expression. Probably it only specifies which environment
98
* will be extended after the evaluation. So current implementation is
99
* correct, I think. -- YamaKen 2006-01-05
101
actuals = EVAL(expr, env);
103
if (SCM_VALUEPACKETP(actuals)) {
104
actuals = SCM_VALUEPACKET_VALUES(actuals);
105
actuals_len = scm_finite_length(actuals);
107
actuals = LIST_1(actuals);
111
if (!scm_valid_environment_extension_lengthp(formals_len, actuals_len))
112
ERR_OBJ("unmatched number of args for multiple values", actuals);
113
eval_state->env = env = scm_extend_environment(formals, actuals, env);
115
return scm_s_body(body, eval_state);