From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,99ab4bb580fc34cd X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Q: access to subprogram Date: 1996/07/10 Message-ID: #1/1 X-Deja-AN: 167572234 references: <4rb9dp$qe6@news1.delphi.com> <4rud55$5b0@fu-berlin.de> <4rvo07$bbl@goanna.cs.rmit.edu.au> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-10T00:00:00+00:00 List-Id: In article <4rvo07$bbl@goanna.cs.rmit.edu.au>, Richard A. O'Keefe wrote: >> 1. You can pass procedures around, and copy them willy-nilly, and >> save them in global variables. This is "call backs". Pascal >> does not have this feature. Modula-2 does, and Ada 95 does. > >Lisp, Scheme, ML, ... have this. > >> 2. You can pass procedures IN, and call them, but must never save >> them in global variables. Pascal has this feature. Modula-2 >> does not. Ada 95 does not, unless you count generic formal >> subprograms, which support MOST of this, but not quite all, >> and are overly verbose (IMHO). I didn't really describe what I meant very well. In (1), I meant that you can assign them into global variables, but you're not allowed to pass nested ones. In (2), I meant that you get nesting, but not the assignment. Lisp has full closures, which subsumes both (1) and (2), and also achieves some things that neither (1) and (2) can do. >>Both of the above are desirable, but not at the same time. > >I'm not quite sure what "not at the same time means". If it means >"not in the same language", I'd disagree. If it means "not in the >same program", I wouldn't agree either. I didn't mean either of those two. I agree that a language should have both 1 and 2, and you should be allowed to use them in the same program. I just meant that the purposes are different, and you can view them as two separate features. You use (1), for example, when you want to hand a procedure to the windowing system, saying please call it when the mouse is clicked. You use (2), for example, in iterators -- please crawl around this data structure, and call so-and-so procedure for each component. This is all assuming that you don't want to pay for full closures. (As I said, full closures subsume both of the above features.) My point is that you can retain the stack-based run-time model of Ada, and retain safety against dangling pointers, and still support both (1) and (2) in the language. And the safety doesn't need to involve expensive run-time checks. - Bob