Arc Forumnew | comments | leaders | submitlogin
4 points by rocketnia 5200 days ago | link | parent

Not to rain on your parade, but I think that utility is buggy, even as small as it is. ^_^ It's easily fixed:

  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> (mac inline (x) `',(eval x))
  #(tagged mac #<procedure: inline>)
  arc> (is is inline.is)
  t
  arc> (is or inline.or)
  nil
  arc> (is setter inline.setter)
  nil
  arc> (mac thunk body `(fn () ,@body))
  #(tagged mac #<procedure: thunk>)
  arc> (mac inline (x) (zap eval x) `(',thunk.x))
  *** redefining inline
  #(tagged mac #<procedure: inline>)
  arc> (is is inline.is)
  t
  arc> (is or inline.or)
  t
  arc> (is setter inline.setter)
  t
  arc>
What I think happens is that every element of an expression--even if it's quoted--is deeply copied by the time the expression is executed. This means the behavior of code is less surprising when it uses (',thunk.x) in place of ',x. I've brought this up before.

Of course, patching the Arc compiler is probably the better answer to this. Here's a patch for http://github.com/awwx/ar you can feel free to steal:

   (extend ac (s env)
     ((g caris) s 'quote)
  -  ((g list) 'quote (make-tunnel (arc-cadr s))))
  +  (let ((s (arc-cadr s)))
  +    ((g list) ((g list) 'quote (lambda () s)))))
I've actually tested this patch, but I may have overlooked some toarc or fromarc business.

(By the way, ar is pretty awesome. It's so simple. XD )

I'd write a patch for Arc 3.1 too (and I'd probably commit it to Anarki), but since 'quasiquote isn't compiled to 'quote there, the patch would be quite a bit more complicated.



1 point by aw 5200 days ago | link

hmm! I'm going to have to look into why inline isn't working for macros in ar. In ar macros are implemented by vectors (same as Arc 3.1), and vectors aren't deep copied... so I'm wondering how the code is managing to create a new vector that would then not be eqv? to the original macro vector...?

By the way, ar is pretty awesome. It's so simple.

Why thank you :) The simplicity has been a lot of work, but was quite necessary... at least for me. Someone smarter than I am, or someone who understands the Arc 3.1 compiler better than I do, likely could have gone ahead and just implemented Arc lists with Racket mpairs directly in the Arc 3.1 compiler, but I got lost when I tried it.

-----

1 point by aw 5200 days ago | link

ah, I think it's Racket's eval which is copying the vector:

  Welcome to Racket v5.0.2.
  > (define a #(1 2 3))
  > (define b (eval (list 'quote a)))
  > a
  '#(1 2 3)
  > b
  '#(1 2 3)
  > (eq? a b)
  #f

-----

1 point by evanrmurphy 5199 days ago | link

> In ar macros are implemented by vectors (same as Arc 3.1)

I did not know this. Are functions implemented by vectors too, or does it have to do with macros being annotated functions (i.e. that annotate is implemented as some sort of vector-wrapper)?

-----

2 points by rocketnia 5199 days ago | link

annotate is implemented as some sort of vector-wrapper

That's the truth. The result of (annotate 'foo 'bar) is #(tagged foo bar), where #(...) is the external representation of a Racket vector. Note that 'tagged here is just a symbol like 'foo or 'bar.

I wonder if Arc could instead use a custom Racket type so that we don't have quirky abstraction leaks when using Racket vectors. I never actually find myself wanting to use vectors, and if I did, I'd just [annotate 'vector _] them, but still. :-p

Are functions implemented by vectors too

They're implemented as Racket functions.

-----

1 point by aw 5199 days ago | link

I wonder if Arc could instead use a custom Racket type

Very easily -- it's just a matter of changing a couple lines of code to use a struct instead of a vector. I'll add it to my todo list if you'd like.

-----

2 points by shader 5199 days ago | link

I did an experiment where annotate produced a list, of the form ('tagged x type1 type2 ...), making the tagged lists transparent objects to the arc system. In doing so, I extended the type system to include the original type of the object in the list and support more than one type, allowing a simple form of inheritance through coercion. I.e. if you annotated a list as type 'foo, until you defined an actual coercion method for converting 'foo to a cons it would be treated as a normal list, and you wouldn't lose any ability to work with it using existing operations.

The thing that annoys me the most about arc's current type system is that if you tag something, it becomes an unusable vector according to all existing arc code, so you need to re-implement or extend any function that you actually want to support the new type.

-----

2 points by akkartik 5199 days ago | link

Hmm, it sounds like just making it a tagged list instead of a tagged vector wouldn't address your criticism. Any other suggestions?

-----

1 point by evanrmurphy 5199 days ago | link

I think he made the additional change of delegating all functional calls to the "parent" type when they didn't explicitly handle the type at hand. This makes a lot of sense. If you have a list that's tagged 'foo, it should behave exactly like a normal list does until you've specified some diverging behavior for type 'foo.

Do you still have the code for your experiment, shader?

-----

1 point by shader 5196 days ago | link

I do, but it was built on the old anarki master, so I'm going to have to spend a little bit of time updating it.

-----

1 point by akkartik 5199 days ago | link

Ah, I didn't properly read that first para somehow!

-----

1 point by rocketnia 5199 days ago | link

I'll add it to my todo list if you'd like.

Like I said, it hardly matters to me 'cause of the [annotate 'vector _] workaround.

More worthwhile would be having custom 'iso hashing and stuff like that. ^_^ That's something that would probably benefit from a dedicated Racket type for tagged values, but that's not necessarily the only way to go about it. I'm still trying to figure out how to go about it for Penknife....

-----

1 point by evanrmurphy 5199 days ago | link

Ah, thanks for explaining that. It's very clear now.

-----

1 point by aw 5199 days ago | link

Wow, thanks! I've incorporated your patch into ar, and updated my post ^_^

-----