This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Query on using `stream-cons' with srfi-14
- From: Kumar Appaiah <a dot kumar at alumni dot iitm dot ac dot in>
- To: kawa at sourceware dot org
- Date: Thu, 24 Jul 2014 09:13:41 +0530
- Subject: Re: Query on using `stream-cons' with srfi-14
- Authentication-results: sourceware.org; auth=none
- References: <20140723112307 dot GA11004 at odessa> <53CFF493 dot 9000706 at bothner dot com>
On Wed, Jul 23, 2014 at 10:44:51AM -0700, Per Bothner wrote:
>
>
> On 07/23/2014 04:23 AM, Kumar Appaiah wrote:
> >Hi.
> >
> >I'm trying out the SICP examples on streams using kawa. I am currently
> >stuck on a stream example. The particular blurb of code is:
> >
> >(define cons-stream stream-cons)
> >(define the-empty-stream stream-null)
> > ...
> >Running this gives me the following error:
> >Argument '#<macro stream-cons>' to 'apply-to-args' has wrong type (kawa.lang.Macro) (expected: procedure)
> > at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:165)
>
> >What am I doing wrong? Please let me know if I am not being clear.
>
> stream-cons is syntax - specifically a macro.
> It doesn't work to treat it as a value that is
> available at run-time. (It might be reasonable for Kawa
> to warn about this.)
>
> You would need to define cons-stream as a macro, for
> example (untested code):
>
> (define-syntax cons-stream
> (syntax-rules ()
> ((_ a b) (stream-cons a b))))
Indeed, this works well. I was not acquainted with define-syntax and
friends, so thank you for the explanation.
Kumar
--
Kumar Appaiah