c) Not that it'll really save anything when it comes to the overall computational complexity, but this version of list length comparison will only traverse the lists up to the end of the shorter one:
(def longer-list (a b)
(if a
(if b
(longer-list cdr.a cdr.b)
t)
nil))
d) Where you say "(if empty.xs ys <else>)", you can probably squeeze out more performance with "(if xs <else> ys)". You can actually use "(iflet (x) xs <else> ys)" here too, but I don't know what that'll do to the performance.
e) There's no need to call 'testify.
After incorporating a bunch of this feedback--I didn't pit '< against '> --the code might look like this:
Inspired by http://arclanguage.org/item?id=14938, I've taken a stab at porting Rainbow from Java to JavaScript. Well, maybe it's not so much a matter of inspiration as it is "Hey, I know Java, I know JavaScript, I know Arc, and I use Rainbow. Do I really expect anyone but me to do this?" :-p
At this point, the basic evaluation model is really buggy, mostly thanks to tons of trivial typos. Nevertheless, there's already a REPL where it's possible to accomplish a few basic calculations: http://rocketnia.github.com/rainbow-js/test/
Be careful if you're on a very stringent data regimen, as the REPL page loads the unminified rainbow.js, which is over half a megabyte in size. :-p I'd minify it, but the last time I tried, the minified version was even more broken. (I'm not doing anything special with property name manipulation--I'm actually writing this with the Closure Compiler in mind, just in case--so I think I must have broken the minifier.)
The REPL can't accomplish anything as ambitious as arc.arc... and at this point it can't even accomplish anything as ambitious as 'def! If you're having trouble at the REPL and want to see some expressions that actually work, take a look at rainbow.test.js--which currently has no real tests, just pastes from the REPL.
For further information, take a look at the README. ^_^
Oh, I should also mention: I've mostly tested this in Chrome. I just tried Firefox, and it mostly accepts the same code, but when there's an error, there seems to be something troublesome about the stack traces. Even an unbound identifier error disrupts the REPL loop and makes it impossible to provide more input.
Opera and IE 8 would be next on my checklist, but at the moment Rainbow.js supports zero platforms, so I might just keep testing on Chrome for a while. :-p
There's a catch: My reader code is in continuation-passing style, and if the input's too long, it goes into a stack overflow.
Fortunately, the reason it's in CPS is so that it can process the input asynchronously. As long as it's actually working asynchronously, its continuation callbacks occur on fresh event stacks rather than piling up. I could go into more details, but what's important is that for now, submitting the input in smaller pieces is an effective, if ugly, workaround:
I suspect you're entering that JavaScript code at the Arc REPL. ^^; I just pasted that JavaScript here as an excerpt of the full(er) instructions on the REPL page:
"Actually, if you you paste from Java Rainbow's arc.arc source yourself, you'll probably find that Rainbow.js encounters a stack overflow error. At this point it's necessary to enter it in more bite-size pieces. Right now you can accomplish this by pasting all of arc.arc into the input box, then entering the following code into a JavaScript console (not the Arc console!) to have it entered one line at a time:
[the JS code I pasted above]"
In Chrome, the JavaScript console is available under "(wrench icon) > Tools > JavaScript console." On Firefox, I tested it using Firebug's console tab, but I think the Error Console might work too.
Also, pasting the JavaScript snippet all at once should be fine. The point is to enter the Arc code in bite-size pieces, and the JavaScript snippet just automates that process.
I'm considering making this workaround a feature of the REPL interface, as a checkbox or something, but what I'd rather do is fix the issue altogether.
Done! Now the reader only uses a number of JavaScript stack frames proportional to the amount of nesting of the program, rather than the number of characters. Feel free to just paste all of arc.arc into the REPL and hit enter. ^_^
I've also tested the REPL on more browsers. The only one that really had a problem was IE 8, and that was because of the code of the REPL interface itself rather than the Rainbow.js runtime. It should work in IE 8 now... except that the performance is terrible there. XD
Any ideas about where this project should go next?
Rainbow.js is compiling with the Closure Compiler's advanced mode now! The REPL page--which still doesn't load arc.arc--is now down to 146 KB (HTML and JavaScript), rather than over 500.
Furthermore, on most recent browsers, the loading speed seems competitive with, or even better than, the loading speed of Java Rainbow. It might not be a fair comparison, since the contents being loaded are coming through a different kind of input, but I'm still pretty excited. ^_^
I usually don't care about currying, but I like this. XD There are places I might miss the ability to use _ from inside other parentheses, like [... (foo _ bar) ...], but it would be interesting to explore the advantages.
Anarki[1] already lets us change the square bracket behavior by redefining the 'make-br-fn macro. In ar[2], it's the 'square-bracket macro.
Here's my take on your idea. When the operator is actually a macro, I just treat it the old way rather than unsuccessfully calling 'apply on it:
Here's a half-demonstration thanks to http://tryarc.org/. It doesn't provide 'make-br-fn or 'square-bracket, so I haven't bothered to actually use the square brakcets:
As you can see, my approach has a little bit of room for improvement. The 'fn special form isn't actually a macro, so this treats it like a function. :-p (Also, I don't do anything about ssyntax, like [a:b c d] or [a&b c].)
I think newlines you're entering into your console are \r\n, and you're using a version of 'readline that only supports \n newlines (and treats \r as a normal character). Andrew Wilcox has made a fixed version: http://awwx.ws/readline1
Furthermore, you're reading from stdin, the same stream the commands are read from, so what you're reading actually starts right after the ')' character and includes the same newline you used to enter the command. I think someone here might have made a fix for this too (probably Pauan or aw), but you might be able to work around it like this:
arc> (do (readline) (...now your *actual* stdin-reading code...))
The first (readline) should hopefully get rid of whatever was left over from the input after reading the command.
Hi
readline1 dose not function as read-line in common lisp.
I type (read-line) and and arc is waiting to enter something so I type my string including spaces like:
Hi there.
output is:
"Hi there"
NIL
Thanks
ly
Right, I expect the version I linked you to doesn't behave exactly like Common Lisp's readline. I just hope it can help. :)
I don't fully understand your example. Did you try something like (do (readline) (readline)), like I was talking about? I'm guessing that since Arc's REPL takes commands and other input from the same stream, it's already different from the REPL you're used to, regardless of how readline works.
You can insert links like *this*... http://arclanguage.org/formatdoc
...separate paragraphs like *this*...
...and indent code like *this*:
You can insert links like *this*... http://arclanguage.org/formatdoc
...separate paragraphs like *this*...
...and indent code like *this*:
"I guess I should have used strings in all of those cases, but I was taking advantage of the fact that I could actually bind values to the symbols to store some metadata."
If you don't mind, how does/did it seem easier to bind values to symbols than to bind them to strings?
I'm not shader, but I'm guessing that it's because... you can't.... bind values to strings...?
I mean, yeah, you could have a table where the keys are strings, and treat that as the metadata, but uuugh it's clunky and I've found myself disliking the whole "global table to hold data" thing more and more, recently.
Then again, I don't know how their compiler works, so I might be completely off-base here...
I don't like len!sym being 1 either. I think ppr.arc is the thing that should be fixed, perhaps by having it use its own spinoff of 'len. But I didn't try to fix that; I just did the minimal change needed to get len.nil to work properly again.
My stance is that they're intuitively separate things. If you take the length of a vector of length 2, you get 2. If you take the length of a linked list node, that's a different story. Still, if a linked list node is implemented as a wrapper around a vector, that's fine.
2) Were I to have accepted the brilliance of this use case, I'd only have been more interested in why 'pr didn't have the same behavior (which was my main gripe to begin with):
arc> (= speed 2)
2
arc> (prn "You are going " (if (> speed 100) "very ") "fast")
You are going nilfast
"You are going "
3) It was actually something I had already thought of and cast aside for the above reasons. (So it didn't even qualify as something "I'm not thinking of.") If aw was grasping for straws like I was, there probably wasn't much more point in talking about it.
4) It had upvotes too--at least one upvote at the time I first read it. Apparently, what I thought was common sense would be outnumbered.
5) I hadn't programmed in Arc that much yet. Maybe the upvoter(s) saw something there I didn't. At any rate, I'd probably be able to discuss the pros and cons better once I'd used Arc for a while.
6) I did say "I can't think of a single time," and this was a single example. I kinda decided to eat my words on account of that. :-p
Turns out (string:accum ...) is the use case I found that convinced me. The key point was that 'string wasn't consistent for symbols because it was too busy being consistent for lists.