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

DO of a script that's modularized can only return MODULE! #14

Open
Siskin-Bot opened this issue Feb 15, 2020 · 0 comments
Open

DO of a script that's modularized can only return MODULE! #14

Siskin-Bot opened this issue Feb 15, 2020 · 0 comments

Comments

@Siskin-Bot
Copy link

Submitted by: Hostilefork

If you have a script that is not a module, you may be motivated to make it a module in order to get the benefits of features like isolation. So if you have something like:

 Rebol [
     Title: "My fun script"
 ]
 private-fun: function [] [print "I am private"]
 fun: function [] [print "I am public" private-fun]

 print "Type FUN for enjoyment"
 1 + 2

You might want the behavior with DO to say:

>> do %my-fun-script.reb
Type FUN for enjoyment
== 3

Then, if you wanted to get the benefits of a module, you might change the header:

 Rebol [
     Title: "My fun script"
     Type: Module
     Options: [isolate]
     Exports: [fun]
 ]

...BUT... doing this changes the behavior of DO to return a MODULE!, not the last thing evaluated to. If you've configured your console to print out the result (instead of hiding it like R3-Alpha does by default) you might get something like:

>> do %my-fun-script.reb
Type FUN for enjoyment
== make module! [
    fun: 'make action! [[] [...]]
    private-fun: 'make action! [[] [...]]
    function: 'make action! [[spec body] [...]]
    print: 'make action! [[line /html] [...]]
    +: 'make action! [[value1 value2] [...]]
]

So once it's a module, DO no longer gets the result of the body. So this means modularized scripts are not directly interchangeable with non-modularized ones. That's inconvenient.

I'd propose that IMPORT be what returns a module. Then, DO of a module returns the body evaluative result...just as if the script were not a module.

Modules that are named in a header don't have any obvious place to convey their evaluative results to a script that Needs: them. But that's not to say there couldn't be a dialect for capturing them into variables if one wanted:

Needs: [My-Fun-Script => result-var]  ; Random notational idea 

(Note: The specific motivating example I have relates to a console configured to display modules, and not wanting the message to be missed. So there's no particularly interesting return result, and DO could just return VOID!. But as mentioned, this seems like a loss for any script which is just being modularized for context isolation and still wants to return a value.)


Imported from: metaeducation/rebol-issues#2373

Comments:


Hostilefork added Ren.important and Type.wish on Apr 15, 2019


Mark-hi commented on Apr 15, 2019:

(1) Aren't needed modules imported, hence result-var would only hold the module itself?
(2) Just confirming: if you want it silent when done your module body must end with a void, right?


@Oldes Oldes transferred this issue from Oldes/Rebol-issues Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants