Useful API Functions: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) |
Cg (Diskussion | Beiträge) |
||
(70 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
This document lists most useful (and most often needed) classes and functions. |
This document lists most useful (and most often needed) classes and functions. |
||
Be aware, that there are many more to be found in either the class references or via the builtin class browser. |
Be aware, that there are many more to be found in either the class references or via the builtin [[Tools_ClassBrowser/en | class browser]]. |
||
== [[String API Functions | String]] == |
== [[String API Functions | String]] == |
||
Strings are sequences of characters. Expecco uses and supports the Unicode encoding standard and supports the whole unicode range. <br>However, not all fonts will contain all characters, resulting in some missing characters being drawn with a replacement char (typically a box-like rectangle) in text windows.<br>The concrete details depend on the operating system and the set of installed fonts. |
|||
All of the following operators are functional operators; meaning that they do not modify |
|||
the argument(s). |
|||
String instances inherit a lot of functionality from String's superclasses: SequenceableCollection and Collection. Thus, all functions found there (enumeration, mapping, filtering, searching etc.) can also be applied to strings. |
|||
==== Literals (i.e. Constant Strings) ==== |
|||
'...' |
|||
::Smalltalk style string (as is; no escapes for special characters). Be aware, that this is inconvenient, if newlines, tabs or other non-graphical characters are to be in the string. |
|||
c'...' |
|||
::C style string (supports the usual C-escapes, such as "\n" for newline, "\t" for tab or "\xHH" for hex codes) |
|||
e'...{expr}...' |
|||
:: C style with embedded expressions. These are evaluated and sliced into the string. |
|||
==== Comparing ==== |
|||
''string1'' = ''string2'' => Boolean |
|||
::compares case sensitive<br> |
|||
''string1'' sameAs: ''string2'' => Boolean |
|||
::compares case insensitive |
|||
==== Case Conversion ==== |
|||
''aString'' asLowercase => String |
|||
<br>''aString'' asUppercase => String |
|||
<br>''aString'' asUppercaseFirst => String |
|||
::return a case converted string |
|||
==== Finding Characters or Substrings ==== |
|||
===== Characters ===== |
|||
''aString'' indexOf: ''aCharacter'' => Integer |
|||
::returns the 1-based index, or 0 if not found.<br> Notice that character constants are denoted as $x in Smalltalk (or "Character return", "Character newline", "Character tab"...) |
|||
''aString'' lastIndexOf: ''aCharacter'' => Integer |
|||
::searching from the end, returns the 1-based index, or 0 if not found. |
|||
''aString'' includes: ''aCharacter'' => Boolean |
|||
::returns true if the character is included |
|||
===== String ===== |
|||
''aString'' indexOfString: ''aSubString'' => Integer |
|||
::returns the 1-based index, or 0 if not found. |
|||
''aString'' indexOfString: ''aSubString'' caseSensitive:''boolean'' => Integer |
|||
::returns the 1-based index, or 0 if not found. |
|||
''aString'' includesString: ''aSubString'' => Boolean |
|||
::returns true if the substring is included |
|||
''aString'' includesString: ''aSubString'' caseSensitive:''boolean'' => Boolean |
|||
::returns true if the substring is included |
|||
==== Concatenation, Splitting and Joining ==== |
|||
''string1'' , ''string2'' (comma operator) => String |
|||
::returns the concatenated string. (i.e. <CODE>'hello' , 'world'</CODE> gives 'helloworld'.) |
|||
''aString'' splitOn: ''aCharacter'' => CollectionOfStrings |
|||
::splits the string into a collection of strings |
|||
''aCollectionOfStrings'' join: ''separator'' => String |
|||
::joins the string, inserting separator. |
|||
Read more: [[String_API_Functions|String API Functions]]<br> |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,String String] |
Reference: [http://live.exept.de/ClassDoc/classDocOf:,String String] |
||
inherits from: [http://live.exept.de/ClassDoc/classDocOf:,CharacterArray CharacterArray] and |
inherits from: [http://live.exept.de/ClassDoc/classDocOf:,CharacterArray CharacterArray] and |
||
Zeile 62: | Zeile 15: | ||
== [[Collection API Functions | Collection]] == |
== [[Collection API Functions | Collection]] == |
||
Collection is an abstract class, serving as a superclass for a number of useful concrete classes (such as Set, Dictionary, Tree, SortedCollection, String etc.) |
|||
It is useful to get a feeling of the set of operations provided there (there are a lot!), so you should not have to reinvent the wheel. |
|||
Read more: [[Collection_API_Functions|Collection API Functions]]<br> |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Collection Collection] |
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Collection Collection] |
||
== [[Filename API Functions | Filename]] == |
== [[Filename API Functions | Filename]] == |
||
Although strings could be used to represent file names and pathes, expecco uses instances of a specialized class called "''Filename''" to represent those. Filename instances know about any details of the underlying operating system (such as the directory separator, any naming restrictions etc.) and also provide a number of useful functions for file and directory access. Filename provides a portable representation, so that code can run on both Windows and Unix unchanged (that is: use "/" in filenames when possible. On a Windows machine, these will be replaced internally by "\" characters). |
|||
Read more: [[Filename_API_Functions|Filename API Functions]]<br> |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Filename Filename] |
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Filename Filename] |
||
== [[Stream API Functions | Stream]] == |
== [[Stream API Functions | Stream]] == |
||
Streams can be internal (eg. reading from a String) or external (eg. a file stream, pipe or socket). |
Streams can be internal (eg. reading from a String) or external (eg. a file stream, pipe or socket). Streams can be used to read bytewiese, character wise (with optional UTF decoding/encoding) or object-wise. |
||
Most uses are with external streams, which are byte or character oriented: FileStream, PipeStream, Socket are examples. |
|||
==== Creating a Stream ==== |
|||
''aString'' readStream => Stream |
|||
:: returns a stream to read from a string |
|||
''aFilenameString'' asFilename readStream => Stream |
|||
:: returns a stream to read the file named aFilenameString |
|||
==== Testing ==== |
|||
''aStream'' atEnd => Boolean |
|||
:: returns true if no more elements are to be read |
|||
==== Reading Characters ==== |
|||
''aStream'' next => Character | nil |
|||
:: returns the next character (as a character) |
|||
''aStream'' next: 'count'' => String |
|||
:: returns the next count characters (as a string) |
|||
''aStream'' nextByte => Integer | nil |
|||
:: returns the next byte (as an integer) |
|||
''aStream'' nextBytes: ''count'' => ByteArray |
|||
:: returns the next count bytes (as a byte array) |
|||
==== Reading Lines ==== |
|||
''aStream'' nextLine => String | nil |
|||
:: returns the next line (up to newLine) as a string |
|||
==== Positioning ==== |
|||
''aStream'' position: ''pos'' => Stream |
|||
:: positions the stream; pos is 0-based (i.e. 0 is the very beginning) |
|||
''aStream'' skip: ''count'' => Stream |
|||
:: positions the stream count elements further (i.e. reads over count elements) |
|||
Read more: [[Stream_API_Functions|Stream API Functions]]<br> |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Stream Stream] |
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Stream Stream] |
||
== [[Number API Functions | |
== [[Number API Functions | Number]] == |
||
Expecco supports a full numeric stack of numbers; both exact (integers and fractions) and inexact (IEEE floats in various precisions). Integer operations do not overflow or loose bits: expecco will automatically choose an appropriate representation to eg. be able to represent huge numbers. |
|||
==== Literals (i.e. Constant Numbers) ==== |
|||
Read more: [[Number_API_Functions|Number API Functions]]<br> |
|||
1234 |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Number Number] and its subclasses |
|||
<br>16rFFAA or 0xaffe |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Integer Integer], |
|||
<br>2r0101 or 0b101010 |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Float Float], |
|||
<br>NrXXX |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Fraction Fraction], |
|||
::integer constant; decimal, hex, binary or any base N; integers may be arbitrary long |
|||
[http://live.exept.de/ClassDoc/classDocOf:,FixedPoint ScaledDecimal], |
|||
0.5 |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Complex Complex] |
|||
<br>1e5 |
|||
<br>-1.2e-3 |
|||
::float constant; actually double precision; use "q" for extra precision |
|||
(4/3) |
|||
:: a fraction (numerator / denominator) |
|||
(4+3i) |
|||
:: complex number (real part / imaginary part) |
|||
== [[Date & Time]] == |
|||
Expecco provides a number of time related support classes: TimeDuration, Time, Date and Timestamp (aka. ''TimeAndDate'') for local, UTC and timezone specific. Although timestamps support picosecond precision, current operating systems will only provide milli or microsecond resolution timestamps. However finer resolution values may come from exact measurement devices or be computed in technical/physical processes. |
|||
Read more: [[Date_and_Time_API_Functions|Date and Time API Functions]]<br> |
|||
Notice: there are no precedence rules for binary operators ('+', '-', '*', etc.) in Smalltalk. All binary operators are evaluated left to right. Use parentheses to specify order. |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Date Date], [http://live.exept.de/ClassDoc/classDocOf:,Time Time], [http://live.exept.de/ClassDoc/classDocOf:,Timestamp Timestamp], [http://live.exept.de/ClassDoc/classDocOf:,UtcTimestamp UtcTimestamp], [http://live.exept.de/ClassDoc/classDocOf:,TZTimestamp TZTimestamp], [http://live.exept.de/ClassDoc/classDocOf:,TimeDuration TimeDuration]. |
|||
== [[PhysicalValues/en|Physical Values]] == |
|||
''number1'' + ''number2'' => Number |
|||
Since 20.1, expecco supports an additional framework to represent physical values, such as mass (in kg), length (in meters), velocity, [[PhysicalValues/en#Acceleration|acceleration]], voltage, electric current etc. |
|||
<br>''number1'' - ''number2'' => Number |
|||
<br>Beside being able to do arithmetic as in <code>3.0 kiloMeter / 20 minutes</code> (which gives "2.5 m/s") they can also be used for conversion between metric and imperial unit systems (eg. "<code>10 nauticalMiles asMeters</code>" gives the answer "18520 m" and "<code>15 inches asMilliMeters</code>" returns "381 mm"). |
|||
<br>''number1'' * ''number2'' => Number |
|||
<br>''number1'' / ''number2'' => Number |
|||
::any combination of types is possible (integer, float, fraction, complex) |
|||
<br>''number1'' // ''number2'' => Number |
|||
::truncating division (truncates towards negative infinity; i.e. the next smaller number) |
|||
<br>''number1'' \\ ''number2'' => Number |
|||
::remainder from above division |
|||
<br>''number1'' quo: ''number2'' => Number |
|||
::truncating division (truncates towards zero; same as "//" for positive numbers) |
|||
<br>''number1'' rem: ''number2'' => Number |
|||
::remainder from quo: (same as "\\" for positive numbers) |
|||
Read more: [[PhysicalValues/en|PhysicalValues]]<br> |
|||
==== Math & Trigonometric Functions ==== |
|||
''aNumber'' ln => Number |
|||
<br>''aNumber'' log10 => Number |
|||
<br>''aNumber'' log2 => Number |
|||
:: logarithm; by default, an error is reported for negative numbers;<br>to get a complex result, use "Complex trapImaginary:[ aNumber ln ]". |
|||
== [[Cryptographic_API_Functions/en | Cryptography]] == |
|||
''aNumber'' sqrt => Number |
|||
:: square root; by default, an error is reported for negative numbers;<br>to get a complex result, use "Complex trapImaginary:[ aNumber sort ]". |
|||
Algorithms for hashing, encryption and decryption, certificate handling etc. |
|||
''aNumber'' cbrt => Number |
|||
:: cubic root. |
|||
Read more: [[Cryptographic_API_Functions/en|Cryptographic API Functions]]<br> |
|||
''aNumber'' exp => Number |
|||
<br>''number1'' raisedTo: ''number2'' => Number |
|||
:: exponentiation |
|||
''aNumber'' sin => Number |
|||
<br>''aNumber'' cos => Number |
|||
<br>''aNumber'' tan => Number |
|||
<br>''aNumber'' arcSin => Number |
|||
<br>''aNumber'' arcCos => Number |
|||
<br>''aNumber'' arcTan => Number |
|||
<br>''aNumber'' arcTan2 => Number |
|||
<br>''aNumber'' sinh => Number |
|||
<br>''aNumber'' cosh => Number |
|||
<br>''aNumber'' tanh => Number |
|||
::trigonometric / hyperbolic functions |
|||
==== Bitwise Operators ==== |
|||
''ínteger1'' bitAnd: ''integer2'' => Integer |
|||
<br>''ínteger1'' bitOr: ''integer2'' => Integer |
|||
<br>''ínteger1'' bitXor: ''integer2'' => Integer |
|||
<br>''ínteger1'' bitShift: ''count'' => Integer |
|||
<br>''ínteger1'' leftShift: ''count'' => Integer |
|||
<br>''ínteger1'' rightShift: ''count'' => Integer |
|||
<br>''ínteger1'' bitTest: ''integer2'' => Boolean |
|||
:: bitwise operations |
|||
Reference: [http://live.exept.de/ClassDoc/classDocOf:,Number Number] and its subclasses |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Integer Integer], |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Float Float], |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Fraction Fraction], |
|||
[http://live.exept.de/ClassDoc/classDocOf:,Complex Complex] |
Aktuelle Version vom 5. Juni 2025, 09:14 Uhr
This document lists most useful (and most often needed) classes and functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.
Inhaltsverzeichnis
String[Bearbeiten]
Strings are sequences of characters. Expecco uses and supports the Unicode encoding standard and supports the whole unicode range.
However, not all fonts will contain all characters, resulting in some missing characters being drawn with a replacement char (typically a box-like rectangle) in text windows.
The concrete details depend on the operating system and the set of installed fonts.
String instances inherit a lot of functionality from String's superclasses: SequenceableCollection and Collection. Thus, all functions found there (enumeration, mapping, filtering, searching etc.) can also be applied to strings.
Read more: String API Functions
Reference: String
inherits from: CharacterArray and
SequenceableCollection and Collection
Collection[Bearbeiten]
Collection is an abstract class, serving as a superclass for a number of useful concrete classes (such as Set, Dictionary, Tree, SortedCollection, String etc.) It is useful to get a feeling of the set of operations provided there (there are a lot!), so you should not have to reinvent the wheel.
Read more: Collection API Functions
Reference: Collection
Filename[Bearbeiten]
Although strings could be used to represent file names and pathes, expecco uses instances of a specialized class called "Filename" to represent those. Filename instances know about any details of the underlying operating system (such as the directory separator, any naming restrictions etc.) and also provide a number of useful functions for file and directory access. Filename provides a portable representation, so that code can run on both Windows and Unix unchanged (that is: use "/" in filenames when possible. On a Windows machine, these will be replaced internally by "\" characters).
Read more: Filename API Functions
Reference: Filename
Stream[Bearbeiten]
Streams can be internal (eg. reading from a String) or external (eg. a file stream, pipe or socket). Streams can be used to read bytewiese, character wise (with optional UTF decoding/encoding) or object-wise. Most uses are with external streams, which are byte or character oriented: FileStream, PipeStream, Socket are examples.
Read more: Stream API Functions
Reference: Stream
Number[Bearbeiten]
Expecco supports a full numeric stack of numbers; both exact (integers and fractions) and inexact (IEEE floats in various precisions). Integer operations do not overflow or loose bits: expecco will automatically choose an appropriate representation to eg. be able to represent huge numbers.
Read more: Number API Functions
Reference: Number and its subclasses
Integer,
Float,
Fraction,
ScaledDecimal,
Complex
Date & Time[Bearbeiten]
Expecco provides a number of time related support classes: TimeDuration, Time, Date and Timestamp (aka. TimeAndDate) for local, UTC and timezone specific. Although timestamps support picosecond precision, current operating systems will only provide milli or microsecond resolution timestamps. However finer resolution values may come from exact measurement devices or be computed in technical/physical processes.
Read more: Date and Time API Functions
Reference: Date, Time, Timestamp, UtcTimestamp, TZTimestamp, TimeDuration.
Physical Values[Bearbeiten]
Since 20.1, expecco supports an additional framework to represent physical values, such as mass (in kg), length (in meters), velocity, acceleration, voltage, electric current etc.
Beside being able to do arithmetic as in 3.0 kiloMeter / 20 minutes
(which gives "2.5 m/s") they can also be used for conversion between metric and imperial unit systems (eg. "10 nauticalMiles asMeters
" gives the answer "18520 m" and "15 inches asMilliMeters
" returns "381 mm").
Read more: PhysicalValues
Cryptography[Bearbeiten]
Algorithms for hashing, encryption and decryption, certificate handling etc.
Read more: Cryptographic API Functions