Re: scheme/dsssl question

Subject: Re: scheme/dsssl question
From: ht@xxxxxxxxxxxxxxx (Henry S. Thompson)
Date: 30 Dec 1997 11:17:36 +0000
Chris and Norm ask for eval:

It's not a bug that this is missing, it's a feature.  Scheme, and a
posteriori DSSSL, are lexically scoped.  Consider the following

(define (dblappl fn var) (fn (eval var) (eval var)))

(let ((foo 3)) (dblappl + 'foo))

There is no definition of eval as such which can exhibit coherent
behaviour in this case.   Some dialects of Scheme support access to
lexical binding tables, in which case eval can be defined as a
TWO-argument function, but this is implementation-dependent and tacky.

The normal strategy to get around this feature is to use thunks,
i.e. procedural closures of no arguments:

(define (dblappl fn thunk) (fn (thunk) (thunk)))

(let ((foo 3)) (dblappl + (lambda () foo)))

The thunk of necessity carries its lexical environment with it,
achieving the encapsulation you need.

Hope this helps

Henry S. Thompson, Human Communication Research Centre, University of Edinburgh
      2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
               Fax: (44) 131 650-4587, e-mail: ht@xxxxxxxxxxxxxxx  

 DSSSList info and archive:

Current Thread
  • scheme/dsssl question
    • Norman Walsh - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id NAA24625Mon, 29 Dec 1997 13:09:02 -0500 (EST)
      • Chris Maden - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id QAA25868Mon, 29 Dec 1997 16:19:19 -0500 (EST)
        • Henry S. Thompson - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id GAA05269Tue, 30 Dec 1997 06:18:32 -0500 (EST) <=
          • Chris Maden - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id KAA07849Tue, 30 Dec 1997 10:24:10 -0500 (EST)
      • <Possible follow-ups>
      • David Megginson - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id IAA06598Tue, 30 Dec 1997 08:54:20 -0500 (EST)