Arc Forumnew | comments | leaders | submitlogin
3 points by rocketnia 4985 days ago | link | parent

Right away, I have a couple of things that I'd sorta like to see implemented (if you don't mind). On the other hand, it might just be that you haven't gotten around to them yet.

1) Strings aren't escaped, which makes them pretty unhygienic (albeit technically livable).

  "'"
  ''';
  
  "\\'"
  '\'';
This could be handled just by being more careful and running the string through a filter function before printing it out as compiled JavaScript. Note that the function would probably be defined within the scope of the private 'nest-lev variable so that it could put in the right number of backslashes.

2) Your 'compose isn't a metafn (and neither are 'andf and 'complement, but 'compose is the main one).

  (do:a b)
  (function(){var g5870=arraylist(arguments);return (function(){return apply(a,g5870);})['call'](this);})(b);
  
  (do (a b))
  (function(){return a(b);})['call'](this);
  
  (a:do b)
  (function(){var g5871=arraylist(arguments);return a(apply(do,g5871));})(b);
  
  (a (do b))
  a((function(){return b;})['call'](this));
This could probably be handled by putting yet another 'if case in 'js1. You could call out to metafn expansion utilities (like arc.arc's 'setforms does) or just hardwire the metafns into the 'if branch (like arc.scm's 'ac does).

Anyway, good stuff. ^_^ I especially like how arc.js is generated by js.arc. XD



1 point by evanrmurphy 4984 days ago | link

Sorry about the lack of string escaping (that's awfully annoying! ^_^). It should be working now, at least for the common cases:

  "'"   ->  '\'';
  "\'"  ->  '\'';
Thanks for the input. I'm studying the metafn problem.

Edit: Actually backslash chars appear to escape incorrectly still. It's doing "\\'" -> '\\'' instead of "\\'" -> '\\\''. Working on it... Update: fixed.

-----

1 point by rocketnia 4984 days ago | link

Ack, there's something missing from that implementation: Nested string handling.

This is working well:

  "\\"
  '\\';
If you use 'quote to compile a string without escapes, you're fine:

  '"foo"
  '\'foo\'';
If you do the same thing where the only things to escape are quotes, you're fine, 'cause you call 'js-q, which uses 'nest-lev:

  '"'"
  '\'\\\'\'';
However, with other escaped things you're in trouble:

  '"\\"
  '\'\\\'';
I suggest putting 'js-charesc where 'js-q is now and having it use 'nest-lev directly. You might not even need 'js-q, since it could just be (js-charesc #\').

-----

1 point by evanrmurphy 4984 days ago | link

I'm not sure that's incorrect. Are you suggesting it should compile to this?

  '\'\\\\\'';
In Chrome's Javascript console, '\\'; and '\'\\\''; evaluate the same except for the extra pair of quotes.

-----

2 points by rocketnia 4984 days ago | link

Right. I'm going to use [] as makeshift quotes. The JavaScript ['\'\\\\\''] evaluates to ['\\'], which evaluates to [\]. The JavaScript ['\'\\\''] evaluates to ['\'], which evaluates to an error, 'cause it's an unterminated string.

-----

3 points by evanrmurphy 4984 days ago | link

OK. Now I'm going to use [] to illustrate how the Walls of Shame closed in on me as I read your last comment:

  [     :)     ]
    [   :|   ]
      [ :-o ]
        [:(]
You were right. ^_^

-----

1 point by evanrmurphy 4984 days ago | link

Could you help me to better understand the metafn issue? Those (do:a b) examples... what should they compile to? Does what you're talking about affect semantics, or just readability and performance?

-----

2 points by rocketnia 4984 days ago | link

When Arc compiles (a:b c), it compiles ((compose a b) c). When it compiles ((compose a b) c), it compiles (a (b c)). So in Arc, (do:a b) and (do (a b)) are basically equivalent, and so are (a:do b) and (a (do b)), where 'do is just an example macro. Since 'do is a macro, the equivalence does involve semantics; your transformation of (a:do b) calls a function named "do", when that function may not actually be defined.

Anyway, I'm just trying to make sure I inform you of stuff you may have overlooked. Once you know what I'm talking about regarding 'compose, it's up to you to decide whether you actually want to preserve an (a:b c)-(a (b c)) equivalence. ^_^ I am quite a fan of it, 'cause it saves some nontrivial edits (adding a closing parenthesis in a distant place and reindenting), but it's not sacred or anything.

-----

1 point by evanrmurphy 4984 days ago | link

Ah, I think I understand now. I had seen this comment from arc.arc:

  ; Composes in functional position are transformed away by ac.
And your examples show how 'compose gets transformed away, but I was having trouble visualizing a case where that wouldn't happen. Now it seems obvious to me: if you have (compose a b), rather than ((compose a b) c), then you can't transform compose away, because something is needed to make a and b act like one function.

-----