I see that you've got some code that's working, but if you want to extend it more, I'll recommend a unit test library I wrote. You might find some unit tests helpful to know when your code is working. The library is https://bitbucket.org/zck/unit-test.arc/ .
You'll make unit tests inside a test suite, like so:
I open up a shell in Emacs (M-x shell), then run Arc manually. You have to explicitly `load` things from the REPL; there isn't any SLIME-like communication between other buffers and the shell. This doesn't seem to work right now with Anarki, but it does with Arc3.1
Now that I've been able to test it, this works, as long as you don't have empty lines in your file. If you do, it works...oddly:
This file:
This is the first line.
After this line there is an empty line.
After this line there are two empty lines.
This is the last line.
results in this list:
arc> (read-all "/home/zck/test.txt")
("This is the first line." "After this line there is an empty line." "\nAfter this line there are two empty lines." "\n" "This is the last line.")
Note how the newline after the first empty line gets glommed onto the line after it? Yech. But it does work exactly as expected if each line is nonempty.
Edit 8 minutes later: seems to work fine for me on anarki.
arc> (fromfile "x" (drain:readline))
("This is the first line." "After this line there is an empty line." "" "After this line there are two empty lines." "" "" "This is the last line.")
arc> (fromstring "\n\na\nc\n\nd" (drain:readline))
("" "" "a" "c" "" "d")
Yeah, I run arc3.1 for several reasons -- including that anarki doesn't work in Emacs's shell, and I haven't taken the time to figure out^1 why: my hypothesis is that simply removing rlwrap would fix it, but I so rarely use Arc these days I haven't dealt with it.
[1] Nor have I taken the time to respond to your emails from months ago. I'm sorry about that; it's related (among other things) to some general malaise I'm trying to deal with.
I've seen this before. What's happening, somehow, is that every time you write more than one line in a definition at the REPL in a Windows prompt, a capital R is being inserted at each newline. Arc compiles this to the Racket code _R, and when Racket executes this, it can't find the _R variable.
I seem to remember I used work around this by always pasting my multi-line definitions from a text editor rather than writing them directly at the REPL.
Oh, sorry. Now that I test it, I realize I remembered incorrectly.
The only time I get those spurious R characters is when I paste code into the REPL and then press enter manually. I don't get them when typing multi-line definitions directly at the REPL, and I don't get them if the code I'm pasting already has a line break at the end.
So the habit I've formed is to make sure the code I'm pasting already has a line break at the end.
I notice this issue also happens on Racket 5.3.3 -- I'm a few versions behind -- and it does not happen in the REPLs for Node.js or Clojure. It's some kind of bug in Racket. (Hmm... Racket's port.c has a bunch of spaghetti code for CRLF processing. Maybe the bug's in there somewhere.)
My money's on the first or last one working. (Obviously this assumes you _have_ a `C:\users` directory) I would similarly bet that you might need to capitalize the drive, even though Windows drive letters are case insensitive (https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...). So if it doesn't work with lowercase letters, try it as above.
Can you try it without the drain, just read the first line from the file?
Edit 10 minutes later: here's a few things I would try:
; a relative path with no slashes/backslashes
(read-all "mccf2.txt")
; inline read-all
(w/infile file "mccf2.txt" (drain (readline file)))
; try reading just the first line
(w/infile file "mccf2.txt" (readline file))
So it looks like the inlined version works, but wrapping it in a function doesn't? Very strange. Paste these lines one at a time into a fresh arc session and show me what you get in response to each line.
(w/infile file "Log.txt" (drain (readline file))) ; just to set a baseline
(def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (drain (do1 (readline f) (prn "CCC")))))
(foo "Log.txt")
(def foo (filename) (prn "AAA") (w/infile f filename (prn "BBB") (readline f)))
(foo "Log.txt")
I think rocketnia has figured it out. Does rocketnia's comment http://arclanguage.org/item?id=19137 make sense? Basically you shouldn't get an error if you type in this expression character by character, but you should if you paste it into an arc session without a trailing <enter>.
The Hacker News codebase is in Arc, and will be for the foreseeable future. All the core domain work is done in it, and we write Arc code every day. When it makes sense for performance or practical reasons we call into Racket, but not frequently enough that we've even bothered exposing nice syntax for it (like anarki's $).
I haven't been running the server in a while, but I have a few thoughts.
First, what version of anarki did you start with?
What were the edits you made? Does it work if you start the server without your changes?
What happens in the log before the errors?
What do you have to do to get the errors to occur? Is it upon server startup, or is it when you load a page in your browser, or try to register a user?
Back when I ran an arc service I noticed it ran out of memory every few days. So I'd run the server in a loop on my shell, immediately restarting it if it died.
I've updated the repository to make this easier. There's now a script called run-news to bring up the HN server.
$ git pull
Now you should be able to run your server in a loop like this:
$ while true; do ./run-news; sleep 5; done
Let me know if you run into trouble with this. I'll be around and more responsive for the next few days.
More notes, just for future reference:
1. run-news provides an interactive prompt, so you can make changes to the server without needing to restart it. Just remember to also modify news.arc otherwise your changes will be lost when the server dies next.
2. The sleep above is to help exit the server. If you quit the server as usual it'll just come up again. To bring it down, hit ctrl-c twice in succession.
3. I also fixed up the readme, which was abysmally out of date. Sorry about that.
error: Your local changes to the following files would be overwritten by merge:
lib/news.arc
Please, commit your changes or stash them before you can merge.
Aborting
Well, since you ask. :-) And since the judging is all done, I might as well update it. So. Currently things are broken up into "dyn-cont", which has the Arc interpreter, "arc-boot", which is the code the interpreter will run on startup, and "memory-system", which is where I'm prototyping the stuff the next version of "dyn-cont" will run on: fake assembly code, which is a preparation for writing real assembly code.
Waterhouse wrote an Arc interpreter on top of Arc with continuations, and first-class macros and first-class special forms. Scanning over his submission form (http://lispinsummerprojects.org/static/summer/250119.pdf), it also interestingly lets quasiquote be defined as a macro.
To explain further: I ask if you're specifically looking for a compiler because some people think that the only way to run any code is with a compiler, or that specific languages require one. Absent a specific thing in a spec ("an implementation of AwesomeLanguage requires compilation or it can't be called AwesomeLanguage"), languages can be interpreted or compiled.
So if you're interested in compilers, and want to see one for Arc, that's fine. But the default way of running Arc is not with a compiler. If you just want to run Arc, follow the instructions above.