Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Aw: Re: [feature wishl] stdin and stdout


[Putting this back on the list, as others may find the bit
about __init__ useful]

On Sat, 26 Dec 2015 23:02:32 +0100, a.regenfuss@xxxxxx wrote:

> 
> >Where/what APIs are you interested in adding? Are you suggesting
> >bio provide bio.^(In Out Err), or something more than that?
> 
> I guess bio seems to be the right place, because it works well
> with bio.^(In Out Err) as file structures and not only as file
> descriptors.

Well, sort of. Unlike C's stdin/stdout/stderr, there is no automatic
flushing with Myrddin bio: You must either close or explicitly flush
the streams yourself. So they're not direct replacements.

> About the implementation: I guess just opening "/dev/stdin"
> would not be enough since this is not guaranteed to be portable.

What problem, exactly, are you trying to solve?

> One possible solution to this would be opening the file-descriptor [0, 1, 2]
> (like you did in std.put) when bio is started.

The operating system opens fd 0, 1, 2 for you at program start on all
Unixy systems; For now, at least, that should be safe to use. It might
be better to add symbolic constants for it -- I'd accept a patch.

> But I have no idea how I would do that without introducing something like
> bio.init().
> 
> But since you are the language creator, maybe you have got an idea.

Myrddin supports module initializer functions:

	const __init__ = {
		...setup code...
	}

may appear once per file. This initializer will run before main.

In fact, more specifically, the __init__ functions are ordered topologically,
such that each __init__ will be run exactly once, after the __init__
functions of its dependencies (if any), and before any __init__ functions
which depend on it. The order that the dependencies are initialized in is
not guaranteed.

For an example, take a look at

	lib/std/fmtfuncs.myr

-- 
    Ori Bernstein

References:
[feature wishl] stdin and stdouta.regenfuss@xxxxxx
Re: [feature wishl] stdin and stdoutOri Bernstein <ori@xxxxxxxxxxxxxx>