Arc Forumnew | comments | leaders | submitlogin
3 points by almkglor 6109 days ago | link | parent

Okay, I'm reviewing ac.scm a bit.

Basically the only thing that can't be redefined on Anarki are:

  quote
  quasiquote
  if
  compile
  fn
  set
  lset
This also means that everything else can be redefined - including +, -, * , /, is, isnt, car, cdr, scar, scdr, sref... Sure, it's not, exactly, "recommended", but exploratory, exploratory...

For instance, scanners redefine car and cdr, and settable-fn's redefine sref.

I propose instead that the compiler detect if the program actually redefines + - * / is isnt etc. If they aren't (which will be 99.9999% of the time) then the compiler can treat them as builtins. Otherwise, the compiler must treat them as globals and insert their definitions into the code (the same way ccc is inserted); then when the program redefines it (probably using (let old car (= car (fn (c) (prn "foo!") (old c)))))), the "builtin" is stored as a function in a global, which the program can refer to and replace.



3 points by sacado 6109 days ago | link

Yep. For the moment, I'm treating them as builtins. They will have to be implemented the way you mention it, that's for sure. I guess the easiest way would be to declare them both ways : as primitives (i.e., + translated to %+ when it is met) and as built-in functions, the way ccc is defined.

-----

3 points by almkglor 6109 days ago | link

Hmm, that's true, you do need to handle stuff like:

  (map + (list 1 2 3) (list 9 8 7))
Haruu, compiling dynamic languages is hard... ^^

For that matter, it shouldn't be so difficult - basically if the compiler ever sees (set + ...) anywhere (where + is a global, at least), it disables the use of %+.

Possibly, we could add another step in the transformation process (which is why I suggested the structure in http://arclanguage.com/item?id=5598 to allow easy insertion/deletion of steps).

Basically the new step just traverses the structure (without mutating it) and creates a list of built-ins to disable.

Edit: or better - it traverses the structure and replaces + with %+, until it reaches a top-level node which has (set + ...), so that code which doesn't use the redefined + will still refer to the builtin %+.

-----