| Fellow Arcists, I worked lately to make Arc be more friendly with Unix, the 40 Years Old OS.
I have now a solution that does everything that I want (including running
scripts), so I thought you may like it too. Let's see the results in practice, step by step: 1. Interaction with an human works as previously, except than Arc now exits on
^D (EOF): $ arc
arc> (+ 40 2)
42
arc> ^D
(exit)
$
^D is Control-D and means "End-Of-File". It's the right behaviour to exit when
this special character is read (try in bash, python, ruby, bc, ...).
Once you're used to it (takes 5 secs), ^D is handy ('cause universal) and sooooo
much quicker than typing "(quit)".As you can see, Arc displays "(quit)" before to exit when it catches EOF.
This is not mandatory, even a violation of the "Silence is gold" rule,
but bash does that too, and I like that. 2. The EOF stuff is very not useless. Once we get it, we automatically get the
ability to do (and this is very important): $ echo '(prn "Hello, pipes & co world!")' | arc
Hello, pipes & co world!
$ echo '(prn "Hello, scripts!")' > tmp.arc
$ arc < tmp.arc
Hello, scripts!
$
Because you know, stdin is really just like any file.
(Currently, since Arc doesn't handle EOF very well, trying the previous examples
will result in an infinite loop where Arc displays "#<eof>: Bad object in
expression" again and again).3. Smart readers will have remarked that the previous example should have given: $ echo '(prn "Hello, pipes & co world!")' | arc
arc> (prn "Hello, pipes & co world")
Hello, pipes & co world!
"Hello, pipes & co world!"
arc> (quit)
$
They are right. But we actually can make a distinction between human input
("interactive") and non-human input. For instance, bash does that. See: $ cat ~/.bashrc
...
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
...
So we do that too. We check if stdin is from a terminal, and if so, we
display the prompt, and each evaluation result.
If not, no prompt, and only explicit printing (via 'prn/'write/'etc.) will be
displayed.
(If you prefer to have the eval results always printed, change the value of
not-interactive-write-evalres? in the patched ac.scm.)4. In 2. there is a "Hello, scripts!" example. Actually, this is a lie.
At this point, we can't execute a script that will interact with the user (e.g:
call 'read). But remember, often when you do: $ python some-fake-script-doing-no-interaction.py
$ wc some-file.txt
what you mean is actually (in the True Pedantic Unix Way): $ python < some-fake-script-doing-no-interaction.py
$ wc < some-file.txt
But you don't care about the pedantic note above and just want to run scripts,
ones that interact with the user and ones that don't, and without having to
type '<' each time.
Well, here you have (text between << and >> indicates input by the user): $ cat example-script.arc
#!/usr/bin/env arc
(pr "Enter your name: ")
(prn "Hello, " (readline) "!")
$ arc example-script.arc
Enter your name: <<palsecam>>
Hello, palsecam!
Or even: $ chmod +x example-script.arc
$ ./example-script.arc
Enter your name: <<palsecam>>
Hello, palsecam!
5. Last little thing, the errors are now displayed on stderr. This changes nothing
since by default stderr == stdout, but if you understand the power of
redirections, you may appreciate.6. Oh, and to run scripts, I was obliged to make Arc works even when not called
in its root directory (current/loading directory stuff, in as.scm). 7. That's all. At this point, Arc is usable on Unix IMO, but if you think
that something is missing, please tell me so! ---------- The patch will be posted in a comment. It modifies as.scm and ac.scm, and is 88 lines long (generated with diff -Nurp).
88 lines may seem a lot, but it's not that big when you remove the context lines
and the comments. Plus, there is no complex or tricky modifications. The `arc' command is this little shell program (you can use something different,
an alias for instance, but "./example-script.arc" would not work then): #!/bin/sh
## arc: launcher for Arc. Put this file in your $PATH and chmod +x it.
ARC_DIR="/home/paul/arc/3.1/" # change this, obviously
rlwrap mzscheme -qr ${ARC_DIR}as.scm $@ # $@ holds the list of cmdline args
# notice the mzscheme switch is "-qr" and not "-f" here
Happy Arc hacking on Unix, or, why not, Unix hacking with Arc! |