Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should an empty block evaluate to? #36

Open
ltratt opened this issue May 31, 2020 · 3 comments
Open

What should an empty block evaluate to? #36

ltratt opened this issue May 31, 2020 · 3 comments
Labels
language design This issue requires design decisions spec Needs specification, or is specification related.

Comments

@ltratt
Copy link

ltratt commented May 31, 2020

What should this program print?

empty_block = (
    run = (
        [] value println.
    )
)

Java SOM prints "instance of Block1". There's nothing wrong with that per se, but it wasn't what I was expecting because a) (at least as far as I know) blocks can't get access to their instances under normal circumstances b) methods return self unless otherwise specified. I wondered if this was intentional or not? I couldn't find any obvious clues in Java SOM's source to indicate anything either way.

@smarr smarr added language design This issue requires design decisions spec Needs specification, or is specification related. labels May 31, 2020
@smarr
Copy link
Member

smarr commented May 31, 2020

Hmpf. You're too good at this...

The answer should really be nil, following all other Smalltalks I tested.

Blocks return the value of their last expression. Since there was no expression, there's no value.
At least that would be my interpretation of what the other Smalltalks do (GNU Smalltalk, Amber Smalltalk, Squeak 2, 5, and Pharo).

@ltratt
Copy link
Author

ltratt commented May 31, 2020

My main skill here is ignorance! nil was what I was vaguely expecting, and it's easy to implement, so I won't complain!

bors bot added a commit to softdevteam/yksom that referenced this issue Jun 1, 2020
128: Empty blocks evaluate to nil. r=ptersilie a=ltratt

Whilst here, it is silly for `add_global` to take a `String` when both callers have to call `to_owned` for the `&str` they really have.

Note this is different behaviour from (at least) Java SOM (see SOM-st/SOM#36).

Co-authored-by: Laurence Tratt <[email protected]>
@smarr
Copy link
Member

smarr commented Aug 24, 2020

Adding tests with #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language design This issue requires design decisions spec Needs specification, or is specification related.
Projects
None yet
Development

No branches or pull requests

2 participants