Forth и другие саморасширяющиеся системы программирования Locations of visitors to this page
Текущее время: Пт апр 19, 2024 19:47

...
Google Search
Forth-FAQ Spy Grafic

Часовой пояс: UTC + 3 часа [ Летнее время ]




Начать новую тему Ответить на тему  [ Сообщений: 3 ] 
Автор Сообщение
 Заголовок сообщения: Мур о некоторых аспектах Форта
СообщениеДобавлено: Сб авг 17, 2013 21:09 
Не в сети
Administrator
Administrator
Аватара пользователя

Зарегистрирован: Вт май 02, 2006 22:48
Сообщения: 7960
Благодарил (а): 25 раз.
Поблагодарили: 144 раз.
http://colorforth.com/binding.html
Цитата:
Early Binding
The interactive nature of Forth leads to recognition of 3 'times':
Edit time. The programmer is editing source code.
Compile time. Source code is being interpreted and compiled.
Run time. Compiled code is being executed.
The earlier in this Edit/Compile/Run sequence a concept can be resolved, the more efficient the code. It is better to do arithmetic at Compile time, than repeat the calculation every Run time. It is better to factor code at Edit time than to expect a smart compiler to do so every Compile time.

Floating-point
Floating-point arithmetic is a classic example of this. It is easy to implement floating-point in Forth, either hardware or software. I, for one, rarely do so.

Fixed-point add is blindingly fast, with no shifting overhead. Fixed-point multiply avoids normalize and rounding cost. Multiplying by a ratio (*/ operator) accurately rescales integers. None of these needs FIX or FLOAT operators, or has to move data to a different stack. The only drawback is the need to choose units and use them consistently. For example, my VLSI simulator uses mV, uA, fC and uK. Multiplying and dividing these takes a little thought as to scale factors. This thought is done at Edit time!

Floating-point would probably use V, A, C and K. These can be combined with formulas from some book. The computer will do the scaling, but does it at Run time! A gigaflop calculation will scale the results giga times. The is convenient and reasonable for prototyping. But insanity for production code.

To repeat: resolve units early in the Edit/Compile/Run sequence.

Conditionals
Another example concerns conditional statements - IF . . . THEN. Minimize them! A conditional is obviously executed at Run time. Let the programmer make the decision at Edit time. This might reduce the range or versatility of the code, but it also reduces testing and improves speed and reliability.

An alternative is to use words like MAX, MIN, ABS that have conditionals built in. They're simple and have been thoroughly tested.

Avoid like the plague, conditional compilation - conditionals at Compile time. These lead to code extremely difficult to read. And very easy to compile incorrectly. For different situations, simply have different versions of the program. In Forth, this usually means blocks with different LOAD sequences.

Portability
Don't try for platform portability. Most platform differences concern hardware interfaces. These are intrinsically different. Any attempt to make them appear the same achieves the lowest common denominator. That is, ignores the features that made the hardware attractive in the first place.

Achieve portability by factoring out code that is identical. Accept that different systems will be different.


Что касается плавающей точки и условных операторов - просто нет слов.


Вернуться к началу
 Профиль Отправить личное сообщение  
Ответить с цитатой  
 Заголовок сообщения: Re: Мур о некоторых аспектах Форта
СообщениеДобавлено: Вс авг 18, 2013 21:12 
Не в сети
Аватара пользователя

Зарегистрирован: Чт июн 25, 2009 11:12
Сообщения: 412
Благодарил (а): 41 раз.
Поблагодарили: 8 раз.
Правильный выбор единиц измерения для вынесения лишних расчетов из программы--это классика 50-х годов :)

Цитата:
Avoid like the plague, conditional compilation - conditionals at Compile time. These lead to code extremely difficult to read. And very easy to compile incorrectly.

А вот с этим согласен.


Вернуться к началу
 Профиль Отправить личное сообщение  
Ответить с цитатой  
 Заголовок сообщения: Re: Мур о некоторых аспектах Форта
СообщениеДобавлено: Вс авг 18, 2013 21:36 
Не в сети
Administrator
Administrator
Аватара пользователя

Зарегистрирован: Вт май 02, 2006 22:48
Сообщения: 7960
Благодарил (а): 25 раз.
Поблагодарили: 144 раз.
dynamic-wind писал(а):
Правильный выбор единиц измерения для вынесения лишних расчетов из программы--это классика 50-х годов

С 50-х годов несколько изменилась ситуация. Конечно, решать задачу чисто силовыми методами не стоит (а плавающая точка требует существенно больше аппаратных ресурсов). Однако тут далеко не все так просто, и дело не только в весе одного разряда. То, о чем пишет Мур, называется фиксированной точкой. Она действительно технически реализуема на целочисленной аппаратуре. Однако вот такой вопрос: пусть a и b принадлежат отрезку [3; 5]. Какие значения может принимать a*b для целочисленной и вещественной арифметики соответственно? Напрашивается ответ [9; 25], только для целочисленной - целые значения, а для вещественной - вещественные. Так ли это?

dynamic-wind писал(а):
Цитата:
Avoid like the plague, conditional compilation - conditionals at Compile time. These lead to code extremely difficult to read. And very easy to compile incorrectly.

А вот с этим согласен.


А вот я в этом вижу мощный инструмент для создания "долгоживущих" программ.


Вернуться к началу
 Профиль Отправить личное сообщение  
Ответить с цитатой  
Показать сообщения за:  Поле сортировки  
Начать новую тему Ответить на тему  [ Сообщений: 3 ] 

Часовой пояс: UTC + 3 часа [ Летнее время ]


Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 28


Вы не можете начинать темы
Вы можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB сборка от FladeX // Русская поддержка phpBB