* Query on using `stream-cons' with srfi-14
@ 2014-07-23 11:23 Kumar Appaiah
2014-07-23 17:45 ` Per Bothner
0 siblings, 1 reply; 5+ messages in thread
From: Kumar Appaiah @ 2014-07-23 11:23 UTC (permalink / raw)
To: kawa
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)
(define (stream-enumerate-interval low high)
(if (> low high)
the-empty-stream
(cons-stream
low
(stream-enumerate-interval (+ low 1) high))))
The full code can be found on this page:
https://gist.github.com/kumanna/94cb8bb130fed4805d21
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)
at gnu.mapping.ProcedureN.apply3(ProcedureN.java:48)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.streamEnumerateInterval(3-streams-1.scm:89)
at atInteractiveLevel$21.apply2(3-streams-1.scm:84)
at gnu.expr.ModuleMethod.apply2(ModuleMethod.java:198)
at atInteractiveLevel$23.lambda1(3-streams-1.scm:98)
at atInteractiveLevel$23.apply0(3-streams-1.scm:98)
at gnu.expr.ModuleBody.applyN(ModuleBody.java:233)
at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:216)
at gnu.kawa.functions.ApplyToArgs.applyN(ApplyToArgs.java:137)
at gnu.mapping.ProcedureN.apply1(ProcedureN.java:31)
at atInteractiveLevel$8.timeExecute(3-streams-1.scm:45)
at atInteractiveLevel$8.apply1(3-streams-1.scm:43)
at gnu.expr.ModuleMethod.apply1(ModuleMethod.java:192)
at gnu.expr.ModuleMethod.apply(ModuleMethod.java:163)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:234)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:373)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:210)
at kawa.Shell.run(Shell.java:279)
at kawa.Shell.runFile(Shell.java:482)
at kawa.Shell.runFileOrClass(Shell.java:420)
at kawa.repl.processArgs(repl.java:250)
at kawa.repl.main(repl.java:850)
What am I doing wrong? Please let me know if I am not being clear.
Thanks.
Kumar
--
Kumar Appaiah
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Query on using `stream-cons' with srfi-14
2014-07-23 11:23 Query on using `stream-cons' with srfi-14 Kumar Appaiah
@ 2014-07-23 17:45 ` Per Bothner
2014-07-23 18:01 ` Jamison Hope
2014-07-24 3:43 ` Kumar Appaiah
0 siblings, 2 replies; 5+ messages in thread
From: Per Bothner @ 2014-07-23 17:45 UTC (permalink / raw)
To: kawa, Kumar Appaiah
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))))
--
--Per Bothner
per@bothner.com http://per.bothner.com/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Query on using `stream-cons' with srfi-14
2014-07-23 17:45 ` Per Bothner
@ 2014-07-23 18:01 ` Jamison Hope
2014-07-24 3:42 ` Kumar Appaiah
2014-07-24 3:43 ` Kumar Appaiah
1 sibling, 1 reply; 5+ messages in thread
From: Jamison Hope @ 2014-07-23 18:01 UTC (permalink / raw)
To: kawa@sourceware.org list
On Jul 23, 2014, at 1:44 PM, Per Bothner <per@bothner.com> 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))))
It'll also work to define cons-stream as an alias:
(define-alias cons-stream stream-cons)
At least that works at the REPL with a slightly out-of-date
build of Kawa circa r7863 or so.
BTW the streams stuff is in SRFI-41, not SRFI-14. At first
I was very confused by what the char-set library had to do
with streams working or not working.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Query on using `stream-cons' with srfi-14
2014-07-23 18:01 ` Jamison Hope
@ 2014-07-24 3:42 ` Kumar Appaiah
0 siblings, 0 replies; 5+ messages in thread
From: Kumar Appaiah @ 2014-07-24 3:42 UTC (permalink / raw)
To: kawa
On Wed, Jul 23, 2014 at 02:00:56PM -0400, Jamison Hope wrote:
> >
> >> 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))))
>
>
> It'll also work to define cons-stream as an alias:
>
> (define-alias cons-stream stream-cons)
Thanks. This works perfectly.
> BTW the streams stuff is in SRFI-41, not SRFI-14. At first
> I was very confused by what the char-set library had to do
> with streams working or not working.
Sorry. This was an idiotic typo; the code actually "requires"
srfi-41. Sorry!
Kumar
--
Kumar Appaiah
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Query on using `stream-cons' with srfi-14
2014-07-23 17:45 ` Per Bothner
2014-07-23 18:01 ` Jamison Hope
@ 2014-07-24 3:43 ` Kumar Appaiah
1 sibling, 0 replies; 5+ messages in thread
From: Kumar Appaiah @ 2014-07-24 3:43 UTC (permalink / raw)
To: kawa
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-24 3:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-23 11:23 Query on using `stream-cons' with srfi-14 Kumar Appaiah
2014-07-23 17:45 ` Per Bothner
2014-07-23 18:01 ` Jamison Hope
2014-07-24 3:42 ` Kumar Appaiah
2014-07-24 3:43 ` Kumar Appaiah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).