Re: Separate high-level and low-level APIs hga@xxxxxx 23 Apr 2020 16:19 UTC

> From: Lassi Kortela <xxxxxx@lassi.io>
> Date: Thursday, April 23, 2020 10:38 AM
>
>> What about thinking of SRFI 170 as the low-level bare-metal
>> interface mimicking C/POSIX as much as possible? On top of that, a
>> more Schemely-SRFI could be layered, in which the current working
>> directory is a parameter object. I agree that the per-thread
>> semantics are more sound.
>
> I would tentatively advise against this since there would seem to be
> very little difference between those low-level and high-level APIs.
>
> The low level is:
>
> - Convert Scheme strings and fixnums to C strings and integers
> - Make the syscall
> - C strings and integers back to Scheme strings and integers
> - On error, either return errno as as fixnum or raise exception

Requiring checks for return values is one of the things I most
dislike about POSIX style APIs.

> High level:
>
> - Same as low level
> - Definitely raise exception on errno
> - Definitely translate per-thread umasks and pathnames
> - Not that many other differences?

We avoid some footguns, one you strongly advocated was having
directory listing procedures never return "." and "..", even the
lowest level open-/read-/close-directory wrappers.  John is planning
to go much further with the processes SRFI which was punted for 170.

And we provide some helper functions on top of the POSIX API, for
things people are likely to want, like directory-files which returns
all the files in a directory, and make-directory-files-generator for
when you don't want them all in a list in one go.

> So they sound almost the same.
>
> [ GNOME provides an example of what not to do. ]
>
> By contrast, OS operations that clearly compose several syscalls are
> clearly at a higher level of abstraction and could benefit from
> being in a separate SRFI.

As of now, directory-files and make-directory-files-generator are
examples that are in the SRFI.  The terminal control procedures like
with-raw-mode are an example of all of the above, they both provide
safety as previously mentioned, and also make a number of system calls
to for example get, set, and reset both an input and an output port.

- Harold