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

Definitional Returns. Solved. #136

Merged
merged 1 commit into from
Nov 1, 2015
Merged

Definitional Returns. Solved. #136

merged 1 commit into from
Nov 1, 2015

Conversation

hostilefork
Copy link
Member

You heard it here first. The console says it all... ;-P

>> foo: func [x] [return x 20]
== make function! [[x /local return][
    return: make function! [
        ["Returns a value from a function." value [any-value!]]
        [throw/name value bind-of 'return]
    ]
    catch/name [
        return x 20
    ] bind-of 'return
]]

>> foo 10
== 10

If you do not wish to have your function bind or provide a definitional return use
<transparent>:

>> bar: func [<transparent> y] [return y 304]
== make function! [[y][return y 304]]

>> bar 1020
** User error: {RETURN called--but no function generator providing it in use}

...of course, the console does NOT tell the whole story. The code may not either
but there are a lot of comments. Blog posts and videos forthcoming.

Happy Halloween 2015... and Ren/C'ing is Ren/beliving...

(Note: With the machinery in place, efficiency passes have already begun....)

You heard it here first.  The console says it all... ;-P

    >> foo: func [x] [return x 20]
    == make function! [[x /local return][
        return: make function! [
            ["Returns a value from a function." value [any-value!]]
            [throw/name value bind-of 'return]
        ]
        catch/name [
            return x 20
        ] bind-of 'return
    ]]

    >> foo 10
    == 10

If you do not wish to have your function bind or provide a definitional return use
<transparent>:

    >> bar: func [<transparent> y] [return y 304]
    == make function! [[y][return y 304]]

    >> bar 1020
    ** User error: {RETURN called--but no function generator providing it in use}

...of course, the console does NOT tell the whole story.  The code may not either
but there are a lot of comments.  Blog posts and videos forthcoming.

Happy Halloween 2015... and Ren/C'ing is Ren/beliving...
@hostilefork hostilefork merged commit fd5f4d6 into metaeducation:master Nov 1, 2015
@hostilefork
Copy link
Member Author

And how are we doing on performance, you ask?

RebolSource:
    >> delta-time [do %make-hostilefork.reb]
    == 0:00:09.31108

Ren/C:
    >> delta-time [do %make-hostilefork.reb]
    == 0:00:10.010641

Doesn't seem too bad a price to pay, eh? And there's plenty of headroom for optimizations with the correctnesses in place...

@hostilefork hostilefork deleted the the-truth-the-shadow-and-the-solution branch November 2, 2015 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant