(toiminnot)

hwechtla-tl: Seminaari esoteerisista ohjelmointikielistä

Kierre.png

Mikä on WikiWiki?
nettipäiväkirja
koko wiki (etsi)
viime muutokset


More information at: https://wiki.helsinki.fi/display/lambda/esoteeriset+ohjelmointikielet

The presentation in the evening school: http://members.sange.fi/~atehwa/slides/esoteric.html

Weekly assignments #2

Underload is a minimalistic, stack-based language with first-class functions but without named functions or any kind of iteration constructs. An underload program is a series of commands that make modifications to an internal stack of values. The commands are represented by specific characters (for instance, "!" is a command to drop the top value of the internal stack), so a program is a string of command characters. The values on the stack are strings, too, and a value can be a program if it only contains command characters. There is a command ("^") to execute the top value on the stack as part of your program; this is the only flow control construct in the language.

The specific commands are documented here: http://esoteric.voxelperfect.net/files/underload/underload.html

Here is a simple program that outputs "Hello, nice nice world":

(world)(Hello, )(nice ):**~*S

Explanation: (world) pushes the string "world" on the stack, similarly for (Hello, ) and (nice ). After these commands, the Stack contains the following values (top of stack, or TOS, on the right):

(world), (Hello, ), (nice )

The ":" command duplicates the TOS, so that the stack becomes:

(world), (Hello, ), (nice ), (nice )

The "*" command concatenates the TOS and STOS (second-to-top of stack), so the stack turns into these with two "*" commands:

(world), (Hello, ), (nice nice )
(world), (Hello, nice nice )

The "~" command swaps TOS with STOS, so "~*" mutates the stack into:

(Hello, nice nice ), (world)
(Hello, nice nice world)

The "S" command pops and outputs the TOS, printing "Hello, nice nice world".

This is a complete table of program states, with stack states on the left and program remaining to be executed on the right:

Stack                                   Program
                                        (world)(Hello, )(nice ):**~*S
(world)                                 (Hello, )(nice ):**~*S
(world), (Hello, )                      (nice ):**~*S
(world), (Hello, ), (nice )             :**~*S
(world), (Hello, ), (nice ), (nice )    **~*S
(world), (Hello, ), (nice nice )        *~*S
(world), (Hello, nice nice )            ~*S
(Hello, nice nice ), (world)            *S
(Hello, nice nice world)                S

As another example, here is an explanation of how the infinite loop works:

(:^):^

After "(:^)", the TOS is the program ":^". Then when ":" is executed, the TOS is duplicated and stack contains the following values:

(:^), (:^)

Now the final command "^" takes one of these and executes it as a program. Now the program to be executed is ":^" and the stack contains:

(:^)

The ":" command duplicates, again, the TOS, so that the stack contains:

(:^), (:^)

After this, the "^" command will again pop and execute one of these, and the process repeats.

This is a complete table of program states for the infinite loop program:

Stack           Program
                (:^):^Wont-reach-this
(:^)            :^Wont-reach-this
(:^), (:^)      ^Wont-reach-this
(:^)            :^Wont-reach-this
(:^), (:^)      ^Wont-reach-this
...

  1. In Underload, implement a program that outputs an increasing series of asterisks: the first output line reads "*", the second reads "**", the third one reads "***", and so on.
  2. Why is Underload Turing-equivalent (as expressive as a Turing Machine), even though it only has one stack of values, not two, as needed to emulate an infinite tape?
  3. Special assignment (in that it is quite advanced): devise a way to express a pair in Underload. A pair is a data type that has two members that are arbitrary values, and you can fetch either of those members from it with different operations. More precisely, show a string p containg two arbitrary substrings x and y, and two programs first and second, such that the TOS changes from p to x by executing the program first, and from p to y by executing the program second.

As before, you can send your solutions to the lecturer (atehwa at iki fi) if you want feedback, fame, or a comparison of your solution with others'.

Weekly assignments #1

Circute is a very simple cellular automaton. In Circute, "sparks" (#) spread in "wires" (=), and there are also "gates" (N), which send out sparks (to wires over and under them), except when they're surrounded by sparks from both sides (right and left), in which case they send out "spark erasers" (-). Essentially the automaton consists of the following rewrite rules (along with the symmetric and rotated rules):

#=   ->   ##       e.g.    ####====  ->  #####===

-#   ->   =-       e.g.    ===-####  ->  ====-###

=N=  ->  =N=       #N#  ->  #N#
 =        #         #        -

#N=  ->  #N=       =N#  ->  =N#
 =        #         =        #

The exact rewrite rules can be checked in Circute's Alpaca definition: http://catseye.tc/projects/circute/src/circute.alp

For example, here we have a NOT gate. The inputs are marked with stars (*), that is to say, you have to replace the stars with sparks or wires according to whether the boolean value of the input is true (spark) or false (wire). The result will be on the lowest line when no rewrite rule can no longer be applied to the automaton.

  *
 ===
 = =
 =N=
  =

  1. Implement a XOR gate with Circute in a similar manner.
  2. Can Circute be used to implement any algorithm? Why?
  3. Can Circute be used to simulate any digital circuit? Why? (More information about digital circuits: http://en.wikibooks.org/wiki/Digital_Circuits)
  4. Special assignment (in that it is very ill-defined): In Circute, implement some oscillators and sync them in order to produce an audio signal with a complex harmonic structure.

You can send your solutions to the lecturer (atehwa at iki fi) if you want feedback, fame, or a comparison of your solution with others'.

Yhteistyötahot

Kysyttyjä / tiedottavia:

Historiallisesti tai aiheeltaan tärkeitä kieliä


kategoria: projektit


Pikalinkit:


kommentoi (viimeksi muutettu 25.10.2011 13:25)