Oneliner
Jump to navigation
Jump to search
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
Designed by | Matrus |
---|---|
Appeared in | 2024 |
Dimensions | one-dimensional |
Computational class | Turing complete |
Reference implementation | |
File extension(s) | .olr |
Oneliner is a esoteric programming language, where every program is supposed to have only one line. Every program with more than 1 line has a one-line version. Newlines are not ignored.
Overview
Oneliner is based on 3 objects: C, c and V. C (stands for Code) is the main object. It can execute code and store variables. c (stands for code) is a predefined Code object. V (stands for Value) is a non-constant value.
Oneliner uses the build technique, where blocks are added one-by-one and then executed at the same time.
Syntax
Here's how to write programs using Oneliner:
Code | Description | Pseudo-code |
---|---|---|
C() | Initialize a new Code object | Code() |
c() | Get variable enviroment | code.variables |
c()["varname"] or c["varname"] | Get the value of a variable | varname |
c()["varname",123] | Set the value of a variable | varname = 123 |
c().g("varname") | The function version of c()[...] | varname |
c().s("varname",123) | The function version of c()[..., ...] | varname = 123 |
c()() | Go back to Code | code.variables.code |
c[function,(1,2,3),{"a":45}] | Add a block | code.addBlock(function(1, 2, 3, a=4)) |
c(1) | Execute all blocks and clear the build | code.executeBlocks(clear=True) |
c.lr | The return value from the latest executed block | code.lastReturn |
c.glr() | The function version of c.lr | code.getLastReturn() |
c.b() | Execute all blocks without clearing the build | code.executeBlock(clear=False) |
c.c() | Clear the build | code.blocks = [] |
c.f() | Create a function copy of the Code object with fixed blocks | code.asFunction() |
c.i(C()[boolean,(1,),{}].f(),print,("Test",),{}) | Add an if statement to the build | code.addBlock( if(boolean(1)) { print("Test") } ) |
c.ii(...) | Run an if statement without adding it to the build | if(boolean(1)) { print("Test") } |
c.ie(C()[boolean,(1,),{}].f(),print,exit,(1,),{}) | Add an if-else statement to the build | code.addBlock( if(boolean(1)) { print(1) } else { exit(1) } ) |
c.iie(...) | Run an if-else statement without adding it to the build | if(boolean(1)) { print(1) } else { exit(1) } |
The rest will be added soon.
Examples
Hello, World!
Here's a simple one:
c[print,("Hello, World!",),{}](1)
Explanation:
c[ Add a block to the build print, The function to be called ("Hello, World!",), Positional arguments {} Keyword arguments ] Block end (1) Execute and clear the build
Truth-machine
Oneliner:
c()["i",num(input())]()[print,("1",),{}].ie(C()[boolean,(c["i"])].f(),c.b,c.c,(),{}).iie(C()[boolean,(c["i"])].f(),c.b,c.c,(),{})
Explanation:
1) Input is saved to i as a number: c()["i",num(input())] 2) Print 1 is added to the build: ()[print,("1",),{}] 3) Continue the loop by executing the build if i is 1: .ie(C()[boolean,(c["i"])].f(),c.b,c.c,(),{}) 4) Start the loop with an instant if-else: .iie(C()[boolean,(c["i"])].f(),c.b,c.c,(),{})
Note
This article is about 30 or so percent done. It will be updated later.
- Feel free to edit this article.