How to change the definition of a word

In the answer that curtisk has provided a link to Bryan Oakley states that this is not possible:

You can’t modify how «wordstart» defines «words».

But based on his answer I have developed the following method select_current_word, the code around is just to illustrate it’s usage.

import Tkinter as tk

class MyText(tk.Text):

     def __init__(self, **kw):
         tk.Text.__init__(self, **kw)
         self.bind('<Double-Button-1>', self.select_current_word)

     def select_current_word(self, event):
         i0 = self.search(r'[-w]+', tk.CURRENT+'+1c', backwards=True, regexp=True)
         i1 = self.search(r'[^-w]+', i0, forwards=True, regexp=True)
         self.tag_remove(tk.SEL, '1.0', tk.END)
         self.tag_add(tk.SEL, i0, i1)
         self.update()
         return 'break'

if __name__=='__main__':
     t = MyText()
     t.pack(expand=True, fill=tk.BOTH)
     t.insert('1.0', """
Options:
  General Options:
     -h, --help                       Print this help text and exit
     --version                        Print program version and exit
     -U, --update                     Update this program to latest version.
""".strip())
     t.mainloop()

It is hard but not impossible

“MISOGYNY” SEEMS a straightforward word. In dictionaries, it is “hatred of women”. In its etymology are the Greek verb misein, to hate, and gyne, women. The word, like the sentiment, has been around for a long time. Euripides, an ancient Greek playwright, was called a misogynes, or woman-hater. (“Well, in his tragedies, yes,” his peer Sophocles is said to have quipped, “but in bed at any rate he was a philogynes.”) The first known use of “misogynist” in English is from 1620—by a female group counter-attacking against a screed called “The Arraignment of Lewd, Idle, Froward [sic], and Unconstant Women”.

Listen to this story.

Enjoy more audio and podcasts on iOS or Android.

Your browser does not support the <audio> element.

In fact, very few interesting words are quite so stable. As they are used, their meanings drift. Furthermore, they need not remain true to their etymological roots, a belief known to linguists as the “etymological fallacy”. The word “person”, for instance, comes from the Latin for “mask”; the word “tragedy” may derive from the Greek for “goat-song”. Over time, words evolve.

Much of that process is random. But it is also possible to make a conscious effort to shift how a word is used. One such bid is under way for “misogyny”. For decades, feminists have expanded its connotations beyond the idea of “hatred of women”. Recently Kate Manne, a philosopher at Cornell University, has become the voice of that campaign. She thinks the notion of a hatred for all women deep in the psychology of some men is philosophically untestable. In any case, few men, she says, really hate all women. Instead of misogyny meaning something men feel, she says it should designate something women face.

Ms Manne distinguishes between sexist beliefs and systemic prejudice. For instance, the idea that women have certain innate characteristics (being loving and nurturing, say) and natural roles that derive from them (wife, mother) is sexist. It is when women fail to behave as they “should” that her version of misogyny comes into play—when men punish them for being too sexually active (or not enough), for neglecting their domestic responsibilities or for claiming “male” roles such as leadership. Her misogyny is the enforcement structure of sexism.

In her recent book “Down Girl”, Ms Manne argues for an “ameliorative” approach to concepts (one she draws from another philosopher, Sally Haslanger), whereby they are made fit for philosophical scrutiny. The vindictive psychology of some men is beyond such analysis, but the expectations widely imposed on women, and how non-conformists are treated, can be probed, and maybe even changed.

What words mean is generally determined another way: most linguists believe that they simply mean what people use them to mean. As virtually all modern lexicographers acknowledge, dictionaries are there to register actual usage, not to tell the mass of people that they are deploying a word incorrectly. If philosophers or activists want dictionaries to include a new meaning, they have to get people to use the word that way.

Sometimes they succeed. In 2012 Julia Gillard, Australia’s prime minister, gave her renowned “misogyny speech”, lambasting her rival Tony Abbott for referring to Ms Gillard “making an honest woman of herself”, and for posing by a sign reading “ditch the witch”. Traditionalists pounced; Mr Abbott didn’t hate all women, they said, so Ms Gillard obviously didn’t know what misogyny meant. In response, Macquarie, an Australian dictionary publisher, expanded its definition of the word to include “entrenched prejudice against women”.

There are other ways to wage a social struggle on the lexical front. Inventing a word is one; Ms Manne has written about “himpathy”, which she uses to describe outbreaks of disproportionate concern for the future of a man accused of harassment, rape or other violence towards women. The term is pointed and memorable, and is spreading online.

Repurposing an existing word is harder; the inertia of the older meaning must be overcome. But this can be done, as (more intentionally than Ms Gillard) theorists and activists managed with “queer”. Whether inventing or repurposing words, in refusing to kowtow to inherited concepts Ms Manne is emulating Friedrich Nietzsche, who said that philosophers “must no longer accept concepts as a gift, nor merely purify and polish them, but first make and create them, present them and make them convincing”. Sound argument is needed to persuade other philosophers of such intellectual leaps; to enlist the wider world, a compelling vocabulary is vital.

This article appeared in the Culture section of the print edition under the headline «In the beginning is the word»

Texafornia: A glimpse into America’s future

From the June 22nd 2019 edition

Discover stories from this section and more in the list of contents

Explore the edition

Generalization, Specialization, Amelioration, and Pejoration

APCortizasJr / Getty Images

Updated on October 05, 2018

Stick around long enough and you’ll notice that language changes—whether you like it or not. Consider this recent report from columnist Martha Gill on the redefinition of the word literally:

It’s happened. Literally the most misused word in the language has officially changed definition. Now as well as meaning «in a literal manner or sense; exactly: ‘the driver took it literally when asked to go straight over the traffic circle,'» various dictionaries have added its other more recent usage. As Google puts it, «literally» can be used «to acknowledge that something is not literally true but is used for emphasis or to express strong feeling.» . . .

«Literally,» you see, in its development from knock-kneed, single-purpose utterance, to swan-like dual-purpose term, has reached that awkward stage. It is neither one nor the other, and it can’t do anything right.»

(Martha Gill, «Have We Literally Broken the English Language?» The Guardian [UK], August 13, 2013)

Changes in word meanings (a process called semantic shift) happen for various reasons and in various ways. Four common types of change are broadening, narrowing, amelioration, and pejoration. (For more detailed discussions of these processes, click on the highlighted terms.)

  • Broadening
    Also known as generalization or extension, broadening is the process by which a word’s meaning becomes more inclusive than an earlier meaning. In Old English, for instance, the word dog referred to just one particular breed, and thing meant a public assembly. In contemporary English, of course, dog can refer to many different breeds, and thing can refer to, well, anything.
  • Narrowing
    The opposite of broadening is narrowing (also called specialization or restriction), a type of semantic change in which a word’s meaning becomes less inclusive. For example, in Middle English, deer could refer to any animal, and girl could mean a young person of either sex. Today, those words have more specific meanings.
  • Amelioration
    Amelioration refers to the upgrading or rise in status of a word’s meaning. For example, meticulous once meant «fearful or timid,» and sensitive meant simply «capable of using one’s senses.»
  • Pejoration
    More common than amelioration is the downgrading or depreciation of a word’s meaning, a process called pejoration. The adjective silly, for instance, once meant «blessed» or «innocent,» officious meant «hard working,» and aggravate meant to «increase the weight» of something.

What’s worth keeping in mind is that meanings don’t change over night. Different meanings of the same word often overlap, and new meanings can co-exist with older meanings for centuries. In linguistic terms, polysemy is the rule, not the exception.

«Words are by nature incurably fuzzy,» says linguist Jean Aitchison in the book Language Change: Progress Or Decay. In recent years, the adverb literally has become exceptionally fuzzy. In fact, it has slipped into the rare category of Janus words, joining terms like sanction, bolt, and fix that contain opposite or contradictory meanings.

Martha Gill concludes that there’s not much we can do about literally. The awkward stage that it’s going through may last for quite some time. «It is a moot word,» she says. «We just have to leave it up in its bedroom for a while until it grows up a bit.»

More About Language Change

  • The Endless Decline of the English Language
  • The Great Vowel Shift
  • Inconceivable!: 5 Words That May Not Mean What You Think They Mean
  • Key Dates in the History of the English Language
  • Six Common Myths About Language
  • Semantic Change and the Etymological Fallacy

>Change of meaning. Extension, narrowing, elevation, degradation of meaning of a word, metaphor, metonymy.
Change of meaning. Extension, narrowing, elevation, degradation of meaning of a word, metaphor, metonymy.

>Definition of changes of word meaning Types of changes Extension Elevation Narrowing Degradation Metaphor
Definition of changes of word meaning Types of changes Extension Elevation Narrowing Degradation Metaphor Metonomy

>Changes in word meaning When a word loses its old meaning and comes to
Changes in word meaning When a word loses its old meaning and comes to refer to something different, the result is a change in word meaning. Change of meaning refers to the alternation of the meaning of existing words, as well as the addition of new meaning to a particular word. Changing word meaning has never ceased since the beginning of the language and will continue in the future. The changes in meaning are gradual, and words are not changed in a day.

>Types of Change -Extension of meaning -Narrowing of meaning -Elevation of meaning -Degradation of
Types of Change -Extension of meaning -Narrowing of meaning -Elevation of meaning -Degradation of meaning

>Extension of Meaning - Generalization of Meaning It is a process by which a
Extension of Meaning — Generalization of Meaning It is a process by which a word which originally had a specialized meaning has now become generalized or has extended to cover a broader concept.

>salary (original) a sum of money given to Roman soldiers to enable them to
salary (original) a sum of money given to Roman soldiers to enable them to buy salt (present) fixed payment made by employer at regular intervals to employees holiday (original) holy day, a day of religious significance (present) day of festivity or recreation

>She is such a pretty little thing. I have to pack my things for
She is such a pretty little thing. I have to pack my things for the journey. There is another thing I want to ask you about. That only makes things worse. The thing is, can we finish the job in time? A large proportion of polysemous words of modern English have their meanings extended sometime in the course of development. Some words are generalized to such a degree that they can mean almost everything. “Thing” which used to mean “a public assembly” or “a council” in Anglo-Saxon times, now has become an all-purpose word. Its meaning is so general, and we sometimes call this noun a ‘light noun’.

>Generalization of meaning is also found in many technical terms, which are confined to
Generalization of meaning is also found in many technical terms, which are confined to specialized use. allergic (original) too sensitive to medicine (present) averse or disinclined alibi (original) a legal term signifying “the plea that the accused is not at the place when the crime is committed” (present) excuse

>Narrowing of Meaning It is a process by which a word of wide meaning
Narrowing of Meaning It is a process by which a word of wide meaning acquires a narrow or specialized sense. In other words, a word which used to have a more general sense becomes restricted in its application and conveys a special concept in present-day English. Narrowing; specialization; restriction

>

>Narrowing of Meaning For economy, some phrases are shortened and only one element of
Narrowing of Meaning For economy, some phrases are shortened and only one element of the original, usually an adjective, is left to retain the meaning of the whole. Such adjectives have thus taken on specialized meanings. a general = a general officer an editorial = an editorial article Some material nouns are used to refer to objects made of them and thus have a more specific sense. glass a cup-like container or a mirror iron device for smoothing clothes

>Change in associative meaning Both extension and narrowing of meaning are talking about the
Change in associative meaning Both extension and narrowing of meaning are talking about the changes in conceptual meaning. Next we will talk about the changes in associative meaning. Elevation of meaning Degradation of meaning

>Elevation of Meaning (amelioration) -It is the process by which words rise from humble
Elevation of Meaning (amelioration) -It is the process by which words rise from humble beginnings to positions of importance. -Some words early in their history signify something quite low or humble, but change to designate something agreeable or pleasant. -A “snarl” word becomes a “purr” word, or a slang becomes a common word. -elevation; amelioration

>Examples of elevation nice -ignorant --- foolish --- delightful, pleasant fond -foolish --- affectionate
Examples of elevation nice -ignorant — foolish — delightful, pleasant fond -foolish — affectionate awesome -terrible—terrific marshal -a keeper of horses — a high ranking army officer constable -a keeper of horses — a policeman Terrific headache Terrific party

>Degradation of Meaning It is a process by which words with appreciatory or neutral
Degradation of Meaning It is a process by which words with appreciatory or neutral affective meaning fall into ill reputation or come to be used in a derogatory sense. A “purr” word becomes a “snarl” word. degradation, degeneration, pejoration

>Examples silly blessed and happy--- innocent----simple or simple-minded ----foolish sad full, satisfied, contented -----
Examples silly blessed and happy— innocent—-simple or simple-minded —-foolish sad full, satisfied, contented —— calm —— serious —-sorrowful

>Figurative use of words Change in word meaning may result from the figurative use
Figurative use of words Change in word meaning may result from the figurative use of the language. Metaphor and metonymy are two important figures of speech. Metaphor is a figure of speech containing an implied comparison based on similarity. E.x.: A cunning person may be referred to as a fox. Here “fox” means something other than its literal meaning. The word “fox” gets the figurative meaning of “a cunning person”.

>Metaphor This is also a horse, but a metaphorical horse.
Metaphor This is also a horse, but a metaphorical horse.

>Example: foot foot 1. The lower extremity of the vertebrate leg that is in
Example: foot foot 1. The lower extremity of the vertebrate leg that is in direct contact with the ground in standing or walking. 2. The lowest part; the bottom the foot of a mountain the foot of a page This meaning is derived through the metaphor “The last line on this page is the foot of the page.”

>Metonymy is another important factor in semantic change. It is a figure of speech
Metonymy is another important factor in semantic change. It is a figure of speech by which an object or an idea is described by the name of something else closely related to it.

