Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!apple!bionet!ig!agate!ucbvax!FREMBL51.BITNET!LANGOWSKI From: LANGOWSKI@FREMBL51.BITNET (Joerg Langowski) Newsgroups: comp.lang.forth Subject: Re: Questions about scoping Message-ID: <8809061903.AA27761@jade.berkeley.edu> Date: 6 Sep 88 10:28:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 54 Doug Felt writes: >1) I would like to use something like header files in C, which I can >include so as to avoid typing in lots of constant definitions for >offsets into structures, parameters, and so on, all of which can be >very error-prone. At the same time I would not like to compile >hundreds of constants into my code, 99% of which will never be used. >Stuff I see in MacTutor usually has pages of constants for just this >purpose. Lots of effort compared to including a few header files. I'd like to have this, too. The reason why I'm including all those constant definitions into the MacTutor examples is simply so that the example is self- consistent; I've in fact been bashed a number of times on the nets by various readers for forgetting one definition or the other. Unfortunately there exist no 'standard' constant definition files in the Mach2 system, so you have to write your own. With clever use of vocabularies you can introduce some kind of scoping at that level. I agree, it is not quite satisfactory yet. In the August MacTutor, you'll find a pretty interesting implementation of an Object Forth under Mach2. Of course, with classes, scoping, type checking, etc. becomes a piece of cake to implement (are you still there, Fraser?). Constants in Mach2 are NOT compiled into the code, they only exist in the vocabulary, which is thrown away in the actual application. So you don't lose anything in terms of memory or efficiency. >2) Are there any good ways to scope names and other declarations? I think I answered some of that; the other point would be that with a good local variable implementation you lose many of those problems. The new version of Mach2 (2.14) has options to reserve local variable blocks and access the loca l dictionary (some hacking still required). Of course, a powerful local variable mechanism has its advantages and drawbacks: the code becomes much more readable, but one is also tempted to write longer blocks of code. Side thought: maybe the admittedly bad readability of the classic 'drip drop flip flop' stack manipulation - which affect code style only on a very low level - has actually promoted factorization in Forth (???). >3) Are there good mechanisms for dynamic memory management? I'm >thinking of heaps, linked lists, trees, and so on. I found it >difficult to use such structures in straight Forth because I couldn't >easily grow and shrink them-- since code and data went into the same >chunk of memory, and the only other dynamic data area was the stack. >I have to use the host machine's operating system to get the memory to >do anything like this, which tends to tie me pretty closely to the >machine (of course, on the Mac this is a given anyway). Yes, on the Mac all of this is provided, and I think in a pretty elegant way. Don't know too much about other systems. Joerg Langowski EMBL, c/o ILL 156X F-38042 Grenoble Cedex France