Skip to content

Commit

Permalink
Fix bug in function built-in with :documentation symbol
Browse files Browse the repository at this point in the history
Previously it was only including the first expression of the function in the
closure. This because we took body from an element wise iterator. So instead we
have defined a new function `rest` that will take the remainder of a cons iterator.
  • Loading branch information
CeleritasCelery committed Feb 8, 2024
1 parent e425dad commit 9265858
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/core/cons/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl ElemIter<'_> {
self.clone().fallible().count()
}

/// Take the rest of the list as a cons.
pub(crate) fn rest(&self) -> Result<Option<&Cons>, ConsError> {
self.0.cons.transpose()
}

pub(crate) fn fallible(self) -> fallible_iterator::Convert<Self> {
fallible_iterator::convert(self)
}
Expand Down
14 changes: 9 additions & 5 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ impl Interpreter<'_, '_> {

/// Handle special case of (:documentation form) to build the docstring
/// dynamically. If the docstring is not of this form, just return the current body.
fn replace_doc_symbol<'ob>(&mut self, quoted: &Rt<GcObj>, cx: &'ob mut Context) -> Result<GcObj<'ob>, EvalError> {
fn replace_doc_symbol<'ob>(
&mut self,
quoted: &Rt<GcObj>,
cx: &'ob mut Context,
) -> Result<GcObj<'ob>, EvalError> {
// quoted = ((<args..>) (doc_str) ...)
let docstring = {
let Ok(list) = quoted.bind(cx).as_list() else { return Ok(quoted.bind(cx)) };
Expand All @@ -263,10 +267,10 @@ impl Interpreter<'_, '_> {
}
};
// ((<args..>) (:documentation <form>) body)
let mut forms = quoted.bind(cx).as_list().unwrap().fallible();
let arg_list = forms.next()?.unwrap();
let _old_doc = forms.next()?.unwrap();
let body = forms.next()?.unwrap_or_default();
let mut forms = quoted.bind(cx).as_list().unwrap();
let arg_list = forms.next().unwrap()?;
let _old_doc = forms.next().unwrap()?;
let body = forms.rest()?.map(|x| x.into()).unwrap_or(NIL);
Ok(Cons::new(arg_list, Cons::new(docstring, body, cx), cx).into())
}

Expand Down

0 comments on commit 9265858

Please sign in to comment.