Erlang/OTP Forums

Author Message

<  Erlang  ~  "Bootstrapping" function - problem

wolfgke
Posted: Thu Oct 18, 2007 3:49 pm Reply with quote
User Joined: 16 Sep 2007 Posts: 16
Dear people,
I wrote the following code:

Code:

-module(stream).
-export([const_stream/1]).

const_stream(N) -> {N, fun() -> const_stream(N)}.


What it is supposed to do should be rather obvious (if not, I could, of course explain it Wink ).

When I try to compile it I get the following set of errors:

Quote:

./stream.erl:4: syntax error before: '}'
./stream.erl:2: function const_stream/1 undefined


So please could you tell me how to fix that code Smile
View user's profile Send private message
hao
Posted: Thu Oct 18, 2007 5:11 pm Reply with quote
User Joined: 20 Aug 2007 Posts: 18 Location: Uppsala, Sweden
Hi, wolfgke,

There is a syntax error before '}'. It is because you missed the 'end' when defining a fun() variable. The correct version of code should be like this:

Code:

-module(stream).
-export([const_stream/1]).

const_stream(N) ->
    {N, fun() -> const_stream(N) end}.


Arrow fun() -> a few lines of code end Wink
View user's profile Send private message Send e-mail MSN Messenger
wolfgke
Posted: Thu Oct 18, 2007 6:59 pm Reply with quote
User Joined: 16 Sep 2007 Posts: 16
Thank you.

Oh dear, I was scatterbrained Sad
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum