Patch: command line options / batch / non-interactive

124 views
Skip to first unread message

Neal Alexander

unread,
Oct 9, 2016, 9:40:21 AM10/9/16
to Shen
This patch against the SBCL version of BSD Shen 19.2 adds:
  • Support for batch processing: shen.exe: [-t] [-e string] [-l filename]

    -t : toggle type checking
    -e : eval, print, exit
    -l : load script, exit

  • A new global variable *system-argv*

Install:
cd "Shen 19.2"; patch -p0 < ../shen_batch_mode.patch

Usage:
> shen -e "[1 a]" -t -e "[1 1]" -e 3 -t -e 4
[1 a]
"[1 1] : (list number)"
"3 : number"
4

Caveats:
  • Tested on windows 10 with SBCL 1.3.10, and Microsoft's linux subsystem version of 'patch'.
  • control-c isn't working right in REPL mode - no clue why.
  • SBCL doesn't strip its own runtime command line options, so it is handled by "install.lsp" in a pretty stupid way.

shen_batch_mode.patch

deech

unread,
Oct 9, 2016, 11:11:54 AM10/9/16
to Shen
Neat! You can now submit this as a PR to https://github.com/Shen-Language/shen-sources if you want.

Bruno Deferrari

unread,
Oct 9, 2016, 11:35:19 AM10/9/16
to qil...@googlegroups.com
On Sun, Oct 9, 2016 at 11:55 AM, deech <aditya...@gmail.com> wrote:
Neat! You can now submit this as a PR to https://github.com/Shen-Language/shen-sources if you want.



That repository contains only the Shen kernel sources (which are port agnostic), so it is not really the place to submit this.

The BSD Common Lisp port is not on Github right now, and it has no maintainer at the moment, maybe Neal is interested in doing that? or anyone who is interested and feels comfortable doing so.

I could do it but I'm not an user of the Common Lisp port myself, so I would rather not.

About the patch itself, it look good, but some of the changes happen in the kernel, and in a way that will break other ports. I don't know if command line handling is something that should be added to the kernel right now.

It seems to me that for now it is something that each port should handle itself, until a common interface can be discussed. For example, a new (optional so that nothing breaks) primitive could be added that returns a list of command line arguments, like the command-line function in shen-scheme: https://github.com/tizoc/shen-scheme#command-line-arguments

Then the kernel could be modified to provide two entry points: shen.shen (the current entry point, maybe rename/alias to shen.run-repl ?) and shen.run-batch (which would look very similar to Neal's batch-mode function but with an option for port writters to add a hook to handle extra flags).

Here is a placeholder issue on Github for discussing that: https://github.com/Shen-Language/shen-sources/issues/3

 
On Sunday, October 9, 2016 at 8:40:21 AM UTC-5, Neal Alexander wrote:
This patch against the SBCL version of BSD Shen 19.2 adds:
  • Support for batch processing: shen.exe: [-t] [-e string] [-l filename]

    -t : toggle type checking
    -e : eval, print, exit
    -l : load script, exit

  • A new global variable *system-argv*

Install:
cd "Shen 19.2"; patch -p0 < ../shen_batch_mode.patch

Usage:
> shen -e "[1 a]" -t -e "[1 1]" -e 3 -t -e 4
[1 a]
"[1 1] : (list number)"
"3 : number"
4

Caveats:
  • Tested on windows 10 with SBCL 1.3.10, and Microsoft's linux subsystem version of 'patch'.
  • control-c isn't working right in REPL mode - no clue why.
  • SBCL doesn't strip its own runtime command line options, so it is handled by "install.lsp" in a pretty stupid way.

--
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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

deech

unread,
Oct 9, 2016, 11:43:57 AM10/9/16
to Shen
You're right, I keep forgetting that the SBCL port is not on Github. I'm just so used to seeing it when I download the sources from the web page. Sorry.
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 https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Bruno Deferrari

unread,
Oct 9, 2016, 11:46:19 AM10/9/16
to qil...@googlegroups.com
On Sun, Oct 9, 2016 at 12:42 PM, deech <aditya...@gmail.com> wrote:
You're right, I keep forgetting that the SBCL port is not on Github. I'm just so used to seeing it when I download the sources from the web page. Sorry.


No problem. Btw, does command line handling make sense in the case of the elisp port? (it was the main reason for me thinking that the new primitive should be optional, the other reason is that it would be less work to update ports to the new version without breaking)
 
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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

deech

unread,
Oct 9, 2016, 11:58:09 AM10/9/16
to Shen
I don't see how. It would be an awkward hack at best. Instead of command line if the primitve were something like "user defined start-up environment" it might make more sense. That way ports that run on the command line can have arguments and ports like JS can interpret that as they wish, perhaps as arguments to the main loop.

Bruno Deferrari

unread,
Oct 9, 2016, 1:06:35 PM10/9/16
to qil...@googlegroups.com
I added some content to the issue with some basic proposals. If anyone has any suggestion or comment, please add a comment on the issue: https://github.com/Shen-Language/shen-sources/issues/3

It only covers command line access and how ports could make the command line arguments available. Neil's patch is a bit more extense than that (it adds extra modes for running shen other than going directly to the REPL, like loading running Shen source files without going through the REPL and also evaluation short expressions, those can be discussed in a separate issue).

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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Neal Alexander

unread,
Oct 9, 2016, 11:30:31 PM10/9/16
to Shen
I actually know nothing about common lisp (and don't really have much motivation to familiarize myself with the standard), but I'll maintain it til someone better comes along.

https://github.com/NHALX/Shen-SBCL

The above patch is applied to the experimental branch.

Neal Alexander

unread,
Oct 10, 2016, 5:52:48 AM10/10/16
to Shen
Partial function errors block waiting for user input: 
partial function primitive-constants;
track primitive-constants?  (y/n)

Is there an option to disable this, and are there any other error conditions produced by Shen that expect user input? They need to be disabled for batch processing.

Bruno Deferrari

unread,
Oct 10, 2016, 8:35:07 AM10/10/16
to qil...@googlegroups.com
On Mon, Oct 10, 2016 at 4:59 AM, Neal Alexander <nha...@gmail.com> wrote:
Partial function errors block waiting for user input: 
partial function primitive-constants;
track primitive-constants?  (y/n)

Is there an option to disable this, and are there any other error conditions produced by Shen that expect user input? They need to be disabled for batch processing.


Not without modifying the code. When compiling define's cases Shen generates a default case in case that will be called if the cases defined by the user are not exhaustive and the function is called with a value that is not matched by them.


default case generated here (and functions defined before in that file)


One solution is to have a global variable switch so that when in batch mode shen generates a different default case. Another (easier) solution is to have a global variable switch that f_error will check for before asking for before printing the tracking prompt (and instead just raising an error).
 

On Sunday, October 9, 2016 at 3:40:21 PM UTC+2, Neal Alexander wrote:
This patch against the SBCL version of BSD Shen 19.2 adds:
  • Support for batch processing: shen.exe: [-t] [-e string] [-l filename]

    -t : toggle type checking
    -e : eval, print, exit
    -l : load script, exit

  • A new global variable *system-argv*

Install:
cd "Shen 19.2"; patch -p0 < ../shen_batch_mode.patch

Usage:
> shen -e "[1 a]" -t -e "[1 1]" -e 3 -t -e 4
[1 a]
"[1 1] : (list number)"
"3 : number"
4

Caveats:
  • Tested on windows 10 with SBCL 1.3.10, and Microsoft's linux subsystem version of 'patch'.
  • control-c isn't working right in REPL mode - no clue why.
  • SBCL doesn't strip its own runtime command line options, so it is handled by "install.lsp" in a pretty stupid way.

--
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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Mark Tarver

unread,
Oct 10, 2016, 8:44:12 AM10/10/16
to qil...@googlegroups.com
I'm not sure you really want to block this stuff.  It's better to make sure such messages are not generated or else simply to put in your own default meaningful message by closing off the function definition and making it total.  

A computer-generated  "partial function error in comp-function-disassembly" or whatever doesn't mean anything to the end-user and may not mean much to you until you track it.  There is a piece in TBoS about why its often good to personalise error messages.

Mark  

Neal Alexander

unread,
Oct 10, 2016, 10:04:24 AM10/10/16
to Shen
Bruno's second suggestion seems best. The partial function error message may be cryptic, but consider that "shen -l broken.shen > output.txt" will just blindly hang waiting on user input without any sort of prompt.

It's better to hard error in batch-mode, since a higher level script calling shen wont be able to fix the problem anyway.
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 https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
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+un...@googlegroups.com.

Bruno Deferrari

unread,
Oct 10, 2016, 10:12:42 AM10/10/16
to qil...@googlegroups.com
I created an issue on Github to track the discussion about what to do and how to update the kernel and ports (if at all) to support a batch execution mode. It is here https://github.com/Shen-Language/shen-sources/issues/4

It is not complete but it is a start.

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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Bruno Deferrari

unread,
Apr 8, 2017, 5:13:09 PM4/8/17
to qil...@googlegroups.com
Neal, I figured out how to ignore the SBCL command line options, there is a :save-runtime-options keyword arguments for save-lisp-and-die that does this. I enabled it in https://github.com/Shen-Language/shen-sbcl

I'm pretty sure the Ctrl-C issue is solvable too, I will probably investigate that soon.
--
BD

Bruno Deferrari

unread,
Apr 8, 2017, 5:36:10 PM4/8/17
to qil...@googlegroups.com

Neal Alexander

unread,
Apr 9, 2017, 9:21:28 AM4/9/17
to Shen
Thanks Bruno, I merged the changes into my branch.

Ctrl-C still doesn't work here, but i'll worry about it later.

Was it a change to Shen 20 that fixed it, or the SBCL exception handler?
--
BD



--
BD

Bruno Deferrari

unread,
Apr 9, 2017, 9:22:36 AM4/9/17
to qil...@googlegroups.com
The SBCL exception handler. A change I made to the ShenOS kernel is that Ctrl+D also exists the REPL, as long as there is no input in the current prompt (otherwise it is ignored).

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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Bruno Deferrari

unread,
Apr 9, 2017, 9:26:40 AM4/9/17
to qil...@googlegroups.com
Btw, what do you see when you press Ctrl+C ? Before making the change what I got was the SBCL debugger (because of the uncaught SB-SYS:INTERACTIVE-INTERRUPT exception).
--
BD

Neal Alexander

unread,
Apr 9, 2017, 10:57:19 AM4/9/17
to Shen
Ctrl+C <enter> <enter> at the prompt gives:

(0-)

The value
  -1
is not of type
  (MOD 1114112)

Bruno Deferrari

unread,
Apr 9, 2017, 11:00:48 AM4/9/17
to qil...@googlegroups.com
Thats weird, -1 is what you get on EOF (which ctrl+d triggers, thats one of the things I solved).

Can you pull from the new repo I created and give it a try?


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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Neal Alexander

unread,
Apr 9, 2017, 11:19:58 AM4/9/17
to Shen
Ctrl-C works fine in your repo. There is probably some strange namespace issue in my local copy or something.

The "Native" dir needs to be manually created after a fresh git clone of your repository btw.

Bruno Deferrari

unread,
Apr 9, 2017, 11:20:33 AM4/9/17
to qil...@googlegroups.com
On Sun, Apr 9, 2017 at 12:17 PM, Neal Alexander <nha...@gmail.com> wrote:
Ctrl-C works fine in your repo. There is probably some strange namespace issue in my local copy or something.

The "Native" dir needs to be manually created after a fresh git clone of your repository btw.

Thanks, I will fix that later today.
 
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 email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



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