New Immissions/Updates:
boundless - educate - edutalab - empatico - es-ebooks - es16 - fr16 - fsfiles - hesperian - solidaria - wikipediaforschools
- wikipediaforschoolses - wikipediaforschoolsfr - wikipediaforschoolspt - worldmap -

See also: Liber Liber - Libro Parlato - Liber Musica  - Manuzio -  Liber Liber ISO Files - Alphabetical Order - Multivolume ZIP Complete Archive - PDF Files - OGG Music Files -

PROJECT GUTENBERG HTML: Volume I - Volume II - Volume III - Volume IV - Volume V - Volume VI - Volume VII - Volume VIII - Volume IX

Ascolta ""Volevo solo fare un audiolibro"" su Spreaker.
CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Benutzer:WStephan/Dodge Ram - Wikipedia

Benutzer:WStephan/Dodge Ram

aus Wikipedia, der freien Enzyklopädie

Icon

Skriptsprache
Basisdaten
Paradigmen:
Erscheinungsjahr:
Designer:
Entwickler:
Aktuelle Version: 9.4  (14. November 2005)
Typisierung: schwach, dynamisch
wichtige Implementierungen: Icon
Dialekte: Unicon
Einflüsse: SNOBOL, siehe SNOBOL4
Beeinflusste: Python
Betriebssystem:
Lizenz:
Website: http://www.cs.arizona.edu/icon/index.htm

Icon ist eine High-Level Programmiersprache, die mehrere Programmierparadigmen umfasst und mit SNOBOL, einer Sprache zum Verarbeiten von Zeichenketten, verwandt ist. Unter anderem unterstützt sie zielgerichtete Ausführung und bietet viele Möglichkeiten zur Verarbeitung von Zeichenketten und Textmuster. Icon war ursprünglich nicht objektorientiert, 1996 wurde jedoch eine objektorientierte Erweiterung namens Idol entwickelt, aus der später Unicon wurde.

Inhaltsverzeichnis

[Bearbeiten] Grundsyntax

Icon ist von der ALGOL-Klasse der strukturierten Programmiersprachen abgeleitet, weshalb seine Syntax C und Pascal stark ähnelt. Es verwendet wie Pascal, mit dem es enger verwandt ist, die :=-Syntax für Zuweisungen, das procedure-Schlüsselwort usw. Andererseits verwendet Icon auch, wie C, geschweifte Klammern, um logisch zusammengehörenden Code zu gruppieren und eine Prozedur mit dem Namen main, die ausgeführt wird, um das Programm zu starten.

In many ways Icon also shares features with most scripting programming languages; variables do not have to be declared, types are cast automatically, and numbers can be converted to strings and back automatically. Another feature common to many scripting languages, but not all, is the lack of a line-ending character; in Icon lines not ended by a semicolon get ended by an implied semicolon if it makes sense.

Procedures are the basic building blocks of Icon programs, and although they use Pascal naming they work more like C functions and can return values; there is no function keyword in Icon.

procedure doSomething(aString)
  write(aString)
end

[Bearbeiten] Goal-directed execution

One of Icon's key concepts is that control structures are based "success" or "failure" of expressions, rather than based on boolean logic as in most other programming languages. Under this model simple comparisons like if a < b do not mean "if the operations to the right evaluate to true" as they would under most languages, instead it means something more like "if the operations to the right succeed". In this case the < operator succeeds if the comparison is true, so the end result is identical between Icon and other languages. Things become slightly more interesting when you consider if a < b < c, a common type of comparison that cannot be directly stated in most languages.

The utility of this concept becomes much clearer when you consider real-world examples. Since Icon uses success or failure for all flow control, this simple code:

if a := read() then write(a)

Will copy one line of the standard input to standard output. What's interesting about this example is that the code will work even if the read() causes an error, for instance, if the file does not exist. In that case the statement a := read() will fail, and write will simply not be called.

Success and failure are passed "up" through functions, meaning that a failure inside a nested function will cause the functions calling it to fail as well. For instance, we can write a program to copy an entire input file to output in a single line:

while write(read())

When the read() command fails, at the end of file for instance, the failure will be passed up the chain and write() will fail as well. The while, being a control structure, stops on failure, meaning it stops when the file is empty. For comparison, consider a similar example written in Java-based pseudocode:

try {
  while ((a = read()) != EOF) {
    write(a);
  }
} catch (Exception e) {
  // do nothing, exit the loop
}

In this case there are two comparisons needed, one for end of file (EOF) and another for all other errors. Since Java does not allow errors to be compared as logic elements, as under Icon, the lengthy try/catch syntax must be used instead. Try blocks also impose a performance penalty for simply using them, even if no error occurs, a distributed cost that Icon avoids.

Icon refers to this concept as goal-directed execution, referring to the way that execution continues until some goal is reached. In the example above the goal is to read the entire file; the read command continues to succeed while there is more information to be read, and fails when there isn't. The goal is thus coded directly in the language, instead of using statements checking return codes or similar constructs.

[Bearbeiten] Generators

Expressions in Icon often return a single value, for instance, x < 5 will evaluate and return success or failure. However several of the examples below rely on the fact that many expressions do not immediately return success or failure, returning values in the meantime. This drives the examples with every and to; every causes to to continue to return values until it fails.

This is a key concept in Icon, known as generators. Generators drive much of the loop functionality in the language, but do so more directly; the programmer does not write a loop and then pull out and compare values, Icon will do all of this for you.

Icon includes several generator-builders. The alternator syntax allows a series of items to be generated in sequence until one fails: 1 | "hello" | x < 5 can generate "1", "hello", and "5" if x is less than 5. Alternators can be read as "or" in many cases, for instance:

if y < (x | 5) then write("y=", y)

will write out the value of y if it is smaller than x or 5. Internally Icon checks every value from left to right until one succeeds or the list empties and it returns a failure. Remember that functions will not be called unless the calls within do not fail, so this example can be shortened to:

write("y=", (x | 5) > y)

Another simple generator is the to, which generates lists of integers; every write(1 to 10) will do exactly what it seems to. The bang syntax generates every item of a list; every write(!aString) will output each character of aString on a new line.

To demonstrate the power of this concept, consider string operations. Most languages include a function known as find or indexOf that returns the location of a string within another. Consider:

s = "All the world's a stage. And all the men and women merely players";
i = indexOf("the", s)

This code will return 4, the position of the first occurrence of the word "the". To get the next instance of "the" an alternate form must be used, i = indexOf("the", s, 5), the 5 at the end saying it should look from position 5 on. In order to extract all the occurrences of "the", a loop must be used...

s = "All the world's a stage. And all the men and women merely players";
i = indexOf("the", s)
while i != -1 {
  write(i);
  i =  indexOf("the", s, i+1);
}

Under Icon the find function is a generator, and will return the next instance of the string each time it is resumed before finally failing after it passes the end of the string. The same code under Icon can be written:

s := "All the world's a stage. And all the men and women merely players"
every write(find("the",s))

Find will return the index of the next instance of "the" each time it is resumed by every, eventually passing the end of the string and failing. As in the prior example, this will cause write to fail, and the (one-line) every loop to exit.

Of course there are times where you deliberately want to find a string after some point in input, for instance, you might be scanning a text file containing data in multiple columns. Goal-directed execution works here as well, and can be used this way:

write(5 < find("the", s))

The position will only be returned if "the" appears after position 5, the comparison will fail otherwise, passing that failure to write() as before. There is one small "trick" to this code that needs to be considered: comparisons return the right hand result, so it is important to put the find on the right hand side of the comparison. If it was placed on the left, 5 would be written.

Icon adds several control structures for looping through generators. The every operator is similar to while, looping through every item returned by a generator and exiting on failure:

 every k := i to j do
  write(someFunction(k))

Why use every instead of a while loop in this case? Because while re-evaluates the first result, but every produces all results. The every syntax actually injects values into the function in a fashion similar to blocks under Smalltalk. For instance, the above loop can be re-written this way:

every write(someFunction(i to j))

Users can build new generators easily using the suspend keyword:

procedure findOnlyOdd(pattern, theString)
  every i := find(pattern, theString) do
    if i % 2 = 1 then suspend i
end

This example loops over theString using find to look for pattern. When one is found, and the position is even, the location is returned from the function with suspend. Unlike return, suspend writes down where it is in the internal generators as well, allowing it to pick up where it left off on the next iteration.

[Bearbeiten] Strings

In keeping with its script-like functionality, Icon adds a number of features to make working with strings easier. Most notable among these is the scanning system, which repeatedly calls functions on a string:

s ? write(find("the"))

is a short form of the examples shown earlier. In this case the subject of the find function is placed outside the parameters in front of the question-mark. Icon functions are deliberately (as opposed to automatically) written to identify the subject in parameter lists and allow them to be pulled out in this fashion.

[Bearbeiten] Other structures

Icon strings are simply lists of characters, similar to their partners in C. Icon also allows the user to easily construct their own lists (or arrays):

aCat := ["muffins", "tabby", 2002, 8]

The items within a list can be of any sort, including other structures. To quickly build larger lists, Icon includes the list generator; i := list(10, "word") generates a list containing 10 copies of "word".

Like arrays in other languages, Icon allows items to be looked up by position; weight := aCat[4]. Also remember the bang-syntax, every write(!aCat) will print out four lines, each with one element. Icon includes stack-like functions, push and pop to allow them to form the basis of stacks and queues.

Icon also includes functionality for sets and tables (known as hashes, associative arrays, dictionaries, etc.), but the syntax for creating them is not as nice as a list:

symbols := table(0)
symbols["there"] := 1
symbols["here"] := 2

This code creates a table that will use zero as the default value of any unknown key. It then adds two items into it, with the keys "there" and "here", and values 1 and 2. Note that most modern scripting languages combine lists and tables into a single feature, allowing the user to look up items by position or name, if it has one. This change would seem to clean up the Icon syntax as well.

[Bearbeiten] References

The definitive work is The Icon Programming Language (third edition) by Griswold and Griswold, ISBN 1-57398-001-3. It is out of print but can be downloaded in PDF form.

Icon also has co-expressions, providing non-local exits for program execution. Please see The Icon Programming language and also Shamim Mohamed's article Co-expressions in Icon. (This topic should probably be expanded).


Static Wikipedia (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia February 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu