Extensions to core Shen in chibi-shen

100 views
Skip to first unread message

Bruno Deferrari

unread,
May 2, 2015, 10:55:43 AM5/2/15
to qil...@googlegroups.com
The next (unreleased) version of chibi-shen will include a few extensions described here:


-------------
* Command line strings can be obtained by calling `(command-line)`, the result is a list of strings, of which the first element is the name of the program, and the rest of the list being the arguments passed to it.
* To exit the process, the `(exit N)` can be called, with `N` being the desired integer exit code.
* A standard error stream can be accessed by calling `(sterror)`.
* Files an be opened for output in "append" mode that doesn't truncate the file by calling `(open-append Filepath)`. The result is an stream handle of type `(stream out)`.
-------------

The code implementing them is here:

https://github.com/tizoc/chibi-shen/blob/master/shen/extras.shen

They are based on what has been discussed on this list already, and ideally we would all agree on a common interface to be used by ports when the functionality is available.

Thoughts?

--
BD

Greg Spurrier

unread,
May 2, 2015, 4:48:36 PM5/2/15
to qil...@googlegroups.com
I will implement these in ShenRuby, too. *sterror* and (exit N) are already available on the master branch. I'll add the other two in the next day or so.

Greg
--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+un...@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at http://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.

Bruno Deferrari

unread,
May 3, 2015, 2:01:03 PM5/3/15
to qil...@googlegroups.com
I added the following functions for controlling stream positions ("seek" and "tell" functionality):

stream-position            (stream A) --> number
stream-seek                (stream A) --> number --> number
stream-seek-from-current   (stream A) --> number --> number
stream-seek-from-end       (stream A) --> number --> number

--
BD

Bruno Deferrari

unread,
May 3, 2015, 2:03:30 PM5/3/15
to qil...@googlegroups.com
Btw feel free to suggest different names, args, etc, some things could be different, for example, the stream-seek functions could return the stream instead of the passed position value, I didn't give it much thought.
--
BD

Ramil Farkhshatov

unread,
May 3, 2015, 2:51:27 PM5/3/15
to qil...@googlegroups.com
Bruno Deferrari <uti...@gmail.com> wrote:

> Btw feel free to suggest different names, args, etc, some things could be
> different, for example, the stream-seek functions could return the stream
> instead of the passed position value, I didn't give it much thought.

I think that returning resulting position is more useful. But would
prefer more consistent syntax.

stream-position (stream A) --> number
stream-set-position (stream A) --> number --> number

or

stream-position (stream A) --> number
stream-position-> (stream A) --> number --> number

Also I am not sure about these:

stream-seek-from-current (stream A) --> number --> number
stream-seek-from-end (stream A) --> number --> number

probably

stream-position-> (stream A) --> number --> symbol --> number

would be more 'idiomatic'.
> To post to this group, send an email to qil...@googlegroups.com.

Bruno Deferrari

unread,
May 3, 2015, 3:15:17 PM5/3/15
to qil...@googlegroups.com
On Sun, May 3, 2015 at 3:51 PM, Ramil Farkhshatov <ra...@gmx.co.uk> wrote:
Bruno Deferrari <uti...@gmail.com> wrote:

> Btw feel free to suggest different names, args, etc, some things could be
> different, for example, the stream-seek functions could return the stream
> instead of the passed position value, I didn't give it much thought.

I think that returning resulting position is more useful. But would
prefer more consistent syntax.

    stream-position            (stream A) --> number
    stream-set-position        (stream A) --> number --> number

or

    stream-position            (stream A) --> number
    stream-position->          (stream A) --> number --> number

Also I am not sure about these:

    stream-seek-from-current   (stream A) --> number --> number
    stream-seek-from-end       (stream A) --> number --> number

probably

    stream-position->          (stream A) --> number --> symbol --> number

would be more 'idiomatic'.


I thought about that one, but in that case you have to either make the type theory more complicated (you now need a "relative-to" argument with a specific type that only allows for valid options**), or you are open to failure cases that don't exist now (invalid symbol was passed, in which case you have to raise an error at runtime or fail silently by picking a default behaviour).

Because of this, and because it was more direct than dispatching over a symbol's value, I decided that having separate functions for each case was the better choice (and the naming was a direct result from this), at least when thinking of them as primitives (a more aesthetically pleasing API can be built on top with little work).

Anyway, that was my reasoning, if others don't think it is not that important we can do it differently.

** this is not usually a problem, it is just that in this case, the code is either precompiled Shen (that extras.shen file gets compiled to Scheme code as part of the building process), or may be implemented on the compiler/runtime directly, and at that level is is not as simple to extend Shen's type theory which is something that only exists while Shen itself is running, but not at lower levels.

Calling `declare` takes care of extending this type theory at runtime in the case of type signatures, but there is nothing like it for other things (like saying that absolute/relative/from-end are the only valid positioning symbols).
Such function could be written (just in the same way as `declare`), but it was extra work and I don't think this specific case warrants it.




--
BD

Bruno Deferrari

unread,
May 3, 2015, 4:02:36 PM5/3/15
to qil...@googlegroups.com
Another option is to just have (stream-position-> Stream Pos), where Pos is always absolute, from the beginning if positive, and from the end if negative. For relative positioning one would have to do:

(stream-position-> Stream (+ Offset (stream-position Stream)))
 
It means more operations will be needed for that case, but most of the time it will not matter (and for then it does, one just has to access more primitive functions through the FFI).

Thoughts?



--
BD

Mark Tarver

unread,
May 5, 2015, 8:01:32 AM5/5/15
to qil...@googlegroups.com
I think that this is something beyond the standard you all need to reach a common agreement on.    I'm writing the first of a series of Shen reports, this on file handling and parsing text.  The report series is designed to be a series of cheaply available reports (about £5 each) on aspects of coding in Shen and each about 50-60 sides in length.  

Mark

> >> To post to this group, send email to qil...@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/qilang.
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Shen" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an

> >> To post to this group, send email to qil...@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/qilang.
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
> >
> >
> > --
> > BD
> >
>
>
>
> --
> BD
>
> --
> You received this message because you are subscribed to the Google Groups "Shen" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
> To post to this group, send an email to qil...@googlegroups.com.
> Visit this group at http://groups.google.com/group/qilang.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send an email to qil...@googlegroups.com.
Visit this group at http://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD



--
BD
Reply all
Reply to author
Forward
0 new messages