Category:Tcl: Difference between revisions
Added another very useful link, to the official HTML versions of the documentation |
m update current version |
||
(30 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
{{language|Tcl |
|||
{{language|Tcl|expression=dynamic|compat=duck|checking=dynamic|parampass=value|safety=safe}} |
|||
|site=http://www.tcl.tk/ |
|||
|exec=bytecode |
|||
|express=implicit |
|||
|compat=duck |
|||
|checking=dynamic |
|||
|parampass=value |
|||
|safety=safe |
|||
|strength=weak |
|||
|gc=yes |
|||
|tags=tcl |
|||
|LCT=yes |
|||
|bnf=http://rosettacode.org/wiki/Category:Tcl#Grammar}} |
|||
{{language programming paradigm|Concurrent}} |
|||
{{language programming paradigm|Dynamic}} |
|||
{{language programming paradigm|Event-driven}} |
|||
{{language programming paradigm|Imperative}} |
{{language programming paradigm|Imperative}} |
||
{{language programming paradigm|Object-oriented}} |
{{language programming paradigm|Object-oriented}} |
||
{{language programming paradigm| |
{{language programming paradigm|Procedural}} |
||
{{language programming paradigm|Reflective}} |
{{language programming paradigm|Reflective}} |
||
{{language programming paradigm|Concurrent}} |
|||
{{Codepad}} |
{{Codepad}} |
||
'''Tcl''' (short for '''T'''ool '''C'''ommand '''L'''anguage) |
|||
'''Tcl''' (short for '''T'''ool '''C'''ommand '''L'''anguage) is a scripting language with very simple syntax, dynamic typing, automatic storage allocation and [[garbage collection]] and native Unicode support. '''Tcl''' is often combined with the [[Tk]] library. As a result, it is often referred to as '''Tcl/Tk'''. |
|||
is a scripting language with very simple syntax, dynamic typing, |
|||
automatic storage allocation and [[garbage collection]] |
|||
and native Unicode support. <br> |
|||
'''Tcl''' is often combined with the [[Tk]] library, |
|||
which provides support for graphics and GUI. <br> |
|||
As a result, it is often referred to as '''Tcl/Tk'''. |
|||
Tcl is known to be supported under a variety of popular operating systems, |
Tcl is known to be supported under a variety of popular operating systems, |
||
including [[UNIX]], [[Linux]], [[BSD]], [[Windows]], [[WinCE]], [[PocketPC]], |
|||
[[Mac OS X]] and [[BeOS]]. <br> |
|||
Tcl is distributed under the [[wp:BSD licenses|BSD License]]. |
|||
;Current version: Tcl/Tk 8.6.10 (Nov 21, 2019) |
|||
The Tcl language has been implemented in multiple lower-level languages. The most common one is '''[[libtcl]]''', written in [[C]], which is the engine used to power [[tclsh]] and [[wish]], but others exist. Notably, these include [[Jacl]] and [[Eagle]], which implement Tcl in [[Java]] and [[C sharp|C#]] respectively. |
|||
The Tcl language has been implemented in multiple lower-level languages. |
|||
The most common one is '''[[libtcl]]''', written in [[C]], which is |
|||
the engine used to power [[tclsh]] and [[wish]], but others exist. |
|||
Notably, these include [[Jacl]] and [[Eagle]], which implement |
|||
Tcl in [[Java]] and [[C sharp|C#]] respectively. |
|||
Its creator, John Ousterhout, wrote about it: |
Its creator, John Ousterhout, wrote about it: |
||
:''“I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.”'' |
:''“I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.”'' |
||
The principal pre-built distributions of Tcl are all based on [[libtcl]]; |
|||
the main ones are - besides those in the repositories of Linux and BSD Unices, which are usually current - [[ActiveTcl]] from ActiveState (for several platforms including Windows), BAWT http://www.bawt.tcl3d.org/ (for several platforms including Windows and Mac), Magicsplat http://www.magicsplat.com/tcl-installer/index.html (Windows), |
|||
and [[tclkit]] from Equi4 Software ''et al''. <br> |
|||
Older versions of the language (8.5) are distributed as part of Apple's OS X. |
|||
==Language Syntax== |
|||
===Grammar=== |
|||
Note that this is a simplified language grammar, and it is normal |
|||
to think of the language at a higher level where these differences don't show. |
|||
<br clear=all> |
|||
script '''::=''' command'''? ((''' “''\n''” '''|''' “'';''” ''')''' script ''')''' |
|||
command '''::=''' “''#''” characters “''\n''” <span style="color:grey">/* comment */</span> |
|||
'''|''' word '''(''' space word ''')*''' <span style="color:grey">/* sequence of space-separated words; |
|||
* first is command name */</span> |
|||
'''|''' <span style="color:grey">/* empty */</span> |
|||
word '''::=''' “''{*}''”'''?''' “''{''” characters “''}''” <span style="color:grey">/* braces must be balanced */</span> |
|||
'''|''' “''{*}''”'''?''' “''"''” charSubsts “''"''” <span style="color:grey">/* double-quotes must be balanced */</span> |
|||
'''|''' “''{*}''”'''?''' charSubsts |
|||
charSubsts '''::=''' “''[''” script “'']''” charSubsts'''?''' <span style="color:grey">/* brackets must be balanced */</span> |
|||
'''|''' “''$''” varName charSubsts'''?''' |
|||
'''|''' “''${''” varName “''}''” charSubsts'''?''' |
|||
'''|''' “''\\''” escapeSequence charSubsts''?'' |
|||
'''|''' ordinaryChar charSubsts''?'' |
|||
The syntax of the language is defined more exactly in the [http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm Tcl(n)] manual page. |
|||
===Conceptual Command Syntax=== |
|||
Though formally not part of the language syntax, the syntactic style of the language's standard commands mostly follow a few basic syntactic principles: |
|||
* Commands are variadic, and frequently accept arbitrary numbers of arguments. |
|||
* Commands that take options will prefix the option name with a single ASCII hyphen, “-”, and if a value parameter to the option is required, that parameter will be in a subsequent argument to the option name. |
|||
* Option names are not single character long strings after removing the hyphen (except in rare cases) and <code>getopt</code>-style argument combination is never supported. |
|||
* Commands perform callbacks by evaluating a caller-provided Tcl script. |
|||
** During-execution callback scripts are evaluated in the context of their caller. |
|||
** After-execution callback scripts are evaluated in the global scope. |
|||
* Commands cannot discover how their arguments were quoted. |
|||
===Key Commands=== |
|||
The following commands are simply normal commands, and can be renamed, deleted, traced, etc., just like any other command, but they are also used in virtually all Tcl scripts and so overriding their behavior is typically an indication of code that is likely to fail. (People do that anyway, but they are almost always careful to ensure that the existing semantics of the commands with these names are still supported.) |
|||
'''set''' ''varName'' ?''value''? |
|||
:Sets a named variable to a value and returns the current value of the variable. If ''value'' is omitted, reads from the variable. |
|||
'''expr''' ''arg''... |
|||
:Concatenates the ''arg''uments and evaluates them as an expression. |
|||
'''if''' ''expr'' ?'''then'''? ''script'' ?'''elseif''' ''expr'' ?'''then'''? ''script'' ...? ?'''else'''? ?''script''? |
|||
:Evaluates expressions in order until one of them yields a true value, and then evaluate the associated script, or evaluate the script from the '''else''' clause otherwise. The '''then''' and '''else''' keyword-arguments are both optional, but it is conventional to always include the '''else''' for readability ('''then''' only tends to be used with multiline conditions). Arbitrarily many '''elseif''' clauses are allowed. |
|||
'''switch''' ?''options''? ''value'' ''body''<br>'''switch''' ?''options''? ''value'' ''val1'' ''script'' ?''val2'' ''script'' ...? |
|||
:Finds the first ''val''n that matches ''value'' (the default matching rule is exact equality, this is overrideable using the ''options'') and evaluate its script. The final ''val'' can be '''default''' to supply a catch-all case, and if a ''script'' is a '''-''' then the ''script'' from the following clause is used. If a single ''body'' is supplied, it is interpreted as a list of clauses. |
|||
'''while''' ''expr script'' |
|||
:While the expression evaluates to true, evaluate the ''script''. |
|||
'''for''' ''init expr incr script'' |
|||
:Evaluate the ''init'' script, and then while the expression evaluates to true, evaluate the ''script'', evaluating the ''incr'' script after each iteration. This is very similar to [[C]]'s <code>for</code> keyword. |
|||
'''foreach''' ''varName list script''<br> |
|||
'''foreach''' ''varNameList list'' ?''varNameList list'' ...? ''script'' |
|||
:Evaluate the ''script'' for each value in ''list'', setting ''varName'' to that value. In the more general case, there is more than one ''list'' and there are multiple variable names per list allowing striding. |
|||
'''break''' |
|||
:Make the current loop finish executing early. |
|||
'''continue''' |
|||
:Make the next iteration of the current loop start early. |
|||
'''error''' ''message'' ... |
|||
:Generate an error exception. The additional optional arguments allow finer control over the exception. |
|||
'''eval''' ''arg''... |
|||
:Concatenate the arguments and evaluate the resulting string as a script. Note that from Tcl 8.5 onwards, this should only be used very rarely; the expansion syntax covers the vast majority of previous uses for '''eval'''. |
|||
'''list''' ''arg''... |
|||
:Create a list out of the arguments and return it. The resulting list is also guaranteed to be a well-formed script that will evaluate the sequence of arguments as a command and arguments without further substitution, making the '''list''' command useful for predictable code synthesis. |
|||
'''proc''' ''name formalArgs body'' |
|||
:Define a new command called ''name'' that pushes a new stack frame, accepts arguments and binds them to the list of local variable names given in ''formalArgs'' and then evaluates ''body''. |
|||
'''return''' ?''options''? ?''value''? |
|||
:Return from the current stack frame with the given ''value'' (or the empty string if that's omitted). The ''options'' allow for greater control of the underlying exception semantics used. |
|||
'''catch''' ''body'' ?''varName''? ?''optVarName''? |
|||
:Evaluate the ''body'' script, and return the exception status produced (e.g., 0 for no exception). If ''varName'' is given, the result or error message is stored in it. If ''optVarName'' is present (from Tcl 8.5 onwards) then a dictionary characterizing the exception status is stored in it. |
|||
'''upvar''' ?''level''? ''otherVarName localVarName'' ?''otherVarName localVarName'' ...? |
|||
:Bind each of the ''otherVarName'' variables (as looked up at stack level ''level'', or the parent stack frame of the current procedure if that is omitted) to the corresponding ''localVarName''. Following this, the two refer to the same variable until the termination of the current stack frame. |
|||
'''uplevel''' ?''level''? ''arg''... |
|||
:Concatenate the arguments and evaluate them as a script in the stack frame given by ''level'' (or the stack frame that called the current procedure if that is omitted). Due to syntactic ambiguities, it is recommended that the ''level'' always be specified explicitly. |
|||
==== From Tcl 8.5 ==== |
|||
'''apply''' ''lambdaTerm arg…'' |
|||
:Applies a lambda term to zero or more arguments. Lambda terms are two- or three-element tuples, the first element being the formal parameter description, the second being the script that implements the lambda (just as with '''proc''') and the optional third being the context namespace (with the default being the global namespace). |
|||
'''dict''' ''subcommand'' … |
|||
:Manipulates dictionaries, values that describe a (sparse) mapping from arbitrary keys to arbitrary values (well, so long as both are themselves values). |
|||
==== From Tcl 8.6 ==== |
|||
'''coroutine''' ''name command arg…'' |
|||
:Create a coroutine called ''name'', which is implemented by the execution of ''command'' together with any supplied arguments. The ''name'' is the name of a command that will be used to resume the coroutine. |
|||
'''yield''' ?''value''? |
|||
:Yield from a coroutine, with optional value (empty if not supplied). Result will be the optional resumption argument to the coroutine's command. |
|||
'''tailcall''' ''command arg…'' |
|||
:Stops the execution of the current context and replaces it with a call to the given ''command'' with any arguments. |
|||
'''oo::class create''' ''name body'' |
|||
:Creates a class called ''name'' with definition ''body''. Instances of ''name'' are created with “''name'' '''new''' ''arg…''” and “''name'' '''create''' ''instanceName arg…''”. (Note that the syntax for '''oo::class''' is a consequence of this.) |
|||
==Language Semantics== |
|||
===Value Model=== |
|||
Tcl's value model operates on two levels. |
|||
* Classically, it is defined purely on unmodifiable strings over a language of unencoded [[UNICODE]] characters. |
|||
* Practically, values are polymorphic and hold a cache of the last type-interpretation that they were used with, together with an optional [[UTF-8]] string representation. They are reference-counted and are not modifiable (unless the code in question holds the only reference, which is a significant efficiency gain; if the value is shared, it is shallow-copied upon modification). Although only reference-counted, they are effectively garbage-collected since circular data structures cannot be constructed (performing such construction requires holding two references to the same object, which forces a copy to be taken and breaks the reference loop). The net effect of this is just like the UNICODE string classical model, except much faster. |
|||
The language supports the following basic types, together with many defined by extension packages: |
|||
* Unicode strings |
|||
* Binary strings |
|||
* Integers of unbounded width |
|||
* Double-precision [[IEEE]] floats |
|||
* Booleans |
|||
* Lists of values |
|||
* Dictionaries mapping values to values |
|||
* Assorted "cache" types used to boost performance: |
|||
** Command handles (several types) |
|||
** Variable handles (several types) |
|||
** Compiled regular expressions |
|||
** Compiled scripts (several types) |
|||
** etc. |
|||
Note that all variables can hold values of ''any'' type; the language does not impose type constraints on variables at all. However, it is possible to use variable traces to enforce a type constraint if so desired. |
|||
==External Links== |
==External Links== |
||
*[http://www.tcl. |
*[http://www.tcl-lang.org/man/ Tcl Documentation] |
||
*[http://wiki.tcl. |
*[http://wiki.tcl-lang.org Tcl Wiki] |
||
*[http://en.wikipedia.org/wiki/Tcl Wikipedia article] |
*[http://en.wikipedia.org/wiki/Tcl Wikipedia article] |
||
*[http://en.wikibooks.org/wiki/Programming:Tcl Wikibook] |
|||
==Todo== |
|||
[[Reports:Tasks_not_implemented_in_Tcl]] |
Latest revision as of 13:59, 4 October 2020
![Language](http://static.miraheze.org/rosettacodewiki/thumb/2/27/Rcode-button-language-crushed.png/64px-Rcode-button-language-crushed.png)
This programming language may be used to instruct a computer to perform a task.
Official website |
---|
Execution method: | Compiled (bytecode) |
---|---|
Garbage collected: | Yes |
Parameter passing methods: | By value |
Type safety: | Safe |
Type strength: | Weak |
Type compatibility: | Duck |
Type expression: | Implicit |
Type checking: | Dynamic |
Lang tag(s): | tcl |
See Also: |
Tcl (short for Tool Command Language)
is a scripting language with very simple syntax, dynamic typing,
automatic storage allocation and garbage collection
and native Unicode support.
Tcl is often combined with the Tk library,
which provides support for graphics and GUI.
As a result, it is often referred to as Tcl/Tk.
Tcl is known to be supported under a variety of popular operating systems,
including UNIX, Linux, BSD, Windows, WinCE, PocketPC,
Mac OS X and BeOS.
Tcl is distributed under the BSD License.
- Current version
- Tcl/Tk 8.6.10 (Nov 21, 2019)
The Tcl language has been implemented in multiple lower-level languages. The most common one is libtcl, written in C, which is the engine used to power tclsh and wish, but others exist. Notably, these include Jacl and Eagle, which implement Tcl in Java and C# respectively.
Its creator, John Ousterhout, wrote about it:
- “I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.”
The principal pre-built distributions of Tcl are all based on libtcl;
the main ones are - besides those in the repositories of Linux and BSD Unices, which are usually current - ActiveTcl from ActiveState (for several platforms including Windows), BAWT http://www.bawt.tcl3d.org/ (for several platforms including Windows and Mac), Magicsplat http://www.magicsplat.com/tcl-installer/index.html (Windows),
and tclkit from Equi4 Software et al.
Older versions of the language (8.5) are distributed as part of Apple's OS X.
Language Syntax
Grammar
Note that this is a simplified language grammar, and it is normal
to think of the language at a higher level where these differences don't show.
script ::= command? (( “\n” | “;” ) script ) command ::= “#” characters “\n” /* comment */ | word ( space word )* /* sequence of space-separated words; * first is command name */ | /* empty */ word ::= “{*}”? “{” characters “}” /* braces must be balanced */ | “{*}”? “"” charSubsts “"” /* double-quotes must be balanced */ | “{*}”? charSubsts charSubsts ::= “[” script “]” charSubsts? /* brackets must be balanced */ | “$” varName charSubsts? | “${” varName “}” charSubsts? | “\\” escapeSequence charSubsts? | ordinaryChar charSubsts?
The syntax of the language is defined more exactly in the Tcl(n) manual page.
Conceptual Command Syntax
Though formally not part of the language syntax, the syntactic style of the language's standard commands mostly follow a few basic syntactic principles:
- Commands are variadic, and frequently accept arbitrary numbers of arguments.
- Commands that take options will prefix the option name with a single ASCII hyphen, “-”, and if a value parameter to the option is required, that parameter will be in a subsequent argument to the option name.
- Option names are not single character long strings after removing the hyphen (except in rare cases) and
getopt
-style argument combination is never supported. - Commands perform callbacks by evaluating a caller-provided Tcl script.
- During-execution callback scripts are evaluated in the context of their caller.
- After-execution callback scripts are evaluated in the global scope.
- Commands cannot discover how their arguments were quoted.
Key Commands
The following commands are simply normal commands, and can be renamed, deleted, traced, etc., just like any other command, but they are also used in virtually all Tcl scripts and so overriding their behavior is typically an indication of code that is likely to fail. (People do that anyway, but they are almost always careful to ensure that the existing semantics of the commands with these names are still supported.)
set varName ?value?
- Sets a named variable to a value and returns the current value of the variable. If value is omitted, reads from the variable.
expr arg...
- Concatenates the arguments and evaluates them as an expression.
if expr ?then? script ?elseif expr ?then? script ...? ?else? ?script?
- Evaluates expressions in order until one of them yields a true value, and then evaluate the associated script, or evaluate the script from the else clause otherwise. The then and else keyword-arguments are both optional, but it is conventional to always include the else for readability (then only tends to be used with multiline conditions). Arbitrarily many elseif clauses are allowed.
switch ?options? value body
switch ?options? value val1 script ?val2 script ...?
- Finds the first valn that matches value (the default matching rule is exact equality, this is overrideable using the options) and evaluate its script. The final val can be default to supply a catch-all case, and if a script is a - then the script from the following clause is used. If a single body is supplied, it is interpreted as a list of clauses.
while expr script
- While the expression evaluates to true, evaluate the script.
for init expr incr script
- Evaluate the init script, and then while the expression evaluates to true, evaluate the script, evaluating the incr script after each iteration. This is very similar to C's
for
keyword.
foreach varName list script
foreach varNameList list ?varNameList list ...? script
- Evaluate the script for each value in list, setting varName to that value. In the more general case, there is more than one list and there are multiple variable names per list allowing striding.
break
- Make the current loop finish executing early.
continue
- Make the next iteration of the current loop start early.
error message ...
- Generate an error exception. The additional optional arguments allow finer control over the exception.
eval arg...
- Concatenate the arguments and evaluate the resulting string as a script. Note that from Tcl 8.5 onwards, this should only be used very rarely; the expansion syntax covers the vast majority of previous uses for eval.
list arg...
- Create a list out of the arguments and return it. The resulting list is also guaranteed to be a well-formed script that will evaluate the sequence of arguments as a command and arguments without further substitution, making the list command useful for predictable code synthesis.
proc name formalArgs body
- Define a new command called name that pushes a new stack frame, accepts arguments and binds them to the list of local variable names given in formalArgs and then evaluates body.
return ?options? ?value?
- Return from the current stack frame with the given value (or the empty string if that's omitted). The options allow for greater control of the underlying exception semantics used.
catch body ?varName? ?optVarName?
- Evaluate the body script, and return the exception status produced (e.g., 0 for no exception). If varName is given, the result or error message is stored in it. If optVarName is present (from Tcl 8.5 onwards) then a dictionary characterizing the exception status is stored in it.
upvar ?level? otherVarName localVarName ?otherVarName localVarName ...?
- Bind each of the otherVarName variables (as looked up at stack level level, or the parent stack frame of the current procedure if that is omitted) to the corresponding localVarName. Following this, the two refer to the same variable until the termination of the current stack frame.
uplevel ?level? arg...
- Concatenate the arguments and evaluate them as a script in the stack frame given by level (or the stack frame that called the current procedure if that is omitted). Due to syntactic ambiguities, it is recommended that the level always be specified explicitly.
From Tcl 8.5
apply lambdaTerm arg…
- Applies a lambda term to zero or more arguments. Lambda terms are two- or three-element tuples, the first element being the formal parameter description, the second being the script that implements the lambda (just as with proc) and the optional third being the context namespace (with the default being the global namespace).
dict subcommand …
- Manipulates dictionaries, values that describe a (sparse) mapping from arbitrary keys to arbitrary values (well, so long as both are themselves values).
From Tcl 8.6
coroutine name command arg…
- Create a coroutine called name, which is implemented by the execution of command together with any supplied arguments. The name is the name of a command that will be used to resume the coroutine.
yield ?value?
- Yield from a coroutine, with optional value (empty if not supplied). Result will be the optional resumption argument to the coroutine's command.
tailcall command arg…
- Stops the execution of the current context and replaces it with a call to the given command with any arguments.
oo::class create name body
- Creates a class called name with definition body. Instances of name are created with “name new arg…” and “name create instanceName arg…”. (Note that the syntax for oo::class is a consequence of this.)
Language Semantics
Value Model
Tcl's value model operates on two levels.
- Classically, it is defined purely on unmodifiable strings over a language of unencoded UNICODE characters.
- Practically, values are polymorphic and hold a cache of the last type-interpretation that they were used with, together with an optional UTF-8 string representation. They are reference-counted and are not modifiable (unless the code in question holds the only reference, which is a significant efficiency gain; if the value is shared, it is shallow-copied upon modification). Although only reference-counted, they are effectively garbage-collected since circular data structures cannot be constructed (performing such construction requires holding two references to the same object, which forces a copy to be taken and breaks the reference loop). The net effect of this is just like the UNICODE string classical model, except much faster.
The language supports the following basic types, together with many defined by extension packages:
- Unicode strings
- Binary strings
- Integers of unbounded width
- Double-precision IEEE floats
- Booleans
- Lists of values
- Dictionaries mapping values to values
- Assorted "cache" types used to boost performance:
- Command handles (several types)
- Variable handles (several types)
- Compiled regular expressions
- Compiled scripts (several types)
- etc.
Note that all variables can hold values of any type; the language does not impose type constraints on variables at all. However, it is possible to use variable traces to enforce a type constraint if so desired.
External Links
Todo
Subcategories
This category has the following 4 subcategories, out of 4 total.
@
- Tcl Implementations (11 P)
- Tcl User (40 P)
T
Pages in category "Tcl"
The following 200 pages are in this category, out of 983 total.
(previous page) (next page)P
- Parameterized SQL statement
- Parse an IP Address
- Parse command-line arguments
- Parse EBNF
- Parsing/RPN calculator algorithm
- Parsing/RPN to infix conversion
- Parsing/Shunting-yard algorithm
- Partial function application
- Pascal matrix generation
- Pascal's triangle
- Pascal's triangle/Puzzle
- Penney's game
- Pentagram
- Percentage difference between images
- Percolation/Bond percolation
- Percolation/Mean cluster density
- Percolation/Mean run density
- Percolation/Site percolation
- Perfect numbers
- Perfect shuffle
- Perfect totient numbers
- Perlin noise
- Permutation test
- Permutations
- Permutations by swapping
- Permutations with repetitions
- Permutations/Derangements
- Permutations/Rank of a permutation
- Pernicious numbers
- Phrase reversals
- Pi
- Pick random element
- Pig the dice game
- Pig the dice game/Player
- Pinstripe/Display
- Pinstripe/Printer
- Play recorded sounds
- Playfair cipher
- Playing cards
- Plot coordinate pairs
- Pointers and references
- Poker hand analyser
- Polymorphic copy
- Polymorphism
- Polynomial long division
- Polynomial regression
- Polynomial synthetic division
- Population count
- Power set
- Pragmatic directives
- Price fraction
- Primality by trial division
- Prime decomposition
- Primes whose sum of digits is 25
- Priority queue
- Probabilistic choice
- Problem of Apollonius
- Process SMIL directives in XML data
- Program name
- Program termination
- Proof
- Proper divisors
- Pseudo-random numbers/Middle-square method
- Pseudo-random numbers/PCG32
- Pythagorean triples
R
- Ramsey's theorem
- Random number generator (device)
- Random number generator (included)
- Random numbers
- Range expansion
- Range extraction
- Ranking methods
- Rate counter
- Ray-casting algorithm
- RCRPG
- Read a configuration file
- Read a file character by character/UTF8
- Read a file line by line
- Read a specific line from a file
- Read entire file
- Real constants and functions
- Record sound
- Reduced row echelon form
- Reflection/Get source
- Reflection/List methods
- Reflection/List properties
- Regular expressions
- Remote agent/Agent interface
- Remote agent/Agent logic
- Remote agent/Simulation
- Remove duplicate elements
- Remove lines from a file
- Rename a file
- Rendezvous
- Rep-string
- Repeat
- Repeat a string
- Resistor mesh
- Respond to an unknown method call
- Retrieve and search chat history
- Return multiple values
- Reverse a string
- Reverse the gender of a string
- Reverse words in a string
- RIPEMD-160
- Rock-paper-scissors
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a function
- Roots of a quadratic function
- Roots of unity
- Rosetta Code/Count examples
- Rosetta Code/Find bare lang tags
- Rosetta Code/Find unimplemented tasks
- Rosetta Code/Fix code tags
- Rosetta Code/Rank languages by popularity
- Rosetta Code/Run examples
- Rot-13
- RSA code
- Run as a daemon or service
- Run-length encoding
- Runge-Kutta method
- Runtime evaluation
- Runtime evaluation/In an environment
S
- S-expressions
- Safe addition
- Sailors, coconuts and a monkey problem
- Same fringe
- Scope modifiers
- Scope/Function names and labels
- Search a list
- Search a list of records
- Secure temporary file
- SEDOLs
- Self-describing numbers
- Semiprime
- Semordnilap
- Send an unknown method call
- Send email
- Separate the house number from the street name
- Sequence of non-squares
- Sequence of primes by trial division
- Sequence: smallest number with exactly n divisors
- Set
- Set consolidation
- Set of real numbers
- Set puzzle
- Seven-sided dice from five-sided dice
- SHA-1
- SHA-256
- Shell one-liner
- Short-circuit evaluation
- Shortest common supersequence
- Show ASCII table
- Show the epoch
- Sierpinski carpet
- Sierpinski triangle
- Sierpinski triangle/Graphical
- Sieve of Eratosthenes
- Simple database
- Simple windowed application
- Simulate input/Keyboard
- Simulate input/Mouse
- Singleton
- Singly-linked list/Element definition
- Singly-linked list/Element insertion
- Singly-linked list/Traversal
- Sleep
- Smith numbers
- SOAP
- Sockets
- Sokoban
- Solve a Hidato puzzle
- Solve a Holy Knight's tour
- Solve a Hopido puzzle
- Solve a Numbrix puzzle
- Solve the no connection puzzle
- Sort a list of object identifiers
- Sort an array of composite structures
- Sort an integer array
- Sort disjoint sublist
- Sort numbers lexicographically
- Sort stability
- Sort three variables
- Sort using a custom comparator
- Sorting algorithms/Bead sort
- Sorting algorithms/Bogosort
- Sorting algorithms/Bubble sort
- Sorting algorithms/Cocktail sort
- Sorting algorithms/Comb sort
- Sorting algorithms/Counting sort
- Sorting algorithms/Cycle sort
- Sorting algorithms/Gnome sort
- Sorting algorithms/Heapsort
- Execution method/Compiled/Bytecode
- Garbage collection/Yes
- Parameter passing/By value
- Typing/Safe
- Typing/Weak
- Typing/Compatibility/Duck
- Typing/Expression/Implicit
- Typing/Checking/Dynamic
- Programming Languages
- Programming paradigm/Concurrent
- Programming paradigm/Dynamic
- Programming paradigm/Event-driven
- Programming paradigm/Imperative
- Programming paradigm/Object-oriented
- Programming paradigm/Procedural
- Programming paradigm/Reflective
- Codepad languages