Arc Forumnew | comments | leaders | submitlogin
3 points by fallintothis 5292 days ago | link | parent

1) I'm not sure what your exact objection is, but it's easy to fix (the CLHS even gives a macro definition for defvar: http://www.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Bod...).

  (mac defvar (var val)
    `(unless (bound ',var)
       (= ,var ,val)))
This can be extended to several variables & values.

  (mac defvar vars/vals
    `(do ,@(map (fn ((var val))
                  `(unless (bound ',var)
                     (= ,var ,val)))
                (pair vars/vals))))
2) Agreed.

3) I don't know what you mean. Could you explain more?



3 points by ylando 5292 days ago | link

   I will explain:
   1) I think we should separate the definition and the
   assignment some thing like:
   use strict; 
   my x; # declare var for the first time
   x=3;  # assign a value to a var
   in perl.
   3) Suppose we want to make an object oriented
   function; we can write a function
   (def myfunc (this arg1 arg2) ...)
   If we had alias we could write a macro that expand to
   (w/alias (var this.var var2 this.var2)
   (def myfunc (this arg1 arg2) ...))

-----

3 points by rocketnia 5292 days ago | link

1) I think you're missing the whole point of 'let.

  arc> (= x 5)
  5
  arc>
    (let x 3         ; "declare" a var with value 3
      (= x (* x x))
      (+ x 2))
  11
  arc> x
  5
If you want to separate the declaration from the initial value... why? What happens if you use the variable in between those two times?

2) For what it's worth, my Lathe library provides a certain sort of namespaces, and I've been using those pretty happily. (http://arclanguage.org/item?id=11610) But of course I'd be happy with them, 'cause I'm their author. :-p

3) Why would you need a macro to expand to...

  (w/alias (var this.var var2 this.var2)
    (def myfunc (this arg1 arg2)
      ...))
...when it could already expand to something like this?

  (def myfunc (this arg1 arg2)
    (with (var this!var var2 this!var2)
      ...))
That said, I think 'symbol-macro-let would be nifty. I wonder if it could be even more useful to have some way to build a lambda whose free variables were treated in a custom way (as opposed to just being globals). Either one of these could be a basis for scoped importing of namespaces.

-----

4 points by zck 5292 days ago | link

So w/alias is like let, but any changes are shadowed back to where the alias came from?

So

  (let var (cons 1 2)
    (w/alias head car.var
      (= head 2))
    var)
would output

  (2 . 2)
This seems related to macros and backquoting, although I can't quite explain it.

-----