>Example: seat Seat (its sense is extended to the right to sit as a
Example: seat Seat (its sense is extended to the right to sit as a member of a committee, such as the House of Commons) He lost his seat in House of Commons. The word “seat” has acquired the meaning of “the right to sit as a member” through the above metonym.

>More Example: cradle Cradle 1. A small low bed for an infant, often furnished
More Example: cradle Cradle 1. A small low bed for an infant, often furnished with rockers 2. The earliest period of life; infancy from the cradle to the grave 3. A place of origin; a birthplace the cradle of civilization. These meanings are derived through the following metonyms.

Conversion
(zero derivation, root formation, functional change) is the process
of coining a new word in a different part of speech and with
different distribution characteristics but without adding any
derivative element, so that the basic form of the original and the
basic form of derived words are homonymous. This phenomenon can be
illustrated by the following cases: work – to work, love – to
love, water – to water.

If
we regard these words from the angle of their morphemic structure, we
see that they are root words. On the derivational level, however, one
of them should be referred to a derived word, as having the same root
morpheme they belong to different parts of speech. Consequently the
question arises here: “What serves as the word-building means in
such cases?” It would appear that the noun is formed from the verb
(or vice versa) without any morphological change, but if we probe
deeper into the matter, we inevitably come to the conclusion that the
two words differ only in the paradigm. Thus, it is the paradigm that
is used as a word-building means. Hence, we can define conversion as
the formation of a new word through changes in its paradigm.

The
change of the paradigm is the only word-building means of conversion.
As the paradigm is a morphological category, conversion can be
described as a morphological way of forming words.

As
a type of word-formation conversion exists in many languages. What is
specific for the English vocabulary is not its mere presence, but its
intense development.

The
main reason for the widespread development of conversion in
present-day English is no doubt the absence of morphological elements
serving as classifying signals, or, in other words, of formal signs
marking the part of speech to which the word belongs. The fact that
the sound pattern does not show to what part of speech the word
belongs may be illustrated by the word back. It may be a noun, a
verb, an adjective, an adverb.

Many
affixes are homonymous and therefore the general sound pattern does
not contain any information as to the possible part of speech.

e.g.:
maiden
(N), darken (V), woollen (A), often (Adv).

O.
Jesperson points out that the causes that made conversion so widely
spread are to be approached diachronically. The noun and verb have
become identical in form firstly as a result of the loss of endings.
More rarely it is the prefix that is lost (mind < gemynd). When
endings had disappeared phonetical development resulted in the
merging of sound forms for both elements of these pairs.

e.g.:
OE carian
(verb)
and caru
(noun)
merged into care
(verb,
noun); OE drinkan
(verb)
and drinca,
drinc
(noun)
merged into
drink
(verb, noun).

A
similar homonymy resulted in the borrowing from French of pairs of
words of the same root but belonging in French to different parts of
speech. These words lost their affixes and became phonetically
identical in the process of assimilation.

Prof.
A. Smirnitsky is of the opinion that on a synchronic level there is
no difference in correlation between such cases as listed above, i.e.
words originally differentiated by affixes and later becoming
homonymous after the loss of endings (sleep

noun :: sleep
– verb) and those formed by conversion (pencil
– noun :: pencil

verb).

Prof.
I. Arnold is of the opinion that prof. Smirnitsky is mistaken. His
mistake is in the wish to call both cases conversion, which is
illogical if he, or any of his followers, accepts the definition of
conversion as a word-building process which implies the diachronistic
approach. Prof. I. Arnold states that synchronically both types sleep
(noun) – sleep (verb) and pencil (noun) – pencil (verb) must be
treated together as cases of patterned homonymy. But it is essential
to differentiate the cases of conversion and treat them separately
when the study is diachronistic.

Conversion
has been the subject of a great many discussions since 1891 when

H.
Sweet first used the term in his New English Grammar. Various
opinions have been expressed on the nature and character of
conversion in the English language and different conceptions have
been put forward.

The
treatment of conversion as a morphological way of forming words was
suggested by A.I. Smirnitsky and accepted by R.Z. Ginzburg, S.S.
Khidekel,

G.Y.
Knyazeva, A.A. Sankin.

Other
linguists sharing, on the whole, the conception of conversion as a
morphological way of forming words disagree, however, as to what
serves here as a word-building means. Some of them define conversion
as a non-affixal way of forming words pointing out that its
characteristic feature is that a certain stem is used for the
formation of a categorically different word without a derivational
affix being added

(I.R.
Galperin, Y.B. Cherkasskaya).

Others
hold the view that conversion is the formation of new words with the
help of a zero-morpheme (H. Marchand).

There
is also a point of view on conversion as a morphological-syntactic
word-building means (Y.A. Zhluktenko), for it involves, as the
linguists sharing this conception maintain, both a change of the
paradigm and of the syntactic function of the word.

e.g.:
I
need some paper for my room : He is papering his room.

Besides,
there is also a purely syntactic approach commonly known as a
functional approach to conversion. In Great Britain and the United
States of America linguists are inclined to regard conversion as a
kind of functional change. They define conversion as a shift from one
part of speech to another contending that in modern English a word
may function as two different parts of speech at the same time.

The
two categories of parts of speech especially affected by conversion
are the noun and the verb. Verbs made from nouns are the most
numerous among the words produced by conversion.

e.g.:
to
hand, to face, to nose, to dog, to blackmail.

Nouns
are frequently made from verbs: catch,
cut, walk, move, go.

Verbs
can also be made from adjectives: to
pale, to yellow, to cool.

A
word made by conversion has a different meaning from that of the word
from which it was made though the two meanings can be associated.
There are certain regularities in these associations which can be
roughly classified. In the group of verbs made from nouns some
regular semantic associations are the following:


A noun is a name of a tool – a verb denotes an action performed by
the tool:
to
knife,
to brush.


A noun is a name of an animal – a verb denotes an action or aspect
of behaviour typical of the animal: monkey
– to monkey, snake – to snake.
Yet, to fish does not mean to behave like a fish but to try to catch
fish.


A noun denotes a part of a human body – a verb denotes an action
performed by it : hand
– to hand, shoulder – to shoulder.
However, to face does not imply doing something by or even with one’s
face but turning it in a certain direction.


A noun is a name of some profession or occupation – a verb denotes
an activity typical of it : a
butcher – to butcher, a father – to father.


A noun is a name of a place – a verb denotes the process of
occupying this place or putting something into it: a
bed – to bed, a corner – to corner.


A noun is the name of a container – a verb denotes an act of
putting something within the container: a
can – to can, a bottle – to bottle.


A noun is the name of a meal – a verb denotes the process of taking
it: supper
– to supper, lunch – to lunch.

The
suggested groups do not include all the great variety of verbs made
from nouns by conversion. They just represent the most obvious cases
and illustrate the great variety of semantic interrelations within
the so-called converted pairs and the complex nature of the logical
associations which underlie them.

In
actual fact, these associations are more complex and sometimes even
perplexing.

Types
of Conversion

Partial
conversion is a kind of a double process when first a noun is formed
by conversion from a verbal stem and next this noun is combined with
such verbs as to give, to make, to take to form a separate phrase: to
have a look, to take a swim, to give a whistle.

There
is a great number of idiomatic prepositional phrases as well: to be
in the know, in the long run, to get into a scrape. Sometimes the
elements of these expressions have a fixed grammatical form, as, for
example, where the noun is always plural: It
gives
me
the creeps (jumps).
In other cases the grammatical forms are free to change.

Reconversion
is the phenomenon when one of the meanings of the converted word is a
source for a new meaning of the same stem: cable
(металевий
провідник)
– to cable (телеграфувати)
– cable(телеграма);
help(допомога)
– to help (допомагати
пригощати)
– help (порція
їжі),
deal (кількість)
– to deal (роздавати)
– deal (роздача
карт).

Substantivation
can also be considered as a type of conversion. Complete
substantivation is a kind of substantivation when the whole paradigm
of a noun is acquired: a private — the private – privates – the
privates. Alongside with complete substantivation there exists
partial substantivation when a feature or several features of a
paradigm of a noun are acquired: the rich. Besides the substantivized
adjectives denoting human beings there is a considerable group of
abstract nouns: the Singular, the Present. It is thus evident that
substantivation has been the object of much controversy. Those who do
not accept substantivation of adjectives as a type of conversion
consider conversion as a process limited to the formation of verbs
from nouns and nouns from verbs. But this point of view is far from
being universally accepted.

Conversion
is not characteristic of the Ukrainian language. The only type of
conversion that can be found there is substantivation:
молодий,
хворий.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]

  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #
  • #

There are two principal modes of editing on the OED. The first is editing from scratch – that is, editing a word or sense that is entirely new to the dictionary; the second is revising and updating an existing dictionary entry. In general the editorial process followed by New Words and Revision editors is similar, the principal difference being that Revision editors start with text from an earlier edition of the dictionary, and New words editors start with a collection of quotations and other references to a particular word or meaning.

