Eduardo,

On Oct 16, 2011, at 01:02 , Eduardo Cavazos wrote:

> "boot-eval.c" has an implementation of set-car however "eval.l" doesn't. Have 
> mutable pairs been deprecated? :-)

eval.l contains little more than the minimum needed to run boot.l and emit.l.  
boot-eval.c is a superset of eval.l because a few things that were used for 
other experiments, but not needed to run boot.l and emit.l, were never removed.

> I added this implementation of set-car to my "eval.l" and it seems to work:
> 
> (define-function subr_set_car (args env)
>  (arity2 "set-car" args)
>  (let ((arg (get_head args)))
>    (if (is <pair> arg)
>        (set_head arg
>                  (get_head (get_tail args)))
>      ())))

Here's what's in my longer version of boot.l.  These are more permissive about 
their arguments (in the spirit of '(cdr (assq ...))') but sightly slower 
because of the additional overhead of the calls to k_c*r and the tests they 
perform for <pair>ness.

(define-function subr_set_car (args ctx)
  (let ((arg (k_car args)))
    (and (is <pair> arg)
         (put <pair> head arg (k_cadr args)))))

(define-function subr_set_cdr (args ctx)
  (let ((arg (k_car args)))
    (and (is <pair> arg)
         (put <pair> tail arg (k_cadr args)))))

> When I used "(pair? arg)" instead of "(is <pair> arg)" the build would fail.

'pair?' is an evaluator-only function that works on objects, whereas '(is 
<type> obj)' is a macro that expands to low-level code that takes apart a 
pointer and/or the structure that it references to figure out if the 
representation of an object makes it smell like a <type>.  You can use the 
former only in interpreted code and the latter only in compiled code.

Regards,
Ian


_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to