yield

27 views
Skip to first unread message

rogerdpack

unread,
May 25, 2011, 6:40:04 PM5/25/11
to The Mirah Programming Language
Hello all. Does mirah handle blocks? If no, what is the future plan
to handle them?

c:\>cat go.mir
def go
yield 3
end

a = 3
go {|n|
a = 4
}

c:\>jruby -S mirahc -j go.mir
Parsing...
go.mir
go.mir:2: undefined method `transform_yield' for
#<Mirah::AST::TransformHelper:0x8fc7a7>
yield
^^^^^^

Thanks!
-roger-

Rib Rdb

unread,
May 25, 2011, 7:32:42 PM5/25/11
to mi...@googlegroups.com
We don't support yield. You need to define an interface to use a block:

interface MyInterface do
  def run:int; end
end

def go(block:MyInterface)
  block.run(3)
end

a = 3
go {|n| a = 4}

rogerdpack

unread,
May 25, 2011, 8:40:31 PM5/25/11
to The Mirah Programming Language
> We don't support yield. You need to define an interface to use a block:

Interesting.

I was able to get it working with

interface MyInterface do
def run(a:int):void; end
end

def go(block:MyInterface)
block.run(3)
end
a = 3
go {|n| a = 4}

my attempt at returning a value out of the block didn't seem to work.

https://gist.github.com/992308#file_gistfile2.txt

Maybe I'm doing something wrong?

Thanks!
-roger-

Nick Howard

unread,
May 25, 2011, 9:11:23 PM5/25/11
to mi...@googlegroups.com

Try changing your interface to have a return value of int.
interface MyInterface do
 def run(a:int):int; end
end

rogerdpack

unread,
May 25, 2011, 9:20:40 PM5/25/11
to The Mirah Programming Language
> Try changing your interface to have a return value of int.
> interface MyInterface do
>  def run(a:int):int; end
> end

Yeah I think that is this instance here:

https://gist.github.com/992308#file_gistfile2.txt

perhaps you can see something I'm doing wrong?
Thanks!
-roger-

Nick Howard

unread,
May 25, 2011, 9:30:12 PM5/25/11
to mi...@googlegroups.com

Is this with the released version or the one from git? A fix to a similar issue was commited a few weeks ago.

rogerdpack2

unread,
May 26, 2011, 8:15:32 AM5/26/11
to The Mirah Programming Language
> Is this with the released version or the one from git? A fix to a similar
> issue was commited a few weeks ago.

It appears to still be the case with HEAD from github. Interestingly,
mirahc works fine with it, but mirah itself doesn't.
I suppose I should file a ticket?

rogerdpack

unread,
May 28, 2011, 10:23:09 AM5/28/11
to The Mirah Programming Language
> I suppose I should file a ticket?

http://code.google.com/p/mirah/issues/detail?id=59

Also here's a question:

interface MyInterface do
def run(a:int); end
end
def go(block:MyInterface)
block.run(3)
end

go { 4 }

results in this error message:

Inference Error:
yoyo.mir:13: Inferred return type Type(void) is incompatible with
declared Type(null)

What's the difference between Type(void) and Type(null)?

Thanks!
-roger-
Reply all
Reply to author
Forward
0 new messages