Why is the OED being revised?

The original OED was published between 1884 and 1928. New words and new meanings of old words have been added to the dictionary since then, but the basic text of the dictionary remained unchanged. Smaller Oxford dictionaries have, of course, been updated regularly, but it was only with the computerization of the text of the dictionary in the 1980s that revising the OED became a practical possibility.

Over the same period the English language has continued to change and adapt: geographical varieties of English, for example, are much more established than they were when the OED was first compiled; enormous social changes have altered how we speak. Similarly, many new discoveries about the language have been made by scholars and others over this period. All of this feeds into the revised text of the OED.

How is an OED entry compiled?

The principal components of an OED dictionary entry are the spelling, etymology, pronunciation, illustrative quotations, and definition(s). Once the basic components are in place, the editor will need to give the whole entry an overview, to ensure that the various parts satisfactorily demonstrate the term’s history and development in English. Not all of the processes will necessarily be appropriate for any given word.

How is a word spelled (or spelt)?

The editor will review evidence for the modern spellings of a term (including capitalization, hyphenation, regional variation) before deciding on the form or forms which should appear as the main spelling of the headword.

In addition to this, all other available spellings of the term over history are reviewed and listed by century (and sometimes also by region, etc.).

So although piazza is chosen as the principal spelling, it is important to show (and if necessary explain) spelling forms that have been found in English over history.

From the list of variant spellings it is possible to see that the modern form piazza dates right back to the 1500s, when the word was borrowed into English from the Italian piazza. But as the centuries passed, numerous by-forms arose as the spelling started to follow variant pronunciations in Scotland and in America.

Etymology: on the origins of words

If the etymology of a word appears straightforward, then this part of the entry can be written by the regular Revision or New words editor. Particularly simple etymologies are those for words formed in English from existing English elements.

Examples of new words formed within English are:

computer game, from computer + game

or

world-like, from world + like

However, even apparently simple etymologies can in fact require considerably more work, by specialist etymologists, before they are right. And so all etymologies are reviewed by the OED‘s etymological editors before they are published. Of the various sources for words, the three most important are borrowing, blending, and invention.

Borrowing

Foreign languages are still a common source of new words, which are borrowed for various reasons, for example:

  • as the name of a food or dish originating in the region where the language is spoken (e.g. bhaji, tzatziki)
  • to describe a cultural or political concept originating in or unique to that region (e.g. feng shui, Knesset, glasnost)
  • as the name of an animal or plant found in that region (e.g. kiwi, aardvark, jojoba)

Blending

Another way in which new words enter the language is by blending two or more existing words, or parts of words. The etymologies of such words note the original words which have been blended, and sometimes other words which have either been formed in the same way or which the new word is intended to resemble. Examples of such words include digerati (from digital and literati), affluenza (from affluent and influenza), chocoholic (from chocolate and alcoholic) and Trustafarian (from trust (trust-fund) and Rastafarian).

Science words

Scientific terms are frequently coined specifically for the purpose of describing a new discovery, invention, or concept. In writing the etymology of such terms, the OED‘s aim is to trace the coinage where possible, usually by following references in the scientific literature. Further research is also necessary, to find out why the word took the form it did: a new mineral may be named after the place where it was found (e.g. bauxite, from Les Baux in south-east France); a drug may be named by combining elements of the words which describe its molecule (e.g. diazepam, from benzodiazepine and amide); a biological structure may be given a name based on Latin or Greek words describing its function or appearance (e.g. mastigoneme, a hair-like structure taking its name from the ancient Greek words for whip and thread). Sometimes, a word may simply have been made up (e.g. nylon), and the OED needs to record if this may have been the case.

For another example see the OED entry for magenta, named after the northern Italian town near where Napoleon III defeated the Austrians in 1859, shortly before the dye was discovered.

Etymology is sometimes thought of as the science of tracing a word’s history back to its ‘origin’, which might be within English, or in another language or languages before it arrived in English. But the OED‘s interest in the prehistory of a word is largely in order to explain aspects of its use in English (when did a particular nuance of meaning evolve; how many other contemporary languages share a form of the word, and why? is the developmental course of the word regular – or at least comparable with that of other words?).

In order to be able to answer questions like these, the OED‘s etymologists take a grand survey of existing records of and writing about each word, and summarize this with particular reference to the period at which the word entered English.

Sometimes the results of this work may appear complex, but then language isn’t always simple – and we can’t understand the network of today’s language without a sense of how it developed to its present state. We understand more about climate, for example, by consulting the etymology for the word than we would by restricting ourselves to the definitions.

Pronunciation: the sounds of English

Editors are responsible for adding or updating the information which the OED provides on the pronunciation of individual terms.

Whereas the First and Second Editions of the dictionary simply offered a modern British English pronunciation, the Third Edition offers British and American English pronunciations, along with pronunciations from other varieties of English when they are relevant for particular terms. For example:

Pronunciations are not given for obsolete words. If the pronunciation history of a word needs discussion, then this will be found within the word’s etymology.

Take, for example, the case of restaurant

The pronunciation of a word is not normally apparent from the documentary evidence on which OED definitions are largely based (though sometimes these do provide observations or other contextual information). As a result, editors frequently consult secondary sources for specialist information on pronunciation. More information on the pronunciations given in the OED can be found in the key to pronunciation.

The OED‘s pronunciations are presented in the International Phonetic Alphabet. The version of this used in revised and new entries is based on that of the Oxford Dictionary of Pronunciation for Current English (2001: Upton, Kretzschmar, Konopka).

Illustrative quotations

Each OED entry presents quotations from any of a wide range of sources, to illustrate the uses being defined.

Example: genetic adj. sense 1b:

The first quotation in any block of illustrative quotations is always the earliest example that was available to editors when the entry was prepared.

Subsequent quotations are chosen for a number of reasons, which include demonstrating:

  • the period of time over which the meaning is evidenced (and if relevant when it fell out of use)
  • the geographical spread of the term
  • the types of sources (genre, etc.) in which it occurs
  • typical registers of use

It is not always possible to show every aspect of these features in the quotation paragraphs. The intention is to give an idea of the extent of use, not to document it comprehensively. This information supplements that given in the definition and by way of subject, usage, and other labels.

The latest quotation dates from the modern period, or the period at which a use is seen to fall into disuse and the typical format of a quotation is:

  • date of first publication, author’s name, short-title of work, date of publication of edition used, location in text (often chapter and page), quotation text (original spelling).

Example of simple quotation cited at major adj.:

The complexities of bibliographical style mean that there is ample scope for varying from this basic style.

Quotations are preferably taken from the first edition of the work cited, though there are sometimes reasons for citing other editions.

It is often noted that the quotations can help to ‘explain’ a definition, and this is particularly noticeable in the case of verbs. The accompanying quotations often help the user distinguish, for example, between subtle syntactic differences between senses.

Reading the quotations helps to disambiguate senses 3 and 4 at marvel v.1:

Definitions: explaining meaning

This is the stage of the editorial process at which the definition is written (or revised) and a selection of illustrative quotations are chosen to accompany the definition.

The definition should be written in such a way that it reflects the usage exemplified by the available quotations. However, the editor must first identify which aspects of the term are significant to form part of the definition. Many inconsequential (or less significant) attributes of a word may be omitted from the final definition.

Here, for example, are several attributes of different books which may be mentioned in the quotations:

  • placed on a windowsill
  • has a red cover
  • contains text to be read
  • consists of pages
  • will take a long time to read
  • contains pictures

But not all of these attributes of particular books are important or generic enough to be included in the definition.

Definitions themselves should have characteristic attributes. They should (as far as possible):

  • be written concisely and elegantly
  • be unambiguous in meaning
  • describe the key features of the term defined
  • contain as little technical vocabulary as possible
  • help the reader understand the use of the word in context
  • use formal but modern language, and avoid informal and slang phraseology
  • relegate important secondary information (if needed) to an accompanying note

The definition of bicycle in the First Edition of the OED (which was published in 1888) meets most of these criteria, but it would fail as a modern definition on several counts.

“A machine for rapid riding, consisting of a saddle-seat surmounting two wheels, to which the rider communicates motion by means of treadles; a two-wheeled velocipede.”

By contrast, this modern redefinition of one of the subsenses of myth does meet all of these criteria:

“A widespread but untrue or erroneous story or belief; a widely held misconception; a misrepresentation of the truth. Also: something existing only in myth; a fictitious or imaginary person or thing”.

>> Researching the language

I’m currently writing my thesis in ShareLatex (I’m a romanian) and I can’t change the words «Definition», «Theorem», etc… to «Definitia», «Teorema». I tried the syntax used with the babel package but it still doesn’t work. I tried the renewcommand to change «Contents» to «Cuprins» and it worked.

Please help me.

cgnieder's user avatar

cgnieder

65.6k5 gold badges169 silver badges375 bronze badges

asked Mar 28, 2017 at 18:07

Sorina Popescu's user avatar

2

Try this:

documentclass[12pt,a4paper]{article}

usepackage[fleqn]{amsmath}
usepackage{amsthm}

newtheorem*{defn*}{Definitia}

begin{document}
begin{defn*}
    This is a definition.
end{defn*}

end{document}

Definitia

answered Mar 28, 2017 at 18:50

Athena Widget's user avatar

Athena WidgetAthena Widget

6431 gold badge7 silver badges19 bronze badges

1

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

In comparison with conventional languages, Forth’s compiler is completely backwards. Traditional compilers are huge programs designed to translate any foreseeable, legal combination of available operators into machine language. In Forth, however, most of the work of compilation is done by a single definition, only a few lines long. Special structures like conditionals and loops are not compiled by the compiler but by the words being compiled (IF, DO, etc.)

Lest you scoff at Forth’s simple ways, notice that Forth is unique among languages in the ease with which you can extend the compiler. Defining new, specialized compilers is as easy as defining any other word, as you will soon see.

When you’ve got an extensible compiler, you’ve got a very powerful language!

On This Page

  • Just a Question of Time
  • How to Define a Defining Word
  • Defining Words You Can Define Yourself
  • How to Control the Colon Compiler
    • More Compiler-Controlling Words
  • Curtain Calls
  • Chapter Summary
    • Forth Words
    • Review of Terms
    • Problems … Chapter 11

Just a Question of Time

Before we get fully into this chapter, let’s review one particular concept that can be a problem to beginning Forth programmers. It’s a question of time.

We have used the term “run time” when referring to things that occur when a word is executed and “compile time” when referring to things that happen when a word is compiled. So far so good. But things get a little confusing when a single word has both a run-time and a compile-time behavior.

In general there are two classes of words which behave in both ways. For purposes of this discussion, we’ll call these two classes “defining words” and “compiling words.”

A defining word is a a word which, when executed, compiles a new definition. A defining word specifies the compile-time and run-time behavior of each member of the “family” of words that it defines. Using the defining word CONSTANT as an example, when we say

80 CONSTANT MARGIN

we are executing the compile-time behavior of CONSTANT; that is, CONSTANT is compiling a new constant-type dictionary entry called MARGIN and storing the value 80 into its parameter field. But when we say

MARGIN

we are executing the run-time behavior of CONSTANT; that is, CONSTANT is pushing the value 80 onto the stack. We’ll pursue defining words further in the next few sections.

The other type of word which possesses dual behavior is the “compiling word.” A compiling word is a word that we use inside a colon definition and that actually does something during compilation of that definition.

One example is the word .”, which at compile time compiles a text string into the dictionary entry with the count in front, and at run time types it. Other examples are control-structure words like IF and LOOP, which also have compile-time behaviors distinct from their run-time behaviors. We’ll explore compiling words after we’ve discussed defining words.

How to Define a Defining Word

Here are the standard Forth defining words we’ve covered so far:

:    
VARIABLE
2VARIABLE
CONSTANT
2CONSTANT
CREATE

What do they all have in common? Each of them is used to define a set of words with similar compile-time and run-time characteristics.

And how are all these defining words defined? First we’ll answer this question metaphorically.

Let’s say you’re in the ceramic salt-shaker business. If you plan to make enough salt shakers, you’ll find it’s easiest to make a mold first. A mold will guarantee that all your shakers will be of the same design, while allowing you to make each shaker a different color. In making the mold, you must consider two things:

  • How the mold will work. (E.g., how will you get the clay into and out of the mold without breaking the mold or letting the seams show?)
  • How the shaker will work. (E.g., how many holes should there be? How much salt should it hold? Etc.

To bring this analogy back to Forth, the definition of a defining word must specify two things: the compile-time behavior and the run-time behavior for that type of word.

Hold that thought a moment while we look at the most basic of the defining words in the above list: CREATE. At compile time, CREATE takes a name from the input stream and creates a dictionary heading for it.

At run time, CREATE pushes the body address of EXAMPLE onto the stack.

What happens if we use CREATE inside a definition? Consider this example, which is the definition for VARIABLE:

: VARIABLE ( -- )   CREATE  0 , ;

When we execute VARIABLE as in

VARIABLE ORANGES

We are indirectly using CREATE to create a dictionary head with the name ORANGES and an xt that points to CREATE’s run-time code. Then we are allotting a cell for the variable itself (with “0 ,”).

Since the run-time behavior of a variable is identical to that of a word defined by CREATE, VARIABLE does not need to have run-time code of its own, it can use CREATE’s run-time code.

defining words - define a different run-time behavior with DOES

How do we specify a different run-time behavior in a defining word? By using the word DOES>, as shown here:

: DEFINING-WORD  CREATE  (compile-time operations)
DOES> (run-time operations) ;

To illustrate, the following could be a valid definition for CONSTANT (although in fact CONSTANT is usually defined in machine code):

: CONSTANT ( n -- )   CREATE  ,  DOES> @ ;

To see how this definition works, imagine we’re using it to define a constant named TROMBONES, like this:

76 CONSTANT TROMBONES

Compile-time portion:

CREATE
Create a new dictionary entry (e.g., TROMBONES)
,
Compiles the value (e.g., 76) for the constant from the stack into the constant’s parameter field.

Run-time portion:

DOES>
Marks the end of the compile-time behavior and the beginning of the run-time behavior. At run time, DOES> will leave the body address of the word being defined on the stack.
@
Fetches the contents of the constant, using the body address that will be on the stack at run time.
defining words - compile-time behaviors and run-time behaviors

The words that precede DOES> specify what the mold will do; the words that follow DOES> specify what the product of the mold will do.

DOES>
run time: ( — addr)
Used in creating a defining word; marks the end of its compile-time portion and the beginning of its run-time portion. The run-time operations are stated in higher-level Forth. At run time, the body address of the defined word will be on the stack.

Defining Words You Can Define Yourself

Here are some examples of defining words that you can create yourself.

Recall that in our discussion of “String Input Commands” in Chap. 10, we gave an example that employed character-string arrays called NAME, EYES, and ME. Every time we used one of these names, we followed it with a character count. In the input definition, we wrote

... PAD NAME 14 MOVE

and in the output definition we wrote

... NAME 14 -TRAILING TYPE ...

and so on.

Let’s eliminate the count by creating a defining word called CHARACTERS, whose product definitions will leave the address and count on the stack when executed.

We’ll use it like this: if we say

20 CHARACTERS ME

we will create an array called ME, with twenty characters available for the character string.

When we execute ME, we’ll get the address of the array and the count on the stack. Now we can write

PAD ME MOVE

instead of

PAD ME 20 MOVE

or

ME -TRAILING TYPE

instead of

ME 20 -TRAILING TYPE

Here’s how we might define CHARACTERS:

: CHARACTERS   CREATE DUP , ALLOT
DOES> ( -- addr len ) DUP CELL+ SWAP @ ;

which breaks down as follows:

CREATE
Create a new dictionary entry (e.g., ME)
DUP , ALLOT
Compiles the count (e.g., twenty) into the first cell of the array for future reference. Then allots an additional twenty bytes beyond the count for the string.
DOES>
Marks the beginning of run-time code, leaving the body address of the product-word on the stack at run time.
DUP
Copies the body address.
CELL+
Advances the address to point past the count, to the start of the character string.
SWAP @
Swaps the string address with the count address and fetches the count. The stack now holds ( addr count — ).

We have just extended our compiler! Our new word CHARACTERS is a defining word that creates a data structure and procedure that we find useful. CHARACTERS not only simplifies our input and output definitions, it also allows us to change the length of any string, should the need arise, in one place only (i.e., where we define it).

Our next example could be useful in an application where a large number of byte (not CHAR!) arrays are needed. Let’s create a defining word called STRING as follows:

: STRING   CREATE ALLOT  DOES> + ;

to be used in the form

30 STRING VALVE 

to create an array thirty bytes in length. To access any byte in this array, we merely say:

6 VALVE C@

which would give us the current setting of hydraulic valve 6 at an oil-pumping station. At run time, VALVE will add the argument 6 to the body address left by DOES>, producing the correct byte address.

If our application requires a large number of arrays to be initialized to zero, we might include the initialization in an alternate defining word called 0STRING:

: ERASED  HERE OVER  ERASE ALLOT ;
   : 0STRING  CREATE ERASED DOES> + ;

First we define ERASED to ERASE the given number of bytes, starting at HERE, before ALLOTing the given number of bytes.

Then we simply substitute ERASED for ALLOT in our new version.

By changing the definition of a defining word, you can change the characteristics of all the member words of that family. This ability makes program development much easier. For instance, you can incorporate certain kinds of error checking while you are developing the program, then eliminate them after you are sure that the program runs correctly.

Here is a version of STRING which, at run time, guarantees that the index into the array is valid:

: STRING   CREATE  DUP , ALLOT
DOES> 2DUP @ U< 0= ABORT" Range error " + CELL+ ;

which breaks down as follows:

DUP , ALLOT
Compiles the count and allots the given number of bytes.
DOES> 2DUP @
At run time, given the argument on the stack, produces
( arg addr arg count — )
U< 0=
Tests that the argument is not less than the maximum, i.e., the stored count. Because U< is an unsigned compare, negative arguments will appear as very high numbers and thus will also fail the test.
ABORT” Range error “
Check if the comparison test fails.
+ CELL+
Otherwise adds the argument to the body address, plus an additional cell to skip the count.

Here’s another way that the use of defining words can help during development. Let’s say you suddenly decide that all of the arrays you’ve defined with STRING are too large to be kept in computer memory and should be kept on disk instead. All you have to do is redefine the run-time portion of STRING. This new STRING will compute which record on the disk a given byte would be contained in, read the record into a buffer using INCLUDED, and return the address of the desired byte within the buffer. A string defined in this way could span many consecutive records (using the same technique as in Prob. 5, Chap. 10).

  c0 c1 c2 c3
r0        
r1        
r2        
r3        

You can use defining words to create all kinds of data structures. Sometimes, for instance, it’s useful to create multi-dimensional arrays. Here’s an example of a defining word which creates two-dimensional byte arrays of given size:

: ARRAY ( #rows #cols -- )   CREATE DUP , * ALLOT
DOES> ( member: row col -- addr )
ROT OVER @ * + + CELL+ ;

To create an array four bytes by four bytes, we would say

4 4 ARRAY BOARD

To access, say, the byte in row 2, column 1, we could say

2 1 BOARD C@

Here’s how our ARRAY works in general terms. Since the computer only allows us to have one-dimensional arrays, we must simulate the second dimension. While our imaginary array looks like this

  c0 c1 c2 c3
r0 0 1 2 3
r1 4 5 6 7
r2 8 9 10 11
r3 12 13 14 15

our real array looks like this

row# 0 1 2 3
offset# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

If you want the address of the byte in row 2, column 1, it can be computed by multiplying your row number (2) by the number of columns in each row (4) and then adding your column number (1), which indicates that you want the ninth byte in the real array. This calculation is what members of ARRAY must do at run time. You’ll notice that, to perform this calculation, each member word needs to know how many columns are in each row of its particular array. For this reason, ARRAY must store this value into the beginning of the array at compile time.

For the curious, here are the stack effects of the run-time portion of array:

Operation Contents of stack
row col addr
ROT col addr row
OVER @ col addr row #cols
* col addr index
+ + CELL+ addr

It is necessary to add a cell to the computed address because the first cell of the array contains the number of columns.

Our final example is the most visually exciting, if not the most useful.

: STAR  [CHAR] * EMIT ;

: .ROW CR 8 0 DO
DUP 128 AND IF STAR ELSE SPACE THEN
1 LSHIFT LOOP DROP ;

: SHAPE CREATE 8 0 DO C, LOOP
DOES> DUP 7 + DO I C@ .ROW -1 +LOOP CR ;

HEX
18 18 3C 5A 99 24 24 24 SHAPE MAN
81 42 24 18 18 24 24 81 SHAPE EQUIS
AA AA FE FE 38 38 38 FE SHAPE CASTLE
DECIMAL

.ROW prints a pattern of stars and spaces that correspond to the 8-bit number on the stack. For instance:

2 BASE !↵ ok 
00111001 .ROW↵
  ***  * ok 
DECIMAL↵ ok 

The defining word SHAPE takes eight arguments from the stack and defines a shape which, when executed, prints an 8-by-8 grid that corresponds to the eight arguments. For example:

MAN↵
   **   
   **   
  ****  
 * ** * 
*  **  *
  *  *  
  *  *  
  *  *  
ok 

In summary, defining words can be extremely powerful tools. When you create a new defining word, you extend your compiler. Traditional languages like Fortran or BASIC do not provide this flexibility because these traditional compilers and interpreters are inflexible packages that say, “Use my instruction set or forget it!”

The real power of defining words is that they can simplify your problem. Using them well, you can shorten your programming time, reduce the size of your program, and improve readability. Forth’s flexibility in this regard is so radical in comparison with traditional languages that many people don’t even believe it. Well, now you’ve seen it.

The next section introduces still another way to extend the ability of Forth’s compiler.

How to Control the Colon Compiler

Compiling words are words used inside colon definitions to do something at compile time. The most obvious examples of compiling words are control-structure words such as IF, THEN, DO, LOOP, etc. Because Forth programmers don’t often change the way these particular words work, we’re not going to study them any further. Instead we’ll examine the group of words that control the colon compiler and thus can be used to create any type of compiling word.

Recall that the colon compiler ordinarily looks up each word of a source definition and compiles each word’s address into the dictionary entry — that’s all. But the colon compiler does not compile the address of a compiling word — it executes it.

How does the colon compiler know the difference? By checking the definition’s precedence bit. If the bit is “off,” the address of the word is compiled. If the bit is “on,” the word is executed immediately; such words are called immediate words.

The word IMMEDIATE makes a word “immediate.” It is used in the form:

: name definition ; IMMEDIATE

that is, it is executed right after the compilation of the definition.

To give an immediate example, let’s define

: SAY-HELLO   ." Hello" ; IMMEDIATE 

We can execute SAY-HELLO interactively, just as we could if it were not immediate.

SAY-HELLO↵ Hello ok 

But if we put SAY-HELLO inside another definition, it will execute at compile time:

: GREET   SAY-HELLO ." I speak Forth " ;↵ Hello ok  

rather than at execution time:

GREET↵ I speak Forth ok 

Before we go on, let’s clarify our terminology. Forth folks adhere to a convention regarding the terms “run time” and “compile time.” In this example, the terms are defined relative to GREET. Thus we would say that SAY-HELLO has a “compile-time behavior” but no “run-time behavior.” Clearly, SAY-HELLO does have a run-time behavior of its own, but relative to GREET it does not.

To keep our levels straight, let’s call GREET in this example the “compilee”; that is, the definition whose compilation we’re referring to. SAY-HELLO has no run-time behavior in relation to its compilee.

Here’s an example of an immediate word that you’re familiar with: the definition of the compiling word BEGIN. It’s simpler than you might have thought:

: BEGIN HERE ; IMMEDIATE

BEGIN simply saves the address of HERE at compile time on the stack. Why? Because sooner or later an UNTIL or REPEAT is going to come along, and either has to know what address in the dictionary to return to in the event that it must repeat. This is the address that BEGIN left on the stack.

BEGIN’s compile-time behavior is leaving HERE on the stack. But BEGIN compiles nothing into the compilee; there is no run-time behavior for BEGIN.

Unlike BEGIN, most compiling words do have a run-time behavior. To have a run-time behavior, a word has to compile into the compilee the address of the run-time behavior, which must already have been defined as a word.

A good example is DO. Like BEGIN, DO must provide, at compile time, a HERE for LOOP or +LOOP to return to. But unlike BEGIN, DO also has a run-time behavior: it must push the limit and index onto the return stack.

The run-time behavior of DO is defined by a lower-level word, sometimes called (DO) or 2>R. The definition of DO is this:

: DO  POSTPONE 2>R  HERE ; IMMEDIATE

POSTPONE and run-time behavior - using defining words

The word POSTPONE finds the address of the next word in the definition (in this case 2>R) and compiles its address into the compilee definition, so that at run-time 2>R will be executed.

Another example is the definition of ;. At compile time, semicolon must do the following things:

  1. compile the address of EXIT into the dictionary entry being compiled,
  2. expose the new word to the colon compiler, and
  3. leave compilation mode.

Here’s the definition of semicolon:

: ;  POSTPONE EXIT  REVEAL  POSTPONE [ ; IMMEDIATE 

The first phrase compiles EXIT, providing the run-time behavior. The second phrase, which is the compile-time behavior, first exposes the word being compiled and then gets out of the compiler.

What is the reason for REVEAL? When words are in the process of being compiled, they are not yet findable by the colon compiler. This is done to make it possible to redefine existing words in terms of the old definition plus additional code, for example:

: CR  CR SPACE ;

If during the compilation of the new CR its name were findable, the name of the original CR would be blocked, and we would have had to do, e.g.:

: _cr_  CR ;    
: CR _cr_ SPACE ;

The word POSTPONE can also be used to compile an immediate word as though it were not immediate. Given our previous example, in which SAY-HELLO is an immediate definition, we might define

: GREET   POSTPONE SAY-HELLO  ." I speak Forth " ;↵ ok  

to force SAY-HELLO to be compiled rather than executed at compile time. Thus:

GREET↵ Hello I speak Forth ok 

Be sure to note the “intelligence” built into POSTPONE. POSTPONE parses the next word in the input stream, decides if it is immediate or not, and proceeds accordingly. If the word was not immediate, POSTPONE compiles the address of the word into a compiled definition; think of it as deferred compilation. If the word is immediate, POSTPONE compiles the address of this word into the definition currently being defined; this is ordinary compilation, but of an immediate word which otherwise would have been executed.

To review, here are the two words which are useful in creating new compiling words:

IMMEDIATE
( — )
Marks the most recently defined word as one which, when encountered during compilation, will be executed rather than being compiled.
POSTPONE xxx
( — )
  1. Used in the definition of a compiling word. When the compiling word, in turn, is used in a source definition, the execution token of xxx will be compiled into the dictionary entry so that when the new definition is executed, xxx will be executed.
  2. Used in a colon definition, causes the immediate word xxx to be compiled as though it were not immediate; xxx will be executed when the definition is executed.

More Compiler-Controlling Words

There are two other compiler control words you should know. The words [ and ] can be used inside a colon definition to stop compilation and start it again, respectively. Whatever words appear between them will be executed “immediately”, i.e., at compile time.

Consider this example:

: SAY-HELLO  ." Hello " ;
: GREET  [ SAY-HELLO ] ." I speak Forth " ;↵ Hello ok 

GREET↵ I speak Forth ok 

In this example, SAY-HELLO is not an immediate word, yet when we compile GREET, SAY-HELLO executes “immediately.”

For a better example we first need to introduce the word LITERAL.

As you may recall, a number that appears in a colon definition is called a “literal.” An example is the “4” in the definition

: FOUR-MORE  4 + ;

using literal values in colon definitions - LITERAL

The use of a literal in a colon definition requires two cells. The first contains the execution token of a routine which, when executed, will push the contents of the second cell (the number itself) onto the stack.

The name of this routine may vary; let’s call it the “run-time code for a literal,” or simply (LITERAL). When the colon compiler encounters a number, it first compiles the run-time code for a literal, then compiles the number itself.

The word you will use most often to compile a literal is LITERAL (no parentheses). LITERAL compiles both the run-time code and the value itself. To illustrate:

: FOUR-MORE  [ 4 ] LITERAL + ;

Here the word LITERAL will compile as a literal the “4” that we put on the stack between the square brackets. We get a dictionary entry that is identical to the one shown above.

Now we know all there is to know about LITERAL, we can also give a better example of [ and ]. Imagine a colon definition in which we need to type the byte from row 2, column 3, of the array BOARD we defined in the previous section. To get the address of this byte, we could use the phrase

BOARD  2 8 ( #cols) * 3 +  CELL+  +

but it’s time consuming to execute

2 8 * 3 +

every time we use this definition. Alternatively, we could write

BOARD  19 CELL+ +

compile-time arithmetic specified with [ and ] (left bracket and right bracket)

but it’s unclear to human readers exactly what 19 means, and it is irritating that, for portability, we still have to write CELL+ although 1 CELLS is just a constant.

The best solution is to write

BOARD [ 2 8 ( #cols) * 3 +  CELL+ ] LITERAL +

Here the arithmetic is performed only once, at compile time, and the result is compiled as a literal.

Here’s a silly example which may give you some ideas for more practical applications. This definition let’s you peek into the innards of the word itself:

: DUMP-THIS   [ HERE ] LITERAL  32 DUMP ." DUMP-THIS" ; 
HERE points to the address of the next free code byte

When you execute DUMP-THIS, you will dump the memory into which DUMP-THIS was defined. You should see how your Forth compiles the literal value of “here,” the literal “32,” the execution token of DUMP, and then how it inlines the string “DUMP-THIS.” (At compile-time, HERE points to the address of the next free code byte. LITERAL compiles this number into the definition as a literal, so that it will serve as the argument for DUMP at run-time.)

By the way, here’s the definition of LITERAL:

: LITERAL  POSTPONE (LITERAL) , ; IMMEDIATE

First it compiles the address of the run-time code, then it compiles the value itself (using comma).

LITERAL
compile: ( n — ) run: ( — n )
Used only inside a colon definition. At compile time, compiles a value from the stack into the definition as a literal. At run time, the value will be pushed on the stack.
[
( — )
Leaves compilation mode.
]
( — )
Enters compilation mode.
Forth text interpreter and code compiler

Curtain Calls

This section gives us a chance to say “Goodbye” to the text interpreter and the colon compiler and perhaps to see them in a new light.

Here is a definition of INTERPRET that will work in most Forth systems:

: INTERPRET ( -- )
BEGIN
BL FIND IF EXECUTE
?STACK ABORT" Stack empty"
ELSE NUMBER THEN
AGAIN ;

We’ve covered each of the words contained in this definition; we can describe INTERPRET in English by simply “translating” its definition, like this:

Begin a loop. Within the loop, try to look up the next word from the input stream. If it’s not defined, try to convert it to a number. If it is defined, execute it, then check to see whether the stack is empty. (If it is, exit the loop and print “STACK EMPTY.”) Then repeat the infinite loop.

As you can see, the Forth text interpreter is a simple yet powerful structure. Now let’s compare its structure with that of the colon compiler:

: ] ( -- )
BEGIN
BL FIND DUP IF
-1 = IF EXECUTE ?STACK ABORT" Stack empty"
ELSE , THEN
ELSE DROP (NUMBER) POSTPONE LITERAL THEN
AGAIN ;

The first thing you probably noticed is that the name of the colon compiler is not :, but ]. The definition of : invokes ] after creating the dictionary head and performing a few other odd jobs.

The next thing you may have noticed is that the compiler is somewhat similar to the interpreter. Let’s translate the definition into English:

  • Begin a loop. Within the loop, try to look up the next word from the input stream. If it’s not defined, try to convert it to a number and, if it’s a number, compile it as a literal.
  • If it is defined, FIND has tested the word’s precedence bit. If the word is immediate, then execute it and check to see whether the stack is empty. If it is not immediate, FIND returned an execution token that can be compiled. Then repeat the infinite loop.

Compare this to INTERPRET and you’ll see that ] could be called an interpreter with the ability to decide whether to execute or compile any given word. It is the simplicity of this design that let’s you add new compiling words so easily.

In summary, we’ve shown two ways to extend the Forth compiler:

  1. Add new, specialized compilers, by creating new defining words.
  2. Extend the existing colon compiler by creating new compiling words.

While traditional compilers try to be universal tools, the Forth compiler is a collection of separate, simple tools … with room for more.

Which approach seems more useful:

ways of extending Forth compilers

Chapter Summary

Forth Words

Here’s a glossary of words covered in this chapter:

DOES>
run time: ( — addr)
Used in creating a defining word; marks the end of its compile-time portion and the beginning of its run-time portion. The run-time operations are stated in higher-level Forth. At run time, the body address of the defined word will be on the stack.
IMMEDIATE
( — )
Marks the most recently defined word as one which, when encountered during compilation, will be executed rather than being compiled.
POSTPONE xxx
( — )
  1. Used in the definition of a compiling word. When the compiling word, in turn, is used in a source definition, the execution token of xxx will be compiled into the dictionary entry so that when the new definition is executed, xxx will be executed.
  2. Used in a colon definition, causes the immediate word xxx to be compiled as though it were not immediate; xxx will be executed when the definition is executed.
LITERAL
compile: ( n — ) run: ( — n )
Used only inside a colon definition. At compile time, compiles a value from the stack into the definition as a literal. At run time, the value will be pushed on the stack.
[
( — )
Leaves compilation mode.
]
( — )
Enters compilation mode.

Review of Terms

Compile-time behavior
1. when referring to defining words: the sequence of instructions which will be carried out when the defining word is executed — these instructions perform the compilation of the member words;
2. when referring to compiling words: the behavior of a compiling word, contained within a colon definition, during compilation of the definition.
Compilee
a definition being compiled. In relation to a compiling word, the compilee is the definition whose compilation the compiling word affects.
Compiling word
a word used inside a colon definition to take some action during the compilation process.
Defining word
a word which, when executed, compiles a new dictionary entry. A defining word specifies the compile-time and run-time behavior of each member of the “family” of words that it defines.
Precedence bit
In Forth dictionary entries, a bit which indicates whether a word should be executed rather than be compiled when it is encountered during compilation.
Run-time behavior
1. when referring to defining words: the sequence of instructions which will be carried out when any member is executed;
2. when referring to compiling words: a routine which will be executed when the compilee is executed. Not all compiling words have run-time behavior.
Forth programming language - examples

Problems … Chapter 11

  1. Define a defining word named LOADED-BY that will define words which include a file when they are executed. Example:
    S" mail.forth" LOADED-BY CORRESPONDENCE
    

    would define the word CORRESPONDENCE. When CORRESPONDENCE is executed, the file mail.forth is included.

  2. Define a defining word BASED that will create number output words for specific bases. For example,
    16 BASED H.
    

    would define H. to be a word that prints the top of the stack in hex but does not permanently change BASE.

    >DECIMAL
    17 DUP H. .↵ 11 17 ok
    
  3. Define a defining word called PLURAL that will take the address of a word such as CR or STAR and create its plural form, such as CRS or STARS. You’ll provide PLURAL with the execution token of the singular word by using tick. For instance, the phrase
    ' CR PLURAL CRS
    

    will define CRS in the same way as though you had defined it

    : CRS ( times -- )  0 DO  CR  LOOP ;
    
  4. Suppose the French words for DO and LOOP are TOURNE and RETOURNE. Using the words DO and LOOP, define TOURNE and RETOURNE as French “aliases.” Now test them by writing yourself a French loop.
  5. Write a word called LOOPS that will cause the remainder of the input stream, up to the carriage return, to be executed the number of times specified by the value on the stack. For example,
    7 LOOPS CHAR * EMIT SPACE↵ * * * * * * * ok
    
Answers

  1. : LOADED-BY ( addr len -- ) 
       CREATE  HERE 2 CELLS + , ( addr) DUP ( count) , 
       >R  HERE R@ MOVE  ( get string)
       R> ALLOT ( make room for it)
       DOES> 2@ SWAP INCLUDED ;
    
  2. : BASED ( compile: new_base -- ) ( run: n -- ) 
       CREATE ,  DOES> @ ( new_base )    
       BASE @ >R ( save old BASE )
       BASE !  .
       R> BASE ! ; ( restore BASE )
    
  3. : PLURAL  ( compile: xt -- ) ( run: #times -- )
       CREATE  ,
       DOES>  @  SWAP ?DUP IF  0 DO  DUP EXECUTE  LOOP THEN DROP ;
    
  4. : TOURNE   POSTPONE DO ; IMMEDIATE
    : RETOURNE   POSTPONE LOOP ; IMMEDIATE
    : TRY   10 0 TOURNE  I .  RETOURNE ;
    
  5. : LOOPS ( n -- )   >IN @  SWAP 0 DO  DUP >IN !  INTERPRET  LOOP DROP ;
    

Понравилась статья? Поделить с друзьями:
  • How to change pages to word
  • How to change page orientation in word for one page
  • How to change one word in word for another
  • How to change numbering in word
  • How to change margins in word