[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: metacircular evaluater with local environments
From: |
Andy Wingo |
Subject: |
Re: metacircular evaluater with local environments |
Date: |
Thu, 17 Feb 2011 18:56:11 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Hi Klaus,
On Thu 17 Feb 2011 12:08, Klaus Schilling <address@hidden> writes:
> How does one implement a metacircular evaluator in Guile 2 with local
> environments and local-eval? Those got trashed.
A fair question, though perhaps it could have been asked more politely.
Basically, you expand a Scheme expression, then potentially do some
analysis on the expansion, then interpret the resulting expression
tree. You have to choose a representation for environments; there is a
lot of code out there to work from, ranging from SICP to PAIP to Guile's
own (ice-9 eval).
I was feeling a bit contrarian this afternoon, so I did just that.
Attached is (ice-9 local-eval), which exports the procedure
`local-eval', the procedure-with-setter `fexpr?', and the fexpr
`the-environment'.
(use-modules (ice-9 local-eval))
(define env (local-eval '(let ((x 10)) (the-environment))))
(local-eval '(* x 20) env)
=> 200
Have fun,
Andy
local-eval.scm
Description: ice-9 local-eval
--
http://wingolog.org/