(I think I prefer the other version of this, though. For one thing, it uses constant stack space.)
Speaking of which, it seems weird to me that you'd have 'if expand to a statement like this:
arc> (js '(if a b c d e))
if(a)b;else if(c)d;else e;
You can have it expand to an expression instead, bringing it closer to the Arc version's functionality:
if(isnt(nil,a))return b;if(isnt(nil,c))return d;return e;})()
On another note, it would be nifty if you could use Arc macros (or even functions, with an Arc hack to put enough metadata on them) in the s-expressions sent to the compiler. But since the namespace seen by the (js ...) Arc isn't nearly the same as the namespace seen by the raw Arc, it seems like the sort of undertaking that would completely change the structure of the code.
...but issues with nested strings and dot ssyntax keep this from being possible at the moment.
Well, the Scheme reader is going to parse (a (b c).d) as a three-element list the same way as it parses (a (b c) .d). I'm not even sure what kind of type we might expect '(b c).d to be. Nevertheless, I agree it ought to work. :-p
As far as nested strings go, could you elaborate on that?
"it would be nifty if you could use Arc macros (or even functions, with an Arc hack to put enough metadata on them) in the s-expressions sent to the compiler."
I had the same reaction.
"But since the namespace seen by the (js ...) Arc isn't nearly the same as the namespace seen by the raw Arc, it seems like the sort of undertaking that would completely change the structure of the code."
Perhaps I'm missing something. I imagine you could implement a macro, say jsdef, to store translation functions in a table and then replace (def js-fn..) with (jsdef fn..). js would then replace keywords in car position with functions before eval-ing the whole shebang. This way you wouldn't need to update js everytime you want to implement a new arc function in js. You'd also be able to avoid quoting when you don't need backquotes.
Hmm, perhaps this runs into a similar problem to my yrc (http://arclanguage.org/item?id=11880) -- since you're doing keyword replace, is there a scenario where the keyword won't show up until after the replace step? My mind is getting bent out of shape thinking about this.
Whoa, I'm now realizing just how especially intriguing this is to me; I've been getting into the thick of working on namespace organization for Blade, and this is really relevant for that. How might one go about having a language where programs may have access to significantly different core functionality depending on how they're compiled... but where it could be swapped out for a substitute implementation on a mismatched platform...
It isn't especially novel, I suppose, 'cause it still boils down to special-casing in the compiler, but at least it's limited to special-casing the JS-runtime parameter, which is part of the library itself.
Thank you for the feedback and for fixing 'join! ^_^
Glad you pointed this out, may save me some debugging time. :)
> As far as nested strings go, could you elaborate on that?
In the first Arc Challenge attempt I posted is the line,
(+ |\'you said: \'| foo.value)))))
...the latter has a close 1-to-1 correspondence of expressions with Arc while the former breaks up an expression into several statements. (Is this what you meant, or have I misunderstood?)
I'm mostly just concerned that you should be able to say things like (let x (if (< foo 2) 0 foo) (* x x)). If (if ...) translates to a statement, that won't work.
|\'you said: \'|
Oh, I see now.
Yeah, the string escaping shouldn't be that difficult. I suppose the trickiest part about string escaping is remembering to do it. ^_^