Friday, May 31, 2002
1. Instance methods maintain. . .
Blank X Answer (B): A separate value for the state information for each class instance is maintained.
2. The following piece of code includes a class variable and an instance method:
public class Counter {
int count;
void incrementCount() {
count++;
}
int getCount() {
return count;
}
}
Blank X Answer (B): False. The ClassCounter class contains only instance variables and methods.
3. To create a class level constant, use the following two keywords together:
Blank X Answer (C): Use these two keywords to create a constant: final and static
4. Call static methods
Blank X Answer (A): Call static methods with a class identifier.
5. What results would print from the following code snippet:
System.out.println("12345 ".valueOf(54321));
Blank X Answer (C): Since valueOf is a static method, the actual value of the calling String is ignored, and the method just works on the argument, and the result is 54321.
You missed 5 questions.
Your score is 0 percent. Consider reading the May supplement again for a better understanding of static and instance members.
May Mini Quiz
New to JavaTM Pogramming Center
Java Platform Overview | Getting Started | Step-by-Step Programming
Learning Paths | References & Resources | Certification | Newsletters
The May issue of the JavaTM Technology Fundamentals covered static and instance variables and methods: what they are and how to use them. Test what you learned by answering the questions below.
--------------------------------------------------------------------------------
Instance methods maintain. . .
A. one copy of the variable for each class instance
B. a separate value for the state information for each class instance.
C. A constant state of the variable for each class instance.
D. None of the above.
The following piece of code includes a class variable and an instance method:
public class Counter {
int count;
void incrementCount() {
count++;
}
int getCount() {
return count;
}
}
A. True
B. False
To create a class level constant, use the following two keywords together:
A. public and constant.
B. final and constant
C. final and static
Call static methods
A. with the class identifier.
B. with a new instance of the class.
C. None of the above.
What results would print from the following code snippet:
System.out.println("12345 ".valueOf(54321));
A. The application won't compile.
B. 12345 54321
c. 54321
Wednesday, May 29, 2002
In philosophy, know how ascriptions cover abilities ranging from simple motor skills (knowing how to walk or how to ride a bicycle) to abstract highly contemplative cases (such as knowing how to prove Fermat's Last Theorem).
Historically, Gilbert Ryle brought the notion of know how to the forefront of philosophical thought in epistemology and philosophy of mind. In his book, The Concept of Mind, Ryle claimed that all human behavior relevant to psychology could be explained exclusively in terms of know how. Ryle offered a dispositional account of knowledge how, which is now widely discredited. In Ryle's own words:
In judging that someone's performance is or is not intelligent, we have,...in a certain manner to look beyond the performance itself. For there is no particular overt or inner performance which could not have been accidentally or 'mechanically' executed by an idiot, a sleepwalker, a man in a panic, absence of mind or delirium or even, sometimes, by a parrot. ...in looking beyond the performance itself,.... We are considering his abilities and propensities of which his performance was an actualization. Our inquiry is not into causes (and a fortiori not into occult causes), but into capacities,.... (Ryle 1949, p.45)
One can find four general criticisms of Ryle's view in the literature. First, commentators often criticize Ryle's view because it is dispositional. A dispositional analysis holds that one is disposed to behave in a certain way in the specified conditions. As with dispositional accounts generally, it is difficult, even impossible to specify non-trivial conditions under which one manifests one's dispositions. If one analyzes knowing how to play chess in terms of dispositions to move chess pieces, one must specify the conditions under which a player manifests those dispositions. Such specifications are difficult since a person's reaction to a chess board and an invitation to play is subject to all manner of physical and psychological preconditions. If the person has been injected with curare, they will likely not react. If they believe themselves to be overmatched, they may demur. A second criticism of Ryle's view is that many cases of ostensive know how seem to involve explicit, conscious knowledge of procedural rules. For example, in exercising one's cake- baking know how, one may well explicitly follow a remembered recipe. Still a third criticism claims that dispositions are superfluous in explaining behavior in that they are merely restatements of the facts to be explained. In this way they are like Moliere's famous satirical explanation of opium's ability to put people to sleep by noting that opium has a dormative virtue (virtus dormitiva). Finally, critics of Ryle note that dispositions, being always potentially active, cannot explain know how in the absence of ability. An arthritic piano player can be said to know how to play the piano without being capable of manifesting the ability to play as required by Ryle's account. The most pervasive response to Ryle's position analyzes know how in terms of conscious, explicit representations of procedural knowledge. Know how remains distinct from propositional knowledge (knowledge that). However, know how, like knowledge that, is construed as explicitly, conscious represented knowledge. David Carr's work (1981) is typical of this approach to know how:
...knowing how in the strong sense to play football is knowing the rules of the game, but a statement of the rules of the game is not a theoretical statement but a description of a set of rules of practice, and mastery of the rules brings with it an understanding of an activity rather than a theory. Statements of the rules of a game are essentially of relations between prescriptions rather than descriptions requiring a grasp of practical rather than theoretical discourse. (Carr 1981, pp.60-1)
One might criticize the above view because, just as some ascriptions of know how seem to involve explicit representations of procedural rules, some ascriptions of know how, like one's ability to walk or ride a bicycle, seem to involve abilities that are not plausibly explained by explicit, conscious representation of procedural rules. In psychology and cognitive science, researchers often equate the 'know how/know that' distinction with the procedural/declarative knowledge distinction. This usage is not consistent with the usage in philosophy. Declarative knowledge is generally characterized as knowledge which can be expressed by a cognizer and which is propositional in nature. While philosophers agree that know how is not propositional in that it is properly understood as true or false, they do not assert that it is inexpressible. Likewise, procedural knowledge is generally held to be a restricted to motor skills in cognitive psychology, whereas philosophers favor a wider applicability for know how, including contemplative activities.
Charles Wallis
The end of the dialectic of modernity has not resulted in the end of the dialectic of exploitation.
Imperialism was really an extension of the sovereignty of the European nation-states beyond their own boundaries.
In contrast to imperialism, Empire establishes no territorial center of power and does not rely on fixed boundaries or barriers. It is a decentered and deterritorializing apparatus of rule that progressively incorporates the entire global realm within its open, expanding frontiers. Empire manages hybrid identities, flexible hierarchies, and plural exchanges through modulating networks of command. The distinct national colors of the imperialist map of the world have merged and blended in the imperial global rainbow. The transformation of the modern imperialist geography of the globe and the realization of the world market signal a passage within the capitalist mode of production. Most significant, the spatial divisions of the three Worlds (First, Second, and Third) have been scrambled so that we continually find the First World in the Third, the Third in the First, and the Second almost nowhere at all. Capital seems to be faced with a smooth world-or really, a world defined by new and complex regimes of differentiation and homogenization, deterritorialization and reterritorialization. The construction of the paths and limits of these new global flows has been accompanied by a transformation of the dominant productive processes themselves, with the result that the role of industrial factory labor has been reduced and priority given instead to communicative, cooperative, and affective labor. In the postmodernization of the global economy, the creation of wealth tends ever more toward what we will call biopolitical production, the production of social life itself, in which the economic, the political, and the cultural increasingly overlap and invest one another.
Many locate the ultimate authority that rules over the processes of globalization and the new world order in the United States. Proponents praise the United States as the world leader and sole superpower, and detractors denounce it as an imperialist oppressor. Both these views rest on the assumption that the United States has simply donned the mantle of global power that the European nations have now let fall. If the nineteenth century was a British century, then the twentieth century has been an American century; or really, if modernity was European, then postmodernity is American. The most damning charge critics can level, then, is that the United States is repeating the practices of old European imperialists, while proponents celebrate the United States as a more efficient and more benevolent world leader, getting right what the Europeans got wrong. Our basic hypothesis, however, that a new imperial form of sovereignty has emerged, contradicts both these views. The United States does not, and indeed no nation-state can today, form the center of an imperialist project. Imperialism is over. No nation will be world leader in the way modern European nations were.
The United States does indeed occupy a privileged position in Empire, but this privilege derives not from its similarities to the old European imperialist powers, but from its differences. These differences can be recognized most clearly by focusing on the properly imperial (not imperialist) foundations of the United States constitution, where by "constitution" we mean both the formal constitution, the written document along with its various amendments and legal apparatuses, and the material constitution, that is, the continuous formation and re-formation of the composition of social forces. Thomas Jefferson, the authors of the Federalist, and the other ideological founders of the United States were all inspired by the ancient imperial model; they believed they were creating on the other side of the Atlantic a new Empire with open, expanding frontiers, where power would be effectively distributed in networks. This imperial idea has survived and matured throughout the history of the United States constitution and has emerged now on a global scale in its fully realized form.
Empire not only manages a territory and a population but also creates the very world it inhabits. It not only regulates human interactions but also seeks directly to rule over human nature. The object of its rule is social life in its entirety, and thus Empire presents the paradigmatic form of biopower
The creative forces of the multitude that sustain Empire are also capable of autonomously constructing a counter-Empire, an alternative political organization of global flows and exchanges.
Whereas the genealogy of Empire is in this sense Eurocentric, however, its present powers are not limited to any region. Logics of rule that in some sense originated in Europe and the United States now invest practices of domination throughout the globe. More important, the forces that contest Empire and effectively prefigure an alternative global society are themselves not limited to any geographical region. The geography of these alternative powers, the new cartography, is still waiting to be written-or really, it is being written today through the resistances, struggles, and desires of the multitude
abduction
A method of reasoning by which one infers to the best explanation. See induction, deduction.
Chris Eliasmith
action
That which we do, in contrast to that which merely happens to us or our parts.
Chris Eliasmith
analogy
A systematic comparison between structures that uses properties of and relations between objects of a source structure to infer properties of and relations between objects of a target structure.
< References> Paul Thagard
anomalous monism
The view put forward by Donald Davidson that all mental events are identical to physical events, and that the only laws that govern the relations between events are physical, not psychological, laws. See monism, supervenience, token identity thesis, physicalism.
Pete Mandik
artificial intelligence
The science of making machines do things that would require intelligence if done by [people] (Minsky, 1968). See connectionism, symbolicism.
Chris Eliasmith
aspectual shape
Similar to the notion of sense. Introduced by Searle (1992).
Chris Eliasmith
background, the
A set of nonrepresentational capacities that enable all representing to take place. The Background includes biological and cultural capacities, skills, stances, assumptions and presuppositions. Introduced in Searle (1978). See also intentionality, intention-in-action, implicit memory, tacit knowledge.
Daniel Barbiero
behaviorism
The theory according to which mental states can be analyzed in terms of observable behavior or dispositions to engage in such behavior.
Jesse Prinz
causal functionalism
The view that a physical system realizes a mental state not in virtue of the particular stuff it is made of but instead in virtue of the causal relations that parts of that system bear to each other. See functionalism(1), functionalism(2).
Pete Mandik
Cartesian skepticism
Any of a class of skeptical views against empirical knowledge based on the claim that claims to empirical knowledge are defeated by the possibility that we might be deceived insofar as we might be, for example, dreaming, hallucinating, deceived by demons, or brains in vats.
Pete Mandik
Chinese
Room
An argument forwarded by John Searle intended to show that the mind is not a computer and how the Turing Test is inadequate.
Chris Eliasmith
cognitive
science
Cognitive science is the interdisciplinary study which attempts to further our understanding of the nature of thought.
William Willaford
cognize
To have access to knowledge that has the properties of knowledge in the ordinary sense, but is not necessarily accessible to consciousness or dependent on warrant or justification. Introduced in Chomsky (1980). See also knowledge, tacit knowledge, implicit memory, rules.
Daniel Barbiero
coherence
A relation among a number of elements, such as propositions or concepts, that fit together well: consistency; cohesiveness.
See practical reasoning for an example.
< References> Paul Thagard
color, theories of
Theories of color make proposals about the nature of the colors that we attribute to physical objects in visual perception. The most common proposals are that these colors are mental properties of perceptual states (subjectivism), they are physical properties of physical objects (physicalism), or they are dispositions of physical objects to produce perceptual states of color (dispositionalism). See theories of color perception.
< References> Peter Ross
color perception, theories of
Theories of color perception propose to explain how it is that colors are perceived as properties of physical objects. What proposal one makes depends in turn on what proposal one makes about the nature of color. See theories of color.
< References> Peter Ross
compositionality
Representations may be said to be compositional insofar as they retain the same meaning across diverse contexts. Thus, "kick" means the same thing in the context of "-the ball", "- a rock", and "- a dog", although it changes meaning in the context of "- the bucket". One might say that according to the principle of the compositionality of representations atomic representations make the same semantic contribution in every context in which they occur. See systematicity, productivity, symbolicism.
< References> Ken Aizawa
computation
A series of rule governed state transitions whose rules can be altered.
Chris Eliasmith
computation
The structure and organization of a given computing device (the way in which it handles memory, the organization of date, the set of primitive instructions it executes, and the ordering of instruction application or execution) define a device's computational architecture. Computational architecture involves only the structure and organization relevant to computation; implementational details to not constitute computational architecture. See also computation, functionalism.
< References> Ken Aizawa
computational models
Models based on the overarching hypothesis that the mind is a type of computer which can be described in algorithmic terms.
Chris Eliasmith
concept
A semantically evaluable, redeployable constituent of thought, invoked to explain properties of intentional phenomena such as productivity and systematicity. Applied to an assortment of phenomena including mental representations, images, words, stereotypes, senses, properties, reasoning abilities, mathematical functions, etc. See nonconceptual content.
Chris Eliasmith & Pete Mandik
conceptual role semantics
see semantics, functional role.
connectionism
A computational approach to modeling the brain which relies on the interconnection of many simple units to produce complex behavior. See also history of connectionism, symbolicism, dynamical systems theory.
Chris Eliasmith
connectionism, history of
Construed broadly, connectionism maintains that cognitive processes are (implemented in) processes taking place in networks of nerve cells. Thus construed, the history of connectionism spans a wide range of research in numerous disciplines over the course of centuries. See connectionism, symbolicism.
Ken Aizawa
consciousness
Self-awareness. Subjective experience. The way things seem to us. Immediate phenomenological properties.
Chris Eliasmith
consciousness, phenomenal
Phenomenal consciousness [p-consciousness] is just experience thus, p-conscious states are experiential states. The totality of the experiential properties of a state are p-consciousness, i.e. "what it is like" to have it.
A. Khwaja
consciousness, access
Access consciousness [a-consciousness] is a kind of direct control; a representation is access-conscious if it is poised to be under direct control of reasoning, reporting and action.
A. Khwaja
creativity
Creativity is an acid test for AI and cognitive science. If computers cannot be creative, then (a) they cannot be intelligent, and (b) people are not machines. However, the standard arguments against machine intelligence are not convincing.
Terry Dartnall
deduction
A method of reasoning by which one infers a conclusion from a set of sentences by employing the axioms and rules of inference for a given logical system. See abduction, induction.
Chris Eliasmith
design stance
See intentional stance
Amy Kind
desire, second-order
Desire about desires. That is, desire of the form 'I want x' where x is a desire.
Chris Eliasmith
distributed representation
See representation, distributed.
doxastic
Pertaining to belief. Alternatively, also pertaining to states sufficiently like beliefs (thoughts, judgments, opinions, desires, wishes, fears).
Pete Mandik
dual-aspect theory
A view forwarded by Spinoza (also called the dual-attribute theory) in which the unitary substance God is expressed in the distinct modes of the mental and the physical. See dualism.
Chris Eliasmith
dualism
Most generally, the view that reality consists of two disparate parts. In philosophy of mind, the belief that the mental and physical are deeply different in kind: thus the mental is at least not identical with the physical. See occasionalism, doctrine of preestablished harmony, substance dualism, property dualism, Cartesian interactionist dualism, mind-body problem, monism.
Chris Eliasmith
dualism, Cartesian interactionist
The view that: (1) the mental and the material comprise two different classes of substance and; (2) both can have causal effects on the other. See dualism.
Pete Mandik
dynamical systems theory
An area of mathematics used to describe the behavior of complex systems by employing differential and difference equations. Recently this approach has been advanced by some as the best way to describe human cognition. See also symbolicism, connectionism.
Chris Eliasmith
eliminativism
The view that, because mental states and properties are items posited by a protoscientific theory (called folk psychology), the science of the future is likely to conclude that entities such as beliefs, desires, and sensations do not exist. The alternate most often offered is physicalist and the position is thus often called 'eliminative materialism'.
Teed Rockwell
emergence
Properties of a complex physical system are emergent just in case they are neither (i) properties had by any parts of the system taken in isolation nor (ii) resultant of a mere summation of properties of parts of the system.
Pete Mandik
empiricism
In its strong form, the thesis that there is no reality behind appearances. Thus, it is the job of science to catalog the formal relations which hold between appearances without claims of describing reality. See phenomenalism
Chris Eliasmith
epiphenomenalism
The doctrine that mental phenomena are not causal despite the fact they may seem to be.
Chris Eliasmith
epistemology
A major branch of philosophy that concerns the forms, nature, and preconditions of knowledge.
Pete Mandik
equivalence thesis
The equivalence thesis states that for any proposed notion of truth, each instance of the schema "S is true if and only if P" resulting from the substitution of a translation of the sentence designated by S for P, is true. This thesis is often taken to be a minimal requirement on any notion of truth.
Whit Schonbein
Evans, Gareth
Philosopher of language and mind, best known for introducing, in his posthumously published The Varieties of Reference, the Generality Constraint, as well as the notion of nonconceptual content as parts of an account of singular referring demonstrative thought.
Rick Grush & Pete Mandik
explanation
A structure, act, or process that provides understanding.
< References> Paul Thagard
explicit memory
Those memories which a subject is able to cite as being a memory of a particular event. See also implicit memory, memory.
Chris Eliasmith
externalism
Externalists hold that there are mental events that do not supervene merely on physical events internal to the agent's body, but supervene on environmental events as well. Also known as anti-individualism.
Pete Mandik
folk psychology
The common-sense conceptual framework that we, as human beings, employ to understand, predict, and explain the behavior of other humans and higher animals.
Chris Eliasmith
functional role semantics
See semantics, functional role.
functionalism(1)
The view that the physical realization of a functional component is not, in some sense, its essence. Rather, what makes a functional component the type it is, is characterized in terms of its role in relating inputs to outputs and its relations to other functional components. See multiple realizability, Turing machine, functionalism(2), causal functionalism.
Chris Eliasmith
functionalism(2)
An explanatory approach to behavior and the constitution of cognitive states that regards particular behaviors and cognitive structures and capacities as playing functional roles in particular domains or contexts. See also functionalism(1), causal functionalism, explanation.
Daniel Barbiero
generality constraint
Constraint on concept possession (and hence on the ability to entertain genuine thoughts) to the effect that a subject has the concept C only if the set of thoughts the subject is able to entertain is closed under recombination of C with all other semantically and categorically appropriate concepts that the subject possesses.
Rick Grush & Pete Mandik
Gettier Problem
A type of counter example to the definition of knowledge as justified true belief.
Chris Eliasmith
GOFAI
Good Old-Fashioned Artificial Intelligence. See symbolicism, artificial intelligence.
; PI (Processes of Induction) LISP code. October, 2001
; See P. Thagard, Computational Philosophy of Science, 1988.
; Here are all the files needed to run PI. The first function
; is a patch needed to convert from Sun Common LISP to
; universal Common LISP. If you encounter problems,
; email pthagard@uwaterloo.ca.
; CONCAT combines any number of atoms into a long atom.
(defun concat (&rest concat-things)
(read-from-string (coerce (apply #'append
(mapcar #'atom-to-list
concat-things
)
)
'string
)
)
)
; FILE: ana_schem.l
; PURPOSE: analogical schema formation in PI
; PROGRAMMER: Paul Thagard
; CREATED: 1-30-86
; UPDATED: 1-14-87
; ******************************************
; SCHEM_ALL is called by solve_problem when a problem solution has
; been achieved using an analogous concept solution.
; old_anas is a list of triples: base target analogous_concepts.
(defun schem_all (prob_name old_anas)
(prog (triples)
(setq triples old_anas)
loop
(cond ( (null triples) (return t)))
(schematize (caar triples) prob_name (third (car triples)))
(setq triples (cdr triples))
(go loop)
)
)
; ******************************************
; SCHEMATIZE creates a
; new, abstract concept solution. The structure ana is a list of
; pairs of analogous concepts, set up by analogize in analog.l.
; For globals, see below.
(defun schematize (prob1 prob2 ana)
(let (schem )
(setq schema (concat prob1 '/ prob2))
; set up variables for assign_vbls:
(setq assoc_vbls nil)
(setq avail_vbls vbl_list)
; set up goals, start, and solution key for schema:
(put schema 'goals (abstract_list (get prob1 'goals)
(get prob2 'goals)
ana
)
)
(put schema 'start (abstract_list (get prob1 'start)
(get prob2 'start)
ana
)
)
(cond ( (get prob1 'explan_status) ; explanation problem
(put schema 'abductions
(abstract_list (get prob1 'abductions)
(get prob2 'abductions)
ana
)
)
)
( t (put schema 'effects_objs ; ordinary problem
(abstract_list (get prob1 'effects_objs)
(get prob2 'effects_objs)
ana
)
)
)
)
; schematize analogous rules for problem solving:
(schem_rules prob1 prob2 ana schema)
; associate schema with relevant concepts:
(setq schema_concs
(conc_from_prob schema)
)
(put schema 'attached_concepts schema_concs)
(store_solution schema schema_concs)
(setq all_problems (cons schema all_problems))
(cond ( trace_data
(my_print '"Analogical schema produced: " schema)
)
)
)
)
; **************************************************************
; STORE_SOLUTION associates concepts with schematic solutions.
(defun store_solution (prob concepts)
(cond ( (null concepts) nil)
(t (put (car concepts) 'old_solutions
(cons prob (get (car concepts) 'old_solutions) )
)
(store_solution prob (cdr concepts) )
)
)
)
; ****************************************************************
; ABSTRACT_LIST builds a list of abstract messages out of two lists
; of concrete messages and an already established analogy.
(defun abstract_list (mess_lst1 mess_lst2 ana)
(prog (mlst1 mlst2 result first_mess)
(setq mlst1 mess_lst1)
(setq mlst2 mess_lst2)
(setq result nil)
loop1
(cond ( (null mlst1)
(return (union (intersection mess_lst1 mess_lst2)
(remove nil result)
)
)
)
)
(setq mlst2 mess_lst2)
; check the first message against all messages in 2nd list
loop2
(cond ( (null mlst2)
(setq mlst1 (cdr mlst1))
(go loop1)
)
)
(setq result (union (abstract_mess (car mlst1) (car mlst2) ana )
result
)
)
(setq mlst2 (cdr mlst2))
(go loop2)
)
)
; ********************************************************
; ABSTRACT_MESS forms an abstraction from two messages, returning
; nil if nothing interesting results.
; Global variable: abstrns.
;
(defun abstract_mess (mess1 mess2 ana)
(cond ( (and (truth_compatible mess1 mess2)
(equal (length (second mess1)) (length (second mess2)))
(analogous (car mess1) (car mess2) ana)
(setq abstrns (related? mess1 mess2) )
)
(prog (abs result)
(setq result nil)
(setq abs abstrns)
loop
(cond ( (null abs) (return result)))
(setq result
(cons (list (car abs)
(assign_vbls (second mess1) (second mess2))
(de_project_val (third mess1))
(cond ( (equal (fourth mess1)
(fourth mess2)
)
(fourth mess1)
)
)
)
result
)
)
(setq abs (cdr abs))
(go loop)
)
)
(t nil)
)
)
; ***********************************************************
; ANALOGOUS checks to see whether two concepts have been determined
; to be related in a given analogy.
(defun analogous (conc1 conc2 ana)
(or (equal conc1 conc2)
(memberlist (list conc1 conc2) ana)
(memberlist (list conc2 conc1) ana)
)
)
; ************************************************************
; RELATED? checks whether two messages are abstractible, i.e. share a
; more abstract concept drawn from the originals.
; Identical concepts require no further abstraction.
; It first tries to
; abstract the concepts, then tries the objects.
; Returns a set of abstracted concepts.
(defun related? (mess1 mess2)
(cond ( (equal (car mess1) (car mess2)) (list (car mess1)))
(t (or (abstract_conc (car mess1) (car mess2) )
(abstract_objs (second mess1) (second mess2))
)
)
)
)
; *************************************************************
; ABSTRACT_CONC finds an abstraction from two concepts based on their
; rules. If A --> C, and B --> C, then C is an abstraction of both
; A and B. E.g. animal is an abstraction of cats and dogs, because
; all cats and dogs are animals. Obviously, there can be more than
; one abstraction.
; More thoroughly, we could do a search up the default
; hierarchy, so that if A --> D --> C, and B --> E --> C, then C
; would be an abstraction. This would be done implicitly by
; abstract_objs, since rule firing would have led to the
; conclusions that follow.
(defun abstract_conc (conc1 conc2)
(intersect (possible_abstrns conc1)
(possible_abstrns conc2)
)
)
; **************************************************************
; POSSIBLE_ABSTRNS looks through the rules attached to a concept C
; for simple ones of the form C --> A, returning A as a possible
; abstraction.
(defun possible_abstrns (conc)
(prog (rules result )
(setq rules (get conc 'rules))
(setq result nil)
loop
(cond ( (null rules) (return result) ) )
(cond ( (and (equal (length (get (car rules) 'conditions)) 1)
(equal (caar (get (car rules) 'conditions)) conc)
)
(setq result
(cons (caar (get (car rules) 'actions)) result)
)
)
)
(setq rules (cdr rules))
(go loop)
)
)
; ***********************************************************
; ABSTRACT_OBJS finds some abstract property of two objects.
; Won't work until objects are upgraded in begin.l and prob_fire.l.
(defun abstract_objs (obj_lst1 obj_lst2)
(cond ( (or (greaterp (length obj_lst1) 1)
(greaterp (length obj_lst2) 1)
)
nil
)
( t (common_properties (car obj_lst1) (car obj_lst2)) )
)
)
; **************************************************************
; COMMON_PROPERTIES returns the properties that two objects have
; in common. Need to add proper definition of objects in begin.l
; and updating of objects by prob_fire.l.
(defun common_properties (obj1 obj2)
(intersect (concepts_from (unary_preds (get obj1 'messages)))
(concepts_from (unary_preds (get obj2 'messages)))
)
)
; **************************************************************
; UNARY_PREDS returns a list of only 1-place predicates from a list
; of messages.
(defun unary_preds (mess_list)
(prog (mess_lst result)
(setq mess_lst mess_list)
(setq result nil)
loop
(cond ( (null mess_list) (return result) ))
(cond ( (equal (length (second (car mess_lst) 1) ) )
(setq result (cons (caar mess_lst) result))
)
)
)
)
; *************************************************************
; ASSIGN_VBLS keeps variable assignment straight in setting up an
; abstraction. It uses an association list:
; ( (val1 vbl1) (val2 vbl2) ...).
; Uses global variables vbl_list set up in begin.l, plus:
; avail_vbls assoc_vbls new_assign.
(defun assign_vbls (arg_lst1 arg_lst2)
(prog (args1 args2 result)
(setq args1 arg_lst1)
(setq args2 arg_lst2)
(setq result nil)
(cond ( (equal args1 args2) (return args1)))
loop
(cond ( (null args1) (return (reverse result)) ) )
(setq new_assign (or (cadr (assoc (car args1) assoc_vbls))
(cadr (assoc (car args2) assoc_vbls))
)
)
; if the value is already associated with a variable, use the vbl.
(cond ( new_assign
(setq result (cons new_assign result) )
)
; otherwise, assign a new variable:
( t (setq result (cons (car avail_vbls) result) )
(setq assoc_vbls
(cons (list (car args1) (car avail_vbls))
(cons (list (car args2) (car avail_vbls))
assoc_vbls
)
)
)
(setq avail_vbls (cdr avail_vbls))
)
)
(setq args1 (cdr args1))
(setq args2 (cdr args2))
(go loop)
)
)
; *************************************************************
; DE_PROJECT_VAL returns simple truth value with proj
; stripped of.
(defun de_project_val (val)
(case val
('proj_true 'true)
('proj_false 'false)
('want_true 'true)
('want_false 'false)
('true 'true)
('false 'false)
)
)
; ************************************************************
; SCHEM_RULES produces schematic forms of rules attached to two
; problem solutions.
(defun schem_rules (pro1 pro2 ana schem)
(prog (ruls)
(setq ruls (get pro1 'rules))
loop
(cond ( (null ruls) (return 'DONE)))
(schem_rule (car ruls) pro2 ana schem)
(setq ruls (cdr ruls))
(go loop)
)
)
; *************************************************************
; SCHEM_RULE looks for schematizable versions of a rule.
(defun schem_rule (rul prob ana schem)
(prog (ruls related_actns related_condns result)
(setq related_actns nil
related_condns nil
result nil
)
(setq ruls (get prob 'rules))
loop
(cond ( (null ruls) (return result)))
(setq rul1 (car ruls))
(setq related_condns
(abstract_list (get rul 'conditions)
(get rul1 'conditions)
ana
)
)
(setq related_actns
(abstract_list (get rul 'actions)
(get rul1 'actions)
ana
)
)
(cond ( (and related_condns related_actns)
(make_rule_long schem
related_condns
related_actns
(get rul 'slot)
(get rul 'status)
(get rul 'strength)
)
(setq result (cons (car all_rules) result))
)
)
(setq ruls (cdr ruls))
(go loop)
)
)
; *************************************************************
; END OF ANA_SCHEM.L
; FILE: analog.l
; PURPOSE: analogical problem solving
; PROGRAMMER: Paul Thagard
; CREATED: 10-24-85
; UPDATED: 1-14-87
; Analogical problem solving works in the following stages.
; 1. Solve problem P1.
; 2. Store solution to P1 with relevant concepts.
; 3. Start solution of P2, the target problem.
; 4. Spreading activation leads to activation of concepts
; to which P1 is linked, hence to P1, the base problem.
; 5. If P1 is sufficiently active, trigger analogical problem
; solving.
; 6. Map from P1 to P2 using record of activation patterns.
; 7. Use information from mapping to start a new
; subproblem to try to apply what worked in P1 to P2.
; 8. Solve P2.
; *****************************************************************
; Global variables in this module: best_prob analogous_concepts
; analogous_objects key_effectors
; constant:
(setq min_prob_activation .55)
; ******************************************************************
; TRIG_ANALOG is called by solve_problem. It checks to see whether
; there are any active problems that might be useful analogs.
; It looks only at the most active problem.
(defun trig_analog (prob problem_list)
(cond ( problem_list
(setq best_prob (highest problem_list 'activation))
(cond ( (greaterp (get best_prob 'activation)
min_prob_activation
)
(analogize best_prob prob)
)
)
)
)
)
; *******************************************************
; ANALOGIZE maps between two problems and constructs a new
; approach to the target problem.
(defun analogize (base target)
; find analogous concepts, which must exist or else activation
; would not be above threshold
(setq analogous_concepts (trace_concepts base target))
; find analogous objects, instantiating analogous concepts
(setq analogous_objects (trace_objects analogous_concepts base target ))
; note what effectors or hypotheses were the key to solution of base
; problem.
(setq key_effectors (get_effectors base))
(setq key_hypotheses (get base 'abductions))
; announce and note analogy:
(print_analogy base target analogous_concepts
analogous_objects key_effectors
)
(put (car active_problems) 'analogies_used
(union (list (list base target analogous_concepts))
(get (car active_problems) 'analogies_used)
)
)
; reconstruct target problem
(reconstruct base target key_effectors key_hypotheses
analogous_concepts analogous_objects
)
; activate rules for solution of base
(setq active_rules (union active_rules (get base 'rules)))
)
; **********************************************************
; TRACE_CONCEPTS returns a list of pairs of associated concepts.
; The associations were set up by execute_actions
; and build_sub_goals in prob_spread.l.
; There when a concept became active, it was noted what concepts had
; led to its activation. This looks at the concepts used in the
; base and in the target, and identifies what concepts in the
; target led to the activation of which concepts in the base,
; establishing the mapping between them. E.g. in the ray problem,
; capture leads to the activation of destroy in the fortress problem,
; so (capture destroy) is one member of the list returned.
(defun trace_concepts (base target)
(prog (base_concepts target_concepts first_conc act_orgins result)
(setq base_concepts (conc_from_prob base)) ; see store.l
(setq target_concepts (conc_from_prob target))
(setq result nil)
loop
(cond ( (null base_concepts) (return result)))
(setq first_conc (car base_concepts))
; find what led to activation of first_conc
(setq act_origins (find_act_origins first_conc base target ))
; look for originating concepts that are in target_concepts
(setq result (union result
(pair_up first_conc act_origins target_concepts)
)
)
(setq base_concepts (cdr base_concepts))
(go loop)
)
)
; *********************************************************
; FIND_ACT_ORIGINS finds the concepts that originated the activation
; of a given concept, using the activation records set up by execute_actions
; and build_sub_goals in prob_spread.l. To avoid infinite loops, it is
; crucial to distinguish between paths of activation by rule-firing and
; paths of activation by sub-goaling. In the former case, activation
; records are stored with the property forward_activated_by;
; in the latter, with
; goal_activated_by.
; Multiple paths of activation are possible, resulting in multiple
; mappings. If the concept was already in the base problem,
; no activation path was necessary.
; for debugging:
(setq activn_debug nil)
(defun find_act_origins (conc base target)
; if concept was in both problems, it activated itself.
(cond ( (member conc (concepts_from (mess_from_prob target)))
(list conc)
)
; otherwise get forward and backward origins:
(t (union (direction_find_origins conc base target
'forward_activated_by
)
(direction_find_origins conc base target
'goal_activated_by
)
)
)
)
)
; *************************************************************
; DIRECTION_FIND_ORIGINS looks for activation origins in one
; direction, either forward (rule firing and ordinate spread)
; or backward by subgoaling.
(defun direction_find_origins (conc base target direction)
(prog (still_to_expand first_conc activ_prop expanded result)
(if activn_debug (my_print '"Debugging " conc '" " direction))
(setq activ_prop direction) ; note source of activation
(setq still_to_expand (get conc activ_prop))
(setq expanded nil)
(setq result nil)
; search for originating concept:
loop
(cond ( (null still_to_expand) (return (remove-duplicates result))))
(setq first_conc (car still_to_expand))
(if activn_debug (my_print first_conc still_to_expand expanded))
; if first_conc was in target, it was source of activation
; also must have same # of arguments.
(cond ( (and (member first_conc (conc_from_prob target))
(same_arg_size conc first_conc)
)
(setq result (cons first_conc result))
; kluge to prevent getting additional silly analogs FIX:
(return result)
)
)
; check to avoid infinite loops:
(cond ( (member first_conc expanded)
(setq still_to_expand (remove first_conc still_to_expand))
(go loop)
)
)
; if concept was activated by other concepts, add them to
; the list with new ones to be checked first.
(cond ( (get first_conc activ_prop)
(setq still_to_expand
(union (reverse (get first_conc activ_prop))
still_to_expand
)
)
(setq expanded (cons first_conc expanded))
)
; otherwise, the concept was an originator
(t (setq result (cons first_conc result)))
)
(setq still_to_expand (remove first_conc still_to_expand))
(go loop)
)
)
; ********************************************************
; SAME_ARG_SIZE checks if two concepts are both n-place.
(defun same_arg_size (conc1 conc2)
(if (or (null (get conc1 'instances))
(null (get conc1 'instances))
)
t
;else
(equal (length (second (car (get conc1 'instances))))
(length (second (car (get conc2 'instances))))
)
)
)
; *********************************************************
; PAIR_UP takes a concept, a list of concepts, and another list of concepts.
; Any member of the first list which is also a member of the second list
; is paired with the original concept.
; Example: (pair_up 'a '(b c d) '(c d)) -> ( (a c) (a d))
(defun pair_up (conc list1 list2)
(prog (lst1 first result)
(setq lst1 list1)
(setq result nil)
loop
(cond ( (null lst1) (return result)))
(setq first (car lst1))
(cond ( (member first list2)
(setq result (cons (list conc first) result))
)
)
(setq lst1 (cdr lst1))
(go loop)
)
)
; ************************************************************
; TRACE_OBJECTS finds similar pairs of analogous objects.
; o1 in the base is paired with o2 in the target if o1 has
; some concept c1 that has been traced to some c2 that the problem
; description says applies to o2.
; Example: in the ray problem, o_army gets paired with o_tumor,
; because army has been associated with tumor.
; Note: takes a list of pairs of concepts, and returns a list
; of pairs of objects.
(defun trace_objects (list_of_concept_pairs base target)
(prog (lst result conc1 conc2)
(setq lst list_of_concept_pairs)
(setq result nil)
loop
(cond ( (null lst) (return (remove_duplicates result))))
(setq conc1 (caar lst))
(setq conc2 (second (car lst)))
(setq result (union result
(pair_obj_up conc1 conc2 base target)
)
)
(setq lst (cdr lst))
(go loop)
)
)
; **********************************************************
; PAIR_OBJ_UP pairs each object that the base says has concept1
; with an object that the target says has concept2.
(defun pair_obj_up (concpt1 concpt2 prob1 prob2)
(make_pairs (objects_from concpt1 prob1)
(objects_from concpt2 prob2)
)
)
; ********************************************************
; OBJECTS_FROM returns a list of objects associated with a
; concept in the given problem.
(defun objects_from (conc prob)
(prog (mess_list first_mess)
(setq mess_list (mess_from_prob prob))
loop
(cond ( (null mess_list) (return nil)))
(setq first_mess (car mess_list))
(cond ( (and (equal conc (get_predicate first_mess))
(or (equal (third first_mess) 'true)
(equal (third first_mess) 'want_true)
)
)
(return (get_argument first_mess))
)
)
(setq mess_list (cdr mess_list))
(go loop)
)
)
; **********************************************************
; MESS_FROM_PROB returns the relevant messages from a problem.
(defun mess_from_prob (prob)
(union (get prob 'goals)
(get prob 'start)
)
)
; **************************************************************
; MAKE_PAIRS takes two lists, and returns a list of pairs,
; with the nth atom of list1 paired with the nth of list2.
(defun make_pairs (lst1 lst2)
(cond ( (not_equal (length lst1) (length lst2)) nil)
( (null lst1) nil )
( t (cons (list (car lst1) (car lst2))
(make_pairs (cdr lst1) (cdr lst2))
)
)
)
)
; ***************************************************************
; GET_EFFECTORS looks to see what effectors were instrumental in
; solving a problem. Currently, this is very simple, looking at
; all the effectors that were used in solving a problem. These are
; noted by update_effects in prob_fire.l.
; A more sophisticated approach would require some causal analysis,
; to determine which of the effectors used were most valuable.
; Cf. explanation-based learning.
(defun get_effectors (prob)
(get prob 'effects_objs)
)
; ****************************************************************
; PRINT_ANALOGY announces the found analogy.
(defun print_analogy (base target ana_conc ana_obj effects)
(cond ( trace_prob
(my_print '"Analogy found between " base " and " target )
(my_print '"Analogous concepts: " ana_conc)
(my_print '"Analogous objects: " ana_obj)
(my_print '"Key effectors: " effects)
(my_print '"Activating rules: " (get base 'rules))
)
)
)
; ****************************************************************
; RECONSTRUCT reconstructs the target problem. Currently, this consists
; of setting new subgoals based on key effectors in the base and the
; mapped objects.
; A more sophisticated technique would be to start a whole new sub-problem,
; e.g. how to split a ray-beam.
; In either case, the result is a kind of decomposition of the target problem
; based on the structure of the base problem. Nice, huh?
; <>
(defun reconstruct (base target effects hypotheses ana_concs ana_objs)
(cond ( hypotheses
(reconstruct_hyps base target hypotheses ana_concs ana_objs)
)
)
(prog (effs first_eff eff_objs new_sub_goal)
(setq effs effects)
loop
(cond ( (null effs) (return t)))
(setq first_eff (car effs))
; find what objects to do the effect on:
(setq eff_objs (find_associates (second first_eff)
ana_objs
)
)
; set a new sub-goal to do the effect:
(setq new_sub_goal (list (car first_eff)
eff_objs
'want_true
)
)
(put target 'sub_goals (cons new_sub_goal
(get target 'sub_goals)
)
)
; activate concept from subgoal:
(put (car new_sub_goal) 'activation
(my_max 1
(add .6 (get (car new_sub_goal) 'activation))
) ; arbitrary number
)
(setq active_concepts (cons (car new_sub_goal)
active_concepts
)
)
(cond ( trace_prob
(my_print '"New sub-goal: " new_sub_goal)
)
)
(setq effs (cdr effs))
(go loop)
)
)
; *************************************************************
; FIND_ASSOCIATES takes a list of objects, and returns a list of
; their associates, based on an association list.
(defun find_associates (lst assoc_lst)
(prog (ls result)
(setq ls lst)
loop
(cond ( (null ls) (return (reverse result)) ))
(setq result (cons (second (assoc (car ls) assoc_lst))
result
)
)
(setq ls (cdr ls))
(go loop)
)
)
; *************************************************************
; FOR ANALOGICAL ABDUCTION:
; *************************************************************
; RECONSTRUCT_HYPS is like reconstruct, except that instead of
; building sub-goals on the basis of past effects, it builds new
; hypotheses on the basis of past abduced hypotheses.
; <>
(defun reconstruct_hyps (base target hypoths ana_concs ana_objs)
(prog (hyps ana_hyp)
(setq hyps hypoths)
loop
(cond ( (null hyps) (return t)))
(setq ana_hyp (or (tight_analog_hypoth base target
(caar hyps) ana_concs ana_objs
)
(loose_analog_hypoth (caar hyps) ana_concs
analogous_objects ; kludge
)
)
)
(cond ( ana_hyp
(make_hypothesis ana_hyp target base 'Analogical)
)
)
(setq hyps (cdr hyps))
(go loop)
)
)
; *************************************************************
; TIGHT_ANALOG_HYPOTH constructs a new hypothesis analogous to an old
; one.
; This uses a detailed mapping between problems to construct
; well-developed analogies.
; Global vbls: new_conc new_args hyp_mess new_mess
(defun tight_analog_hypoth (base target hyp ana_concs ana_objs)
(setq hyp_mess hyp) ;correction from earlier: hyp is mess already
; construct new predicate:
(setq new_conc (second (assoc (car hyp_mess) ana_concs)))
; construct new arguments
(setq new_args (find_associates (second hyp_mess) ana_objs))
(cond ( (and new_conc new_args)
(setq new_mess
(list new_conc
new_args
(third hyp_mess)
.1
)
)
; make sure explanation not circular, i.e. explaining itself:
(cond ( (circular new_mess base target) nil)
; return message
( t (name_message new_mess 'hypothesis))
)
)
(t nil) ; return nil if nothing formed
)
)
; *************************************************************
; CIRCULAR checks that a new hypothesis isn't equivalent to
; one of the explananda. If it is, the base problem is listed as
; useless, and de-activated by prob_spread.l.
(defun circular (mess base target)
(cond ( (mess_on mess (get target 'goals) 'sought)
(my_print '"Circular hypothesis rejected: " mess)
(my_print '"Failed analogy: " base)
(put target 'bad_ana_problems
(union (list base) (get target 'bad_ana_problems))
)
)
(t nil)
)
)
; *************************************************************
; LOOSE_ANALOG_HYPOTH constructs a new hypothesis analogous to an old
; one.
; This uses any possible mapping between problems to construct
; well-developed analogies. Currently a bit klugy.
; Global vbls: new_conc new_args hyp_mess new_mess
(defun loose_analog_hypoth (hyp ana_concs ana_objs)
(setq hyp_mess hyp)
; construct new predicate - cheap:
(setq new_conc (car hyp_mess))
; construct new arguments - cheap:
(setq new_args (find_loose_associates (second hyp_mess) ana_objs))
(cond ( (and new_conc new_args)
(setq new_mess
(list new_conc
new_args
(third hyp_mess)
.1
)
)
(cond ( (circular new_mess base target) nil)
; return message
( t (name_message new_mess 'hypothesis))
)
)
(t nil) ; return nil if nothing formed
)
)
; *************************************************************
; FIND_LOOSE_ASSOCIATES takes a list of objects, and returns a list of
; their associates, based on an association list.
; If no associate available, will use existential variable, set up
; by reconstruct hyps
(defun find_loose_associates (lst assoc_lst)
(prog (ls result ex_vbl)
(setq ls lst)
loop
(cond ( (null ls) (return (reverse result)) ))
(setq result
(cons (cond ( (second (assoc (car ls) assoc_lst)))
(t (setq ex_vbl (car exist_vbls))
(setq analogous_objects ; kluge!
(cons (list (car ls) ex_vbl)
analogous_objects
)
)
(setq exist_vbls (cdr exist_vbls))
ex_vbl
)
)
result
)
)
(setq ls (cdr ls))
(go loop)
)
)
; *************************************************************
; End of analog.l.; FILE: begin.l
; PURPOSE: Central file for system PI (Processes of Induction)
; Program written in Common Lisp, running on a Sun 3/75
; under UNIX.
; Includes functions for running system
; and functions for making
; the central data structures of PI: concepts,
; rules, objects, problems.
; PROGRAMMER: Paul Thagard
; CREATED: 5-23-84
; LAST UPDATED: 5-23-88
; NOTE: PI is copyright (c) 1988 Paul Thagard. Permission is
; granted to use it for research purposes, but denied for
; commercial and military purposes.
; This is the Common LISP version.
; *********************************************************
(my_print "Welcome to PI. This program is copyright (c) 1988 Paul Thagard.")
(my_print "Permission is hereby granted for use for research purposes,")
(my_print " but denied for commercial or military purposes.")
(my_print "It comes with no warranty.")
;**********************************************************
; PI files: (add suffix ".l")
; analog analogical problem solving
; ana_schem analogical schema formation
; begin initialization and data structure creation
; cause causal analysis (not for distribution)
; common conversion to common lisp
; concepts concept formation
; explain explanation and abduction
; gen generalization: synchronic rule learning
; misc miscellaneous utility functions
; motiv motivated inference
; prob problem solving
; prob_fire problem solving: firing rules
; prob_spread problem solving: spreading activation
; store storing and retrieving messages and problems
; theory inference to the best explanation
; trig triggering conditions
; world simulated world (not for distribution)
; wts input file: discovering the wave theory of sound
; *************************************************************
; TO RUN PI, LOAD ALL THE ABOVE FILES AND A DATA FILE MODELED ON
; WTS.L
; **************************************************************
; data files: some not yet transferred into franz
; most not transferred into common
;
; for distribution, the file wts is included to simulate
; discovery of the wave theory of sound.
;
; data/abd sample data for abduction
; data/abd_rul data for abduction to a rule
; data/adair schema formation
; data/ana_schem data for analogical abduction
; data/class sample data for classification
; data/cup input data for cup & paper problem
; data/breed.l analogical abduction
; data/exist.l existential abduction
; data/fem-banl.l conceptual combination
; data/fort.l problem solving by analogy
; data/gen_lon data for generalization with relations
; data/ray data for ray problem - analogy
; data/spec input data for specialization
; data/theor data for theory evaluation
; data/theor2 theory evaluation
; data/wts1 data for propagation -> wave theory of sound
; data/wts2 data for reflection -> wave theory of sound
; data/wts3 data for propagation & reflection -> wave theory
; data/wts4 data for discovery and rejection of ball theory
; data/wts5
; data/wts.big wave theory of sound
; data/yuppy input data for concept formation
; pi.d1 sample data for conceptual combination
; *******************************************************
; run_pi initializes the system setting these parameters:
; 1. trace_data: produces a trace of creation of concepts
; and rules.
; 2. trace_prob: traces problem solving by printing out system
; status at each time step.
; 3. max_rules: the maximum number of rules to be fired at once.
; 4. deact_conc: the amount a concept is deactivated per time step.
; 5. min_activ: the minimum amount a concept must be activated to
; remain on active_concepts.
; 6. incr_activ: determines the extent to which a concept is activated
; as the result of the strength of the rule which
; fired it.
; 7. incr_stren: the amount a successful rule has its strength
; increasedata/
; 8. timesteps: maximum number of steps in problem solving
;
; a typical call would be (run_pi 'true nil 5 .1 .2 .5 .1 50)
(defun run_pi (trace_data? trace_prob? max_rules? deact_conc?
min_activ? incr_activ? incr_stren? timesteps?
)
(setq all_rules nil ; system information
all_concepts nil
all_problems nil
generic_concepts nil
all_objects nil
all_goal nil
all_hypothesis nil
all_explanandum nil
active_concepts nil ; data structures
active_rules nil
active_messages nil
active_problems nil
active_solutions nil
active_projections nil
known_messages nil
projected_messages nil
best_rules nil
trace_data trace_data? ; parameters
trace_prob trace_prob?
max_rules max_rules?
deact_conc deact_conc?
min_activ min_activ?
incr_activ incr_activ?
incr_stren incr_stren?
timesteps timesteps?
; flags for system functioning:
goals_to_messages nil ; make want_true messages
go_backwards t ; use subgoals
world_made nil ; artificial environment
trig_flag t ; trigger inductions
analogy_flag t ; trigger use of analogy
motive_relevance_flag nil ; see motiv.l.
rel_motiv_flag nil ; "
chain_explain_flag nil ; see concepts.l
conc_to_explain_with nil ; "
; constants:
confidence_threshold .5
; available variables:
univ_vbls '($x $y $z $u $v $w $d $e $f) ; universal
exist_vbls '(%x %y %z %u %v %w %a %b %c %d %e %f %g %h) ; existential
all_exist_vbls '(%x %y %z %u %v %w %a %b %c %d %e %f %g %h)
vbl_list (union univ_vbls exist_vbls )
)
(setq debug nil)
(my_print '"PI initialized.")
)
; to make life easy, just call run which sets defaults:
(defun run (steps)
(run_pi 'true 'true 10 .1 .001 1 .2 steps)
)
;**********************************************************
;**********************************************************
;* functions for creating data structures: *
;**********************************************************
; MAKE_PROBLEM constructs a problem with goals and starting conditions:
(defun make_problem (problem_name start_list goal_list type)
(setq all_problems (cons problem_name all_problems))
(put problem_name 'goals
(name_mess_list goal_list type)
)
(put problem_name 'data_type 'problem)
(put problem_name 'start start_list)
(put problem_name 'activation 0)
(cond ( trace_data
(my_print '"Problem made: " problem_name)
)
)
)
; *****
Trail: Internationalization
by Dale Green
The lessons in this trail teach you how to internationalize Java applications. Internationalized applications are easy to tailor to the customs and languages of end users around the world.
Introduction defines the term internationalization, gives a quick sample program, and provides a checklist you can use to internationalize an existing program.
Lesson: Introduction
Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes. Sometimes the term internationalization is abbreviated as i18n, because there are 18 letters between the first "i" and the last "n."
An internationalized program has the following characteristics:
With the addition of localized data, the same executable can run worldwide.
Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically.
Support for new languages does not require recompilation.
Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language.
It can be localized quickly.
Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text. The term localization is often abbreviated as l10n, because there are 10 letters between the "l" and the "n." Usually, the most time-consuming portion of the localization phase is the translation of text. Other types of data, such as sounds and images, may require localization if they are culturally sensitive. Localizers also verify that the formatting of dates, numbers, and currencies conforms to local requirements.
Internationalization may seem a bit daunting at first. Reading the following sections will help ease you into the subject.
A Quick Example
This section shows you how to internationalize a simple program, step by step.
Checklist
So you've inherited a program that needs to be internationalized, but you don't know where to start? Check out this checklist. It summarizes the necessary internationalization tasks and provides links to the relevant lessons in this chapter.
Setting the Locale explains how to create and how to use Locale objects.
Lesson: Setting the Locale
An internationalized program can display information differently throughout the world. For example, the program will display different messages in Paris, Tokyo, and New York. If the localization process has been fine-tuned, the program will display different messages in New York and London to account for the differences between American and British English. How does an internationalized program identify the appropriate language and region of its end users? Easy. It references a Locale object.
A Locale object is an identifier for a particular combination of language and region. If a class varies its behavior according to Locale, it is said to be locale-sensitive. For example, the NumberFormat class is locale-sensitive; the format of the number it returns depends on the Locale. Thus NumberFormat may return a number as 902 300 (France), or 902.300 (Germany), or 902,300 (United States). Locale objects are only identifiers. The real work, such as formatting and detecting word boundaries, is performed by the methods of the locale-sensitive classes.
The following sections explain how to work with Locale objects:
Creating a Locale
When creating a Locale object, you usually specify a language code and a country code. A third parameter, the variant, is optional.
Identifying Available Locales
Locale-sensitive classes support only certain Locale definitions. This section shows you how to determine which Locale definitions are supported.
The Scope of a Locale
On the Java platform you do not specify a global Locale by setting an environment variable before running the application. Instead you either rely on the default Locale or assign a Locale to each locale-sensitive object.
Isolating Locale-Specific Data shows how to dynamically access objects that vary with Locale.
Lesson: Isolating Locale-Specific Data
Locale-specific data must be tailored according to the conventions of the end user's language and region. The text displayed by a user interface is the most obvious example of locale-specific data. For example, an application with a Cancel button in the U.S. will have an Abbrechen button in Germany. In other countries this button will have other labels. Obviously you don't want to hardcode this button label. Wouldn't it be nice if you could automatically get the correct label for a given Locale? Fortunately you can, provided that you isolate the locale-specific objects in a ResourceBundle.
In this lesson you'll learn how to create and access ResourceBundle objects. If you're in a hurry to examine some coding examples, go ahead and check out the last two sections in this lesson. Then you can come back to the first two sections to get some conceptual information about ResourceBundle objects.
About the ResourceBundle Class
ResourceBundle objects contain locale-specific objects. When you need a locale-specific object, you fetch it from a ResourceBundle, which returns the object that matches the end user's Locale. This section explains how a ResourceBundle is related to a Locale, and describes the ResourceBundle subclasses.
Preparing to Use a ResourceBundle
Before you create your ResourceBundle objects, you should do a little planning. First, identify the locale-specific objects in your program. Then organize them into categories and store them in different ResourceBundle objects accordingly.
Backing a ResourceBundle with Properties Files
If your application contains String objects that need to be translated into various languages, you can store these String objects in a PropertyResourceBundle, which is backed up by a set of properties files. Since the properties files are simple text files, they can be created and maintained by your translators. You don't have to change the source code. In this section you'll learn how to set up the properties files that back up a PropertyResourceBundle.
Using a ListResourceBundle
The ListResourceBundle class, which is a subclass of ResourceBundle, manages locale-specific objects with a list. A ListResourceBundle is backed by a class file, which means that you must code and compile a new source file each time support for an additional Locale is needed. However, ListResourceBundle objects are useful because unlike properties files, they can store any type of locale-specific object. By stepping through a sample program, this section demonstrates how to use a ListResourceBundle.
Formatting explains how to format numbers, dates, and text messages according to Locale, and how to create customized formats with patterns.
Lesson: Formatting
This lesson explains how to format numbers, currencies, dates, times, and text messages. Because end users can see these data elements, their format must conform to various cultural conventions. Following the examples in this lesson will teach you how to:
Format data elements in a locale-sensitive manner
Keep your code locale-independent
Avoid the need to write formatting routines for specific locales
Numbers and Currencies
This section explains how to use the NumberFormat, DecimalFormat, and DecimalFormatSymbols classes.
Dates and Times
This section focuses on the DateFormat, SimpleDateFormat, and DateFormatSymbols classes.
Messages
This section shows how the MessageFormat and ChoiceFormat classes can help you solve some of the problems you might encounter when formatting text messages.
Working with Text provides techniques for manipulating text in a locale-independent manner.
Lesson: Working with Text
Nearly all programs with user interfaces manipulate text. In an international market the text your programs display must conform to the rules of languages from around the world. The Java programming language provides a number of classes that help you handle text in a locale-independent manner.
Checking Character Properties
This section explains how to use the Character comparison methods to check character properties for all major languages.
Comparing Strings
In this section you'll learn how to perform locale-independent string comparisons with the Collator class.
Detecting Text Boundaries
This section shows how the BreakIterator class can detect character, word, sentence, and line boundaries.
Converting Non-Unicode Text
Different computer systems around the world store text in a variety of encoding schemes. This section describes the classes that help you convert text between Unicode and other encodings.
Lesson: Working with Text
Nearly all programs with user interfaces manipulate text. In an international market the text your programs display must conform to the rules of languages from around the world. The Java programming language provides a number of classes that help you handle text in a locale-independent manner.
Checking Character Properties
This section explains how to use the Character comparison methods to check character properties for all major languages.
Comparing Strings
In this section you'll learn how to perform locale-independent string comparisons with the Collator class.
Detecting Text Boundaries
This section shows how the BreakIterator class can detect character, word, sentence, and line boundaries.
Converting Non-Unicode Text
Different computer systems around the world store text in a variety of encoding schemes. This section describes the classes that help you convert text between Unicode and other encodings.
Converting Non-Unicode Text
In the Java programming language char values represent Unicode characters. Unicode is a 16-bit character encoding that supports the world's major languages. You can learn more about the Unicode standard at the Unicode Consortium Web site .
Few text editors currently support Unicode text entry. The text editor we used to write this section's code examples supports only ASCII characters, which are limited to 7 bits. To indicate Unicode characters that cannot be represented in ASCII, such as ö, we used the \uXXXX escape sequence. Each X in the escape sequence is a hexadecimal digit. The following example shows how to indicate the ö character with an escape sequence:
String str = "\u00F6";
char c = '\u00F6';
Character letter = new Character('\u00F6');
A variety of character encodings are used by systems around the world. Currently few of these encodings conform to Unicode. Because your program expects characters in Unicode, the text data it gets from the system must be converted into Unicode, and vice versa. Data in text files is automatically converted to Unicode when its encoding matches the default file encoding of the Java Virtual Machine. You can identify the default file encoding by checking the System property named file.properties, as follows:
System.out.println(System.getProperty("file.encoding"));
If thefile.encoding property differs from the encoding of the text data you want to process, then you must perform the conversion yourself. You might need to do this when processing text from another country or computing platform.
This section discusses the APIs you use to translate non-Unicode text into Unicode. Before using these APIs, you should verify that the character encoding you wish to convert into Unicode is supported. The list of supported character encodings is not part of the Java programming language specification. Therefore the character encodings supported by the APIs may vary with platform. To see which encodings the Java Development Kit supports, see the "Supported Encodings" section in the Internationalization Overview document.
The material that follows describes two techniques for converting non-Unicode text to Unicode. You can convert non-Unicode byte arrays into String objects, and vice versa. Or you can translate between streams of Unicode characters and byte streams of non-Unicode text.
Byte Encodings and Strings
This section shows you how to convert non-Unicode byte arrays into String objects, and vice versa.
Character and Byte Streams
In this section you'll learn how to translate between streams of Unicode characters and byte streams of non-Unicode text.
Byte Encodings and Strings
If a byte array contains non-Unicode text, you can convert the text to Unicode with one of the String constructor methods. Conversely, you can convert a String object into a byte array of non-Unicode characters with the String.getBytes method. When invoking either of these methods, you specify the encoding identifier as one of the parameters.
The example that follows converts characters between UTF-8 and Unicode. UTF-8 is a transmission format for Unicode that is safe for UNIX file systems. The full source code for the example is in the file StringConverter.java.
The StringConverter program starts by creating a String containing Unicode characters:
String original = new String("A" + "\u00ea" + "\u00f1" +
"\u00fc" + "C");
When printed, the String named original appears as:
AêñüC
To convert the String object to UTF-8, invoke the getBytes method and specify the appropriate encoding identifier as a parameter. The getBytes method returns an array of bytes in UTF-8 format. To create a String object from an array of non-Unicode bytes, invoke the String constructor with the encoding parameter. The code that makes these calls is enclosed in a try block, in case the specified encoding is unsupported:
try {
byte[] utf8Bytes = original.getBytes("UTF8");
byte[] defaultBytes = original.getBytes();
String roundTrip = new String(utf8Bytes, "UTF8");
System.out.println("roundTrip = " + roundTrip);
System.out.println();
printBytes(utf8Bytes, "utf8Bytes");
System.out.println();
printBytes(defaultBytes, "defaultBytes");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
The StringConverter program prints out the values in the utf8Bytes and defaultBytes arrays to demonstrate an important point: The length of the converted text might not be the same as the length of the source text. Some Unicode characters translate into single bytes, others into pairs or triplets of bytes.
The printBytes method displays the byte arrays by invoking the byteToHex method, which is defined in the source file, UnicodeFormatter.java. Here is the printBytes method:
public static void printBytes(byte[] array, String name) {
for (int k = 0; k < array.length; k++) {
System.out.println(name + "[" + k + "] = " + "0x" +
UnicodeFormatter.byteToHex(array[k]));
}
}
The output of the printBytes method follows. Note that only the first and last bytes, the A and C characters, are the same in both arrays:
utf8Bytes[0] = 0x41
utf8Bytes[1] = 0xc3
utf8Bytes[2] = 0xaa
utf8Bytes[3] = 0xc3
utf8Bytes[4] = 0xb1
utf8Bytes[5] = 0xc3
utf8Bytes[6] = 0xbc
utf8Bytes[7] = 0x43
defaultBytes[0] = 0x41
defaultBytes[1] = 0xea
defaultBytes[2] = 0xf1
defaultBytes[3] = 0xfc
defaultBytes[4] = 0x43
The Java programming language is a high-level language that can be characterized by all of the following buzzwords:
Simple
Architecture neutral
Object oriented
Portable
Distributed
High performance
Interpreted
Multithreaded
Robust
Dynamic
Secure
1.2 Design Goals of the JavaTM Programming Language
The design requirements of the JavaTM programming language are driven by the nature of the computing environments in which software must be deployed.
The massive growth of the Internet and the World-Wide Web leads us to a completely new way of looking at development and distribution of software. To live in the world of electronic commerce and distribution, Java technology must enable the development of secure, high performance, and highly robust applications on multiple platforms in heterogeneous, distributed networks.
Operating on multiple platforms in heterogeneous networks invalidates the traditional schemes of binary distribution, release, upgrade, patch, and so on. To survive in this jungle, the Java programming language must be architecture neutral, portable, and dynamically adaptable.
The system that emerged to meet these needs is simple, so it can be easily programmed by most developers; familiar, so that current developers can easily learn the Java programming language; object oriented, to take advantage of modern software development methodologies and to fit into distributed client-server applications; multithreaded, for high performance in applications that need to perform multiple concurrent activities, such as multimedia; and interpreted, for maximum portability and dynamic capabilities.
Together, the above requirements comprise quite a collection of buzzwords, so let's examine some of them and their respective benefits before going on.
1.2.1 Simple, Object Oriented, and Familiar
Primary characteristics of the Java programming language include a simple language that can be programmed without extensive programmer training while being attuned to current software practices. The fundamental concepts of Java technology are grasped quickly; programmers can be productive from the very beginning.
The Java programming language is designed to be object oriented from the ground up. Object technology has finally found its way into the programming mainstream after a gestation period of thirty years. The needs of distributed, client-server based systems coincide with the encapsulated, message-passing paradigms of object-based software. To function within increasingly complex, network-based environments, programming systems must adopt object-oriented concepts. Java technology provides a clean and efficient object-based development platform.
Programmers using the Java programming language can access existing libraries of tested objects that provide functionality ranging from basic data types through I/O and network interfaces to graphical user interface toolkits. These libraries can be extended to provide new behavior.
Even though C++ was rejected as an implementation language, keeping the Java programming language looking like C++ as far as possible results in it being a familiar language, while removing the unnecessary complexities of C++. Having the Java programming language retain many of the object-oriented features and the "look and feel" of C++ means that programmers can migrate easily to the Java platform and be productive quickly.
1.2.2 Robust and Secure
The Java programming language is designed for creating highly reliable software. It provides extensive compile-time checking, followed by a second level of run-time checking. Language features guide programmers towards reliable programming habits.
The memory management model is extremely simple: objects are created with a new operator. There are no explicit programmer-defined pointer data types, no pointer arithmetic, and automatic garbage collection. This simple memory management model eliminates entire classes of programming errors that bedevil C and C++ programmers. You can develop Java code with confidence that the system will find many errors quickly and that major problems won't lay dormant until after your production code has shipped.
Java technology is designed to operate in distributed environments, which means that security is of paramount importance. With security features designed into the language and run-time system, Java technology lets you construct applications that can't be invaded from outside. In the network environment, applications written in the Java programming language are secure from intrusion by unauthorized code attempting to get behind the scenes and create viruses or invade file systems.
1.2.3 Architecture Neutral and Portable
Java technology is designed to support applications that will be deployed into heterogeneous network environments. In such environments, applications must be capable of executing on a variety of hardware architectures. Within this variety of hardware platforms, applications must execute atop a variety of operating systems and interoperate with multiple programming language interfaces. To accommodate the diversity of operating environments, the Java CompilerTM product generates bytecodes--an architecture neutral intermediate format designed to transport code efficiently to multiple hardware and software platforms. The interpreted nature of Java technology solves both the binary distribution problem and the version problem; the same Java programming language byte codes will run on any platform.
Architecture neutrality is just one part of a truly portable system. Java technology takes portability a stage further by being strict in its definition of the basic language. Java technology puts a stake in the ground and specifies the sizes of its basic data types and the behavior of its arithmetic operators. Your programs are the same on every platform--there are no data type incompatibilities across hardware and software architectures.
The architecture-neutral and portable language platform of Java technology is known as the Java virtual machine. It's the specification of an abstract machine for which Java programming language compilers can generate code. Specific implementations of the Java virtual machine for specific hardware and software platforms then provide the concrete realization of the virtual machine. The Java virtual machine is based primarily on the POSIX interface specification--an industry-standard definition of a portable system interface. Implementing the Java virtual machine on new architectures is a relatively straightforward task as long as the target platform meets basic requirements such as support for multithreading.
1.2.4 High Performance
Performance is always a consideration. The Java platform achieves superior performance by adopting a scheme by which the interpreter can run at full speed without needing to check the run-time environment. The automatic garbage collector runs as a low-priority background thread, ensuring a high probability that memory is available when required, leading to better performance. Applications requiring large amounts of compute power can be designed such that compute-intensive sections can be rewritten in native machine code as required and interfaced with the Java platform. In general, users perceive that interactive applications respond quickly even though they're interpreted.
1.2.5 Interpreted, Threaded, and Dynamic
The Java interpreter can execute Java bytecodes directly on any machine to which the interpreter and run-time system have been ported. In an interpreted platform such as Java technology-based system, the link phase of a program is simple, incremental, and lightweight. You benefit from much faster development cycles--prototyping, experimentation, and rapid development are the normal case, versus the traditional heavyweight compile, link, and test cycles.
Modern network-based applications, such as the HotJavaTM Browser for the World Wide Web, typically need to do several things at the same time. A user working with HotJava Browser can run several animations concurrently while downloading an image and scrolling the page. Java technology's multithreading capability provides the means to build applications with many concurrent threads of activity. Multithreading thus results in a high degree of interactivity for the end user.
The Java platform supports multithreading at the language level with the addition of sophisticated synchronization primitives: the language library provides the Thread class, and the run-time system provides monitor and condition lock primitives. At the library level, moreover, Java technology's high-level system libraries have been written to be thread safe: the functionality provided by the libraries is available without conflict to multiple concurrent threads of execution.
While the Java Compiler is strict in its compile-time static checking, the language and run-time system are dynamic in their linking stages. Classes are linked only as needed. New code modules can be linked in on demand from a variety of sources, even from sources across a network. In the case of the HotJava Browser and similar applications, interactive executable code can be loaded from anywhere, which enables transparent updating of applications. The result is on-line services that constantly evolve; they can remain innovative and fresh, draw more customers, and spur the growth of electronic commerce on the Internet.
--------------------------------------------------------------------------------
1.3 The Java Platform--a New Approach to Distributed Computing
Taken individually, the characteristics discussed above can be found in a variety of software development platforms. What's completely new is the manner in which Java technology and its runtime environment have combined them to produce a flexible and powerful programming system.
Developing your applications using the Java programming language results in software that is portable across multiple machine architectures, operating systems, and graphical user interfaces, secure, and high performance. With Java technology, your job as a software developer is much easier--you focus your full attention on the end goal of shipping innovative products on time, based on the solid foundation of the Java platform. The better way to develop software is here, now, brought to you by the Java platform.
2.3 Summary
To sum up this chapter, Java is:
Simple--the number of language constructs you need to understand to get your job done is minimal.
Familiar--Java looks like C and C++ while discarding the overwhelming complexities of those languages.
Now that you've seen how Java was simplified by removal of features from its predecessors, read the next chapter for a discussion on the object-oriented features of Java.
3.1 Object Technology in Java
To be truly considered "object oriented", a programming language should support at a minimum four characteristics:
Encapsulation--implements information hiding and modularity (abstraction)
Polymorphism--the same message sent to different objects results in behavior that's dependent on the nature of the object receiving the message
Inheritance--you define new classes and behavior based on existing classes to obtain code re-use and code organization
Dynamic binding--objects could come from anywhere, possibly across the network. You need to be able to send messages to objects without having to know their specific type at the time you write your code. Dynamic binding provides maximum flexibility while a program is executing
Java meets these requirements nicely, and adds considerable run-time support to make your software development job easier.
--------------------------------------------------------------------------------
3.2 What Are Objects?
At its simplest, object technology is a collection of analysis, design, and programming methodologies that focuses design on modelling the characteristics and behavior of objects in the real world. True, this definition appears to be somewhat circular, so let's try to break out into clear air.
What are objects? They're software programming models. In your everyday life, you're surrounded by objects: cars, coffee machines, ducks, trees, and so on. Software applications contain objects: buttons on user interfaces, spreadsheets and spreadsheet cells, property lists, menus, and so on. These objects have state and behavior. You can represent all these things with software constructs called objects, which can also be defined by their state and their behavior.
In your everyday transportation needs, a car can be modelled by an object. A car has state (how fast it's going, in which direction, its fuel consumption, and so on) and behavior (starts, stops, turns, slides, and runs into trees).
You drive your car to your office, where you track your stock portfolio. In your daily interactions with the stock markets, a stock can be modelled by an object. A stock has state (daily high, daily low, open price, close price, earnings per share, relative strength), and behavior (changes value, performs splits, has dividends).
After watching your stock decline in price, you repair to the cafe to console yourself with a cup of good hot coffee. The espresso machine can be modelled as an object. It has state (water temperature, amount of coffee in the hopper) and it has behavior (emits steam, makes noise, and brews a perfect cup of java).
3.4 Summary
This chapter has conveyed the essential aspects of Java as an object-oriented language. To sum up:
Classes define templates from which you instantiate (create) distinct concrete objects.
Instance variables hold the state of a specific object.
Objects communicate by sending messages to each other. Objects respond to messages by selecting a method to execute.
Methods define the behavior of objects instantiated from a class. It is an object's methods that manipulate its instance variables. Unlike regular procedural languages, classes in an object-oriented language may have methods with the same names as other classes. A given object responds to a message in ways determined by the nature of that object, providing polymorphic behavior.
Subclasses provide the means by which a new class can inherit instance variables and methods from any already defined class. The newly declared class can add new instance variables (extra state), can add new methods (new behavior), or can override the methods of its superclass (different behavior). Subclasses provide code reuse.
Taken together, the concepts of object-oriented programming create a powerful and simple paradigm for software developers to share and re-use code and build on the work of others.
4.4 Summary
Java--an architecture-neutral and portable programming language--provides an attractive and simple solution to the problem of distributing your applications across heterogeneous network-based computing platforms. In addition, the simplicity and robustness of the underlying Java language results in higher quality, reliable applications in which users can have a high level of confidence. The next chapter contains a brief discussion of Java's interpreted implementation.
5.2 Summary
The interpreted and dynamic nature of Java provides several benefits:
The interpreted environment enables fast prototyping without waiting for the traditional compile and link cycle,
The environment is dynamically extensible, whereby classes are loaded on the fly as required,
The fragile superclass problem that plagues C++ developers is eliminated because of deferral of memory layout decisions to run time.
6.5 Summary
Java is secure to survive in the network-based environment. The architecture-neutral and portable aspects of the Java language make it the ideal development language to meet the challenges of distributing dynamically extensible software across networks.
7.3 Multithreading Support--Conclusion
While other systems have provided facilities for multithreading (usually via "lightweight process" libraries), building multithreading support into the language as Java has done provides the programmer with a much more powerful tool for easily creating thread-safe multithreaded classes.
Other benefits of multithreading are better interactive responsiveness and real-time behavior. Stand-alone Java run-time environments exhibit good real-time behavior. Java environments running on top of popular operating systems provide the real-time responsiveness available from the underlying platform.
8.4 Summary
From the discussion above, you can see that the Java language provides high performance, while its interpreted nature makes it the ideal development platform for fast and fearless prototyping. From the previous chapters, you've seen that the Java language is extremely simple and object oriented. The language is secure to survive in the network-based environment. The architecture-neutral and portable aspects of the Java language make it the ideal development language to meet the challenges of distributing dynamically extensible software across networks.
Now We Move On to the HotJava World-Wide Web Browser
These first eight chapters have been your introduction to the Java language environment. You've learned about the capabilities of Java and its clear benefits to develop software for the distributed world. Now it's time to move on to the next chapter and take a look at the HotJava World-Wide Web browser--a major end-user application developed to make use of the dynamic features of the Java language environment.
Subscribe to:
Comments (Atom)