Side-Effect Free Environment (Failed)
Friedrich Delgado Friedrichs <[email protected]> Sat, 8 Sep 2007 12:39:19 +0200
| Newsgroups | gmane.comp.java.sisc.user |
|---|---|
| Message-ID | <[email protected]> |
Hi!
I've tried to set up a side-effect free environment with SISC, and
failed, for several reasons.
When the current macro expander (psyntax 6.9) is exchanged for André
van Tonder's expander, I'd ask you to consider using its default
behaviour to expand to LAMBDA and SET! instead of using LETREC as a
primitive, as it is currently the case, for reasons detailed below:
First of all, I'm running user-specified code in an environment
generated with make-child-environment. By this I can successfully
protect bindings in the parent environment from modifications by
user-defined code. However there's no way I can prevent the user's
code from changing cells.
I attempted to create a protected subset of (scheme-report-environment
5) with the following procedure:
(define (pure-r5rs-subset)
(let ((env (scheme-report-environment 5))
(disallowed-syntax '(set!)))
(strict-r5rs-compliance #t)
(for-each (lambda (proc)
(eval `(define ,proc
(lambda args
(,error "forbidden procedure: ~a" ,proc)))
env))
unpure-procedures)
(for-each (lambda (sym) (disallow-syntax sym env))
disallowed-syntax)
(eval ($sc-put-cte-redefinition) env)
(make-child-environment env)))
Unpure procedures being the following list:
(define unpure-procedures
'(set-cdr!
scheme-report-environment
interaction-environment
with-output-to-file
vector-fill!
string-set!
open-output-file
set-car!
close-output-port
call-with-output-file
write-char
vector-set!
close-input-port))
In order to prevent DEFINE from acting like set, I redefine
$SC-PUT-CTE to only allow one definition. However now the following
problem arises:
LETREC in combination with call-with-current-continuation acts like
SET!, see:
http://swiss.csail.mit.edu/ftpdir/scheme-mail/HTML/rrrs-1991/msg00001.html
http://groups.google.de/group/comp.lang.scheme/msg/bc27beffba1bfdb9
I can of course try to define letrec as a macro, using the fixes
discussed by Matthias Felleisen, Bruce Duba and Marc Feeley, which I
successfully (!) did.
However internal DEFINEs in a local scope will still be expanded to
#%LETREC, an internal syntax identifier of psyntax, which I can do
absolutely nothing about. #%LETREC is not even a symbol, so I cannot
shadow it but it can still be used in scheme code just as if it was a
normal identifier. (Same as #%DEFINE, #%LAMBDA and #%SET! etc.) In
effect it is a protected keyword, which is something I didn't believe
to exist in any scheme implementation.
So if you rewrite Alan Bawden's original attack to use #%LETREC, it
will still work even if LETREC has been shadowed with a new macro.
Also Al Petrofsky's attacks will work, since internal DEFINEs are
directly expanded to #%LETREC, with the old behaviour.
And of course, attempting to re-define DEFINE itself will cause
modules to break and also doesn't help against the user who finds out
about #%DEFINE.
I'm hoping that dropping LETREC as a primitive together with psyntax
will allow me to redefine LETREC in a way that ensures that the right
side of a temporary assignment only returns once.
However I can't say which other problems may or may not arise with
André van Tonder's expander, since I only had a very superficial look
at its documentation so far.
Other problems I have with the current version of psyntax are
detailled in
http://sourceforge.net/tracker/index.php?func=detail&aid=1769860&group_id=23735&atid=379534
[ 1769860 ] Unquoted parameter objects in eval get applied twice
and
http://sourceforge.net/tracker/index.php?func=detail&aid=1754254&group_id=23735&atid=379534
[ 1754254 ] require-library breaks in environments
Kind regards
Friedel
--
Friedrich Delgado Friedrichs <[email protected]>
Laziness led to the invention of the most useful tools.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Sisc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sisc-users
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iEYEARECAAYFAkbie9cACgkQCTmCEtF2zEBtdQCeINh/GuYVDS6EpZedMLZRJcJP NMAAoJvu8naEGEQB6E8XuG8os5jsDynH =HFJL -----END PGP SIGNATURE-----