[Grace-core] Assignment return values and null

Jan Larres jan at majutsushi.net
Tue Jun 26 05:56:42 PDT 2012


Hi Bart,

Bart Jacobs <bart.jacobs at cs.kuleuven.be>:
> recurse { me ->
>     def line = myfile.getline
>     if (!myfile.eof) {
>         print(line)
>         me.apply()
>     }
> }
>
> where
>
> method recurse(body) { body.apply(body) }

That's kind of a neat trick, but it isn't exactly intuitive for
beginners to use recursion for doing something sequential like looping
over the lines in a file. It would also need to be tail call optimized
or you will get a stack overflow with larger files.

Just in case my original message wasn't quite clear, I wasn't looking
for the most theoretically elegant solution just for myself, I was
trying to figure out a simple, straightforward way for the language
target audience of beginning students.

> Or still nicer perhaps:
>
> loop { break ->
>     def line = myfile.getline; if (myfile.eof) { break.apply() }
>     print(line)
> }
>
> where
>
> method loop(body) {
>     def myBreakException = new Exception
>     try {
>         def break = { -> throw myBreakException }
>         while {true} do {
>             body.apply(break)
>         }
>     } catch { (myBreakException) -> }
> }

I'm not sure I would call this "nice" -- in my opinion it mainly
demonstrates that there's a real need for proper break/continue
statements in Grace. Passing around and applying 'break' blocks would
most likely seem pretty arbitrary to beginners.

Thanks for the input! Given how the language currently works your ideas
are certainly reasonable. I just think that there should be more
straight-forward ways of doing this, considering what the actual goal of
the language is.

Jan

-- 
-[ OpenPGP key ID: 00A0FD5F ]-
It's hard to be religious when certain people are never incinerated by bolts
of lightning.
                -- Calvin, "Calvin & Hobbes"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20120627/41a7b63d/attachment.pgp>


More information about the Grace-core mailing list