initializing arc.. (may take a minute)
serving from C:\Users\user\anarki\apps\news
starting app news
load items:
ranking stories.
ready to serve port 8080
To quit:
arc> (quit)
(or press ctrl and 'd' at once)
For help on say 'string':
arc> (help string)
For a list of differences with arc 3.2:
arc> (incompatibilities)
To run all automatic tests:
$ ./arc.sh
arc> (load "tests.arc")
If you have questions or get stuck, come to http://arclanguage.org/forum.
Arc 3.2 documentation: https://arclanguage.github.io/ref.
arc>
What OS are you on? If you're on Linux or MacOS, you can use `pushd` and `popd`.
On bash, I have some aliases set up. they will move you to the right directory, run arc or anarki, then when it exits, move you back to the original folder.
alias arc="pushd ~/programs/arc/arc3.2/; rlwrap racket -f as.scm; popd"
alias anarki="pushd ~/programs/arc/anarki/; ./arc.sh; popd"
I normally use fish shell, but functions there are simple enough to make based on the bash aliases.
Getting back after arc is not the problem; even if I didn't have cd history set up a simple `cd -` would handle that.
Simple problem: I have a file containing a program written in Arc. I want to run it from the shell. How do I do that? I can fire up arc and `(load)` the file, but then the file needs to be in the arc2.3 dir or else I have to load it by absolute path, even if I was just in the same directory it's in.
For now I've just switched to using Anarki; I can run its `arc.sh` start script from anywhere in the filesystem and feed it a locally-relative pathname and it will run. Although it does seem to take quite a lot longer to start up than arc.
Ah, interesting. That's a good point that it's Unix/MacOS-specific. My hope was that it should make Arc interpret paths the same way the default shell on the system does. On Linux, ~/ is the home directory of the current user, so it makes sense that Anarki would work that way on Linux. But Windows doesn't work that way, so it makes sense Anarki wouldn't either.
I don't know of any similar path tricks on Windows, But, if this change hasn't broken anything on Windows, I would be satisfied with that. Can you verify it still works to open an existing file? Are there any other special ways to refer to files or directories on Windows?
"On Linux, ~/ is the home directory of the current user, so it makes sense that Anarki would work that way on Linux. But Windows doesn't work that way, so it makes sense Anarki wouldn't either."
Yeah, I don't know much about what a Windows user would expect ~ to do. I would say `expand-user-path` leaving ~ alone on Windows is probably as good a behavior as any. It coincides with Command Prompt, where ~ just refers to a file or folder named "~". In PowerShell, ~ seems to be expanded to C:\Users\[username]\ somehow, so there's potentially an alternative design there.
---
"I don't know of any similar path tricks on Windows, But, if this change hasn't broken anything on Windows, I would be satisfied with that. Can you verify it still works to open an existing file?"
On Windows 10 64-bit with Racket 8.1, I've at least run the tests.arc unit tests, the unit-test.arc/tests.arc unit tests, and build-web-help.arc, and they seem to work.
---
"Are there any other special ways to refer to files or directories on Windows?"
I hardly know where to begin learning about and testing those features, and the documentation makes it look like Racket has explored hat rabbit hole pretty thoroughly already, so I'm inclined to suggest we just piggyback on Racket's work here.
I just ran the unit-test.arc unit tests on both Arc3.1 and Anarki master, and they ran in virtually the same time. Arc3.1 took 49 seconds, and Anarki took 51 seconds.
Certainly would be worth trying to optimize. I'm sure there are a lot of improvements to be had, both in unit-test.arc and Anarki.
Hrm. The tests definitely were faster. They weren't as fast as I'd wanted, but certainly not this slow. It just took three minutes for me to load that file. It's slightly complicated by that file loading _and_ running the tests, but again, it wasn't that slow before. For reference, I'm on Ubuntu running Racket 8.1.
One thing that definitely has changed is that now, Anarki requires Racket >=7.7. I just had to update my Racket from 7.2, which worked the last time I ran Anarki, Perhaps this is related?
At one point, years ago, I relied on every lambda returning a newly allocated object. I think I brought it up as a bug in Rainbow that the [] expressions in my Arc code were generating the same lambda-lifted result instead of creating unique objects each time.
But I think this was never something I could rely on in the original, Racket-based Arc either. The Racket docs don't specify whether a lambda expression returns a new object or reuses an existing one, and in fact they explicitly allow for the possibility of reusing one:
"Similarly, evaluation of a lambda form typically generates a new procedure object, but it may re-use a procedure object previously generated by the same source lambda form."
That sentence has been in the reference since the earliest versions I can find online:
I'm not sure if the bug you're referring to had to do with making the same mistake I was making back then, or if you're talking about making the opposite assumption (expecting two procedures to be equal), but it's probably best not to expect stability either way.
I was doing a deep-`iso` comparison I called `same`, because in Arc, hash tables are not the same. In Arc3.1:
arc> (iso (obj) (obj))
nil
arc> (iso (obj 1 2) (obj 1 2))
nil
So I made a function that iterated over the key/value pairs and compared them. In some unit tests, I used that on a hash table that contained functions. Yesterday, I refactored the unit tests to instead make sure the keys were right.
Interestingly, it seems that Anarki can compare hash tables:
arc> (iso (obj) (obj))
't
arc> (iso (obj 1 2) (obj 1 2))
't
Anyway, this should fix the unit test tests in the Anarki repo.
The "racket -f as.scm" is supposed to be done in your terminal, you're right! DrRacket is a different thing that is very cool, but not the tool to run Arc with.
When you type it in your terminal, what does it say? If it says something like "racket not found", try downloading the racket installer from https://download.racket-lang.org/.
If it installs correctly, you should be able to type "racket" (without quotes) in your terminal, and get a message "Welcome to Racket 8.0". To quit, press Ctrl-D, or type (exit) with the parentheses, then hit enter.
If that works, you should be able to run "racket -f as.scm".
Thank you so much, zck :)
I've used a combination of your helpful suggestions, stack overflow, and cd command to get to the right folder, and now it works. I got the arc command prompt (arc>) in my terminal now. I will take my time to explore the tutorial on Arc.
I feel good that this community is really helpful. Thanks everyone!
Super interesting! I like how you can zoom into the system, almost like using a microscope to see how code works.
One thing that isn't quite clear from your examples here (and maybe that wasn't the point, but I am wondering): why have a different stack when a function is called? Your examples would work fine if they used the same stack. That is, if functions used the same stack, `1+` could be defined as `1 +`.
Perhaps it would be more clear if an example used two variables, or used the same variable twice.
Is it that you're trying to reduce stack juggling? That's hard to understand from simple examples (that you need to have to grok the syntax). Maybe compare something like finding the hypotenuse of a right triangle given the two other sides. Without naming arguments, you'd have to do something like:
hypot = dup * swap dup * + sqrt
But with named arguments:
hypot x y = x x * y y * + sqrt
That seems a little easier to read, but even the original isn't so complicated. Is there an example that makes it more obvious why it's better? Even your `square` example is more tokens than with stack juggling (without arguments, `square = dup *` is just four tokens, compared to six with named arguments). I'd say the with-arguments one is easier to read, but I've far less familiar with stack-based postfix programming.
Yeah, some other polynomial might be a better example. The Pythagorean formula has a clean separation when it comes to which args each term uses. How about the roots of a quadratic equation when you start out with a, b and c on the stack?
Yes, that is definitely simpler, although the formula is more esoteric. At least, for me, it triggers the "I was taught this in school and haven't used it since" filter.
You're right that in general any such example can be refactored to reduce stack operations. That's even a fun game for many Forth programmers to play. (We lispers have our own equivalents.) But it usually makes the code less comprehensible, in my experience.