Re: Frozen sequences
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Jan 29, 1999
- 526 views
Bernhard Gausen wrote: > I just got this idea, and I want to here some opinions about it. > > I understand that one problem with sequences is that they support > dynamical memory allocation even when this is not required or > even wanted, since it slows down things. Actually, it would only speed it up, if the 'freeze' routine was on the top-level. Why? Because only then, the interpreter can replace all slices in the sequece, with direct memory addresses. This is why I wanted arrays. The speed, but also the ability to define such a common type, easily. How often do we work wiht multi-dimensional sequences, of a fixed length for every direction. Often. Graphics, Text, etc. Im not into changing any of the documentation. Im in favor of an alternative way to define the structure of a sequence. Sequences are still sequences. A structure is nothing more than sequences, and constants pointing to elements of the structure. However, the amount of work to write a type-check function, for even the most simply structure is not worth the trouble. Same with arrays. We often use them. I just want a quick way to do things as they can already be done. But it will take 100 lines to do so, if you want to maintain the same level of type-checking. For a structure you currently need to: You have to go through a sequence, test it length. Test all elements. You have to setup the sequence, and initialize all the elements. You have to setup constants to point to certain elements of the sequence. You have to worry about namespace, because of all those constants. Example: Two structures, one is addres, other is friend. addres has two entries: Street .. a one dimensional sequence House .. an integer number Tel .. a one dimensional sequence Friend has two entries: name .. a one dimenisonal sequence Tel .. a one dimensional sequence ? my_addres[TEL] ? my_friend[TEL] In the case of my_friend, tel has to mean: 2. In the case of addres, tel has to mean: 3 However, this wouldnt even work, because when you declare TEL for the second time, an error occurs. This is one of the namespace problems. The other is: there is only one global namespace. For any modular program this is a hell. Example: I have a font library using graphics.e I myself am using neil.e (Pete's graphics library) Both graphics.e and Neil.e have a display_image routine. Currently, you cant use both at the same time, because those name conflict. Which is weird, because for any human it would be clear which one to use when: In font.e include graphics.e display_image (..... ) In program.ex include font.e include neil.e display_image (...) Display_image is not a routine of font.e It is of Neil.e That font.e loaded graphics.e is irrelevant for program.ex If program.ex wanted to use display_image from graphics.e it would have included graphics.e itself. However, when you shroud a program or library. The namespace *does* work ok. (it only keeps the global identifers from the file you shroud global. The rest is made local. Ralf N. nieuwen at xs4all.nl ralf_n at email.com