Arc Forumnew | comments | leaders | submit | xrchz's commentslogin
1 point by xrchz 5897 days ago | link | parent | on: Referential transparency

is it possible for a macro library to provide hygienic macros? I suppose you could port the "portable syntax case" implementation from scheme to arc... but I don't know how much help, if any, you'll need from the expander

-----

1 point by xrchz 5898 days ago | link | parent | on: Referential transparency

is it really true that 'set and 'if (and 'symeval...) are completely non-overrideable in arc? is that a convention or something enforced?

-----

1 point by almkglor 5896 days ago | link

It's enforced. For example, you can assign a macro to 'if, but it'll never be used: 'eval will always interpret 'if in its sense, and will never look at your macro.

-----

1 point by xrchz 5898 days ago | link | parent | on: Referential transparency

I think you're right.

-----

1 point by xrchz 5898 days ago | link | parent | on: Referential transparency

I think 'symeval is a possible solution to this problem, and I'm glad somebody thought of it before me. But the question is why you wouldn't use 'symeval on every free variable in your macro template, just in case some newbie decides to let bind one of your "global but internal" names. If you did use 'symeval everywhere (or automatically) you would have something closer (but still a poor approximation) to scheme's hygienic macro system. I think the automatic solution to be found there is more interesting.

-----

2 points by rincewind 5897 days ago | link

I tried that. It doesn't work without knowing which variables are local and arc currently has no way of finding out, what the binding forms are, because all macros are unhygienic.

example:

  (let list '(foo bar) (do (prn list)))
    |    |   unbound    |    |    |
   mac   |             mac   | function 
      function            function

  =>(let (global list) '(foo bar) (do ((global prn) (global list))))
We know that let binds its first argument and aif binds self, but since macros are turing-complete, this cannot be automatically inferred.

-----

1 point by almkglor 5896 days ago | link

expand any macros in sub-expressions, then look at them. That's the advantage of avoiding "first-class macros", whatever their imagined advantages might be. ^^

-----

2 points by xrchz 5898 days ago | link | parent | on: Referential transparency

I'm really sorry my parentheses were mismatching. Here is a correct example.

  (define pusher cons)
  (define-syntax push
    (syntax-rules ()
      ((_ e ls) (pusher e ls))))
  (let ((pusher (lambda (x ls) (append ls (list x)))))
    (display (push 'a '(b c d))) (newline)
    (display (pusher 'd '(a b c))) (newline))

-----

1 point by xrchz 5898 days ago | link | parent | on: Return value of pr and prn

do pr or prn create a string? it might be less expensive to return that string if it is created

-----