Subject: RE: SOLUTION FOR : How can I add a new children in a node?? From: "Frank A. Christoph" <christo@xxxxxxxxxxxxxxxxxx> Date: Tue, 5 Oct 1999 15:54:14 +0900 |
> Quoting Frank A. Christoph <christo@xxxxxxxxxxxxxxxxxx>: > > What Brandon wrote about "storing the definition environment" > is true about > > lambda-calculus, but Scheme and DSSSL are not quite lambda-calculus. > > > Actually, what I wrote came from the spec (8.3.1.4): > A lambda expression evaluates to a procedure. The environment > in effect when the lambda expression was evaluated is > remembered as part of the procedure. When the procedure is > later called with some actual arguments, the environment in > which the lambda expression was evaluated shall be extended by > binding the variables in the formal argument list to the > corresponding actual argument values, and the body of the > lambda expression shall be evaluated in the extended > environment. The result of the body shall be returned as the > result of the procedure call. > Am I missing something? Maybe you are, but so was I---sorry. I was a little confused about this too. I thought this had something to do with a distinction between top-level and local definitions in Scheme, but it doesn't. There is no such thing as a REPL (for the uninitiated: read-eval-print loop), or modules, or state in lambda-calculus, so whether it is some incompatibility between Scheme and lambda-calculus is a really moot issue. The thing in question is actually "what ought to be the behavior of variable references under state transformations?" Let me repeat my example: (hp3) ~ 502 $ petite Petite Chez Scheme Version 6.0a Copyright (c) 1998 Cadence Research Systems > (define (f) (+ 1 1)) > (f) 2 > (define + -) > (+ 1 1) 0 > (f) 0 So you see that the "+" symbol is being resolved dynamically w.r.t. state changes. I say "state changes" here because in fact in Scheme "(define x ...)" is equivalent to "(set! x ...)" when x is already defined. One of the neat things about Scheme is that the action of compiling a program is (supposed to be) the same as that of just cat'ing it to the standard input of a Scheme REPL, so you can actually make your program do things at compile-time without having to invoke a preprocessor or something. From that perspective, redefining an identifier is just a compile-time state change. (It is worth noting that a DSSSL can never behave like this, because, as I pointed out, redefinitions are only effective for "built-ins".) This is rather different from the way REPLs usually work in typed languages. In the functional language Objective Caml, for instance, a program is not allowed to do anything such as changing the state at compile-time. Therefore you need to think about redefinitions in a different way, namely as identifier shadowing. (hp3) ~ 503 $ ocaml Objective Caml version 2.02 # let f () = 1 + 1;; val f : unit -> int = <fun> # f();; - : int = 2 # let (+) = (-);; val + : int -> int -> int = <fun> # 1 + 1;; - : int = 0 # f();; - : int = 2 Here you see that the denotation of f, i.e., which mathematical function it implements, has not changed despite the fact that we altered the definition of a function that it uses. In a typed language, this is more or less necessary, since otherwise the type of f could change or become ill-typed if we changed the type of +. You could do fancy things like ensure that any redefinition of + in the same session would preserve the type, but that would make the REPL rather less useful---you'd have to restart your session and re-enter all your definitions to change the type of something like +. In Ocaml, you could have gotten the effect of the Scheme definition by using a ref cell: # let plus = ref (+);; val plus : (int -> int -> int) ref = {contents=<fun>} # let f () = !plus 1 1;; (* ! is dereferencing in ML *) val f : unit -> int = <fun> # f();; - : int = 2 # plus := (-);; - : unit = () # f();; - : int = 0 In the Hugs 98 interpreter for the programming language Haskell, the designers have actually disallowed definitions --FAC DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: SOLUTION FOR : How can I add a , Brandon Ibach | Thread | RE: SOLUTION FOR : How can I add a , Frank A. Christoph |
RE: Formatting_the_result, Ron Ross | Date | RE: SOLUTION FOR : How can I add a , Frank A. Christoph |
Month |