The Risky programming language

Related tags

Security risky
Overview

Risky

Risky is a programming language designed as a proof-of-concept. Risky features a (to my knowledge) original form of what could loosely be called tacit programming.

Risky's operators are overloaded, both by type and arity. It uses a 4-bit code page, so only 16 operators are available.

Basics

In most golfing languages, operators (called atoms or functions in some languages) form a sort of tree of arguments. Take, for example, the program 1+_2 in a language where _ is negate (prefix), and + is add (infix). You could draw this with the following tree:

  +
 / \
1   _
    |
    2

With Risky, things work a bit different. Parsing works like this:

  1. If the program consists of a single operator, it is a nilad
  2. If the program consists of an even number of operators, the first operator is a monad
  3. Otherwise, the middle operator is a dyad

For case 2, the remaining operators are treated as a program and given as an argument, and for case 3 both remaining halves are given as arguments.

Take the Risky program */2*11-. This is 7 operators long, so * is parsed as a dyad. This splits the program into two arguments to multiply: */2, and 11-. Both are still odd, so */2 becomes / with * and 2 as arguments, and 11- becomes 1 with 1 and - as arguments.

You'll notice that * and 1 have been used as both dyads and nilads in this program. This is the main advantage Risky has for golfing; nilads can be overloaded onto the same operators as monads and dyads, reducing the number of operators required by a significant amount. This is how Risky can get away with having just 16 operators.

This system does have some disadvantages, which makes a small number of operators even more important. Due to the way Risky's dyads work, symmetry is often required. If you were to try to port the 1+_2 program from above into Risky, you would run into a problem. To add numbers, you would use +. However, this needs to be in the center of the program for it to be parsed correctly. On the right side you would have -2 (negation monad and nilad 2), but on the left side you only need 1. In order to maintain symmetry, an extra _ monad (identity) is required.

The resulting program, _1+-2, is one operator longer. With small programs this isn't very significant, but under certain conditions large programs can become much longer. Specifically, Risky programs are optimal when the tree you draw for it is close to symmetrical. Look at these two (pseudocode) programs:

       +
     /   \
   +       +
  / \     / \
 x   x   x   x
      +
     / \
    x   +
       / \
      x   +
         / \
        x   x

Both contain the same number of operators. In a typical tacit (including prefix or postfix) language, they would be equally short. However, in Risky, there is a large difference. The first is perfectly symmetrical, and could be represented with x+x+x+x. The second, however, would look something like: 0+0+0+x+0+x+x+x. This looks a bit ridiculous at first, but when you draw it as a tree it makes more sense why this is required:

              +
          /       \
      +               +
    /   \           /   \
  +       +       +       +
 / \     / \     / \     / \
0   0   0   x   0   x   x   x

Format

Risky programs can be formatted either as text (string mode), or raw bits (binary). The differences between these methods are important to keep in mind for certain types of programming challenges, like [tag:radiation-hardening], or for scoring (where string mode uses twice as many bits per operator as binary mode).

String:

Risky's string mode uses ASCII, UTF-8, or any other encoding an interpreter will accept. All spaces, \t (tabs), \r (carriage returns), and \n (newlines) will be discarded. Any ; will be the start of a comment, which is terminated by a \n (newline). Note that \r will not terminate comments.

Binary:

Risky has a 4-bit code page, consisting of 16 operators:

x x
0 _ 8 /
1 ? 9 \
2 - a }
3 0 b +
4 1 c *
5 2 d [
6 ! e :
7 { f ]

In order to pad programs to a whole number of bytes, a _ should be inserted at the start. This will be parsed as the identity function, and will not impact the program.

Note that whitespace and comments cannot be represented in binary mode.

Nilads

Risky has two data types: Integer, and Array. Arrays can contain integers or more arrays, or some of both.

Input is handled by the interpreter. The reference implementation accepts an array of inputs, which can be integers, arrays, characters (converted to integers), or strings (converted to arrays of characters), and supports string output.

Nilad
_ Inputs
? Next input
- -1
0 0
1 1
2 2
! 3
{ 4
/ 5
\ 6
} 7
+ 8
* 10
[ 64
: 100
] []

Monads

Monads other than _ (identity) are overloaded over numbers and arrays.

Number Array
? [x] x
- Negate Reverse
0 Range Transpose
1 Sign Sort
2 Double Unique
! Factorial Count
{ Log 2 Slices
/ Factors Combinations
\ Prime factors Permutations
} Square root Orderings
+ 2 ** x Sum
* 10 ** x Product
[ Absolute value Minimum
: Is not 0 Flat
] Fibonacci Optimize

Optimize is the only one there that might need a bit of explaining. It takes an array of arrays, finds the one with the minimum first item, and returns the rest of it. For example, [[1, 0], [0, 4, 6], [2]] would result in [4, 6].

Dyads

Risky's dyads are divided into 13 normal dyads, and 3 dynamics. The normal dyads are overloaded over two numbers, array and number, number and array, and two arrays.

Numbers Array and Number Number and Array Arrays
+ Add Copy final Rotate right Concat
- Subtract Remove Rotate left Difference
* Multiply Repeat Join Join
/ Divide Group Split Split
\ Modulo Partition Find Find
2 Power Append Prepend Append
{ Compare xth item Slice first Map to xth item
1 Distance From sig. figs (with exponent) Farthest Map pairs
: Equals All equal Combinations Equals
! Pair None equal Permutations Cartesian product
} Base convert Base convert Base convert Base convert
[ GCD Pad start Slice from Intersection
] LCM Pad end Slice final Union

Risky has three dynamics, which essentially treat their second argument as a code block. They prepend additional inputs.

  • _ (NUMBER): Pass x as an input, run once
  • _ (ARRAY): Map over all items in x, passed as inputs
  • ? (NUMBER): Count up from 0, passing the counter as input, and find the xth counter value returning a truthy value
  • ? (ARRAY): Filter
  • 0 (NUMBER): While loop, with x passed as input, then the return value of the previous iteration for subsequent ones
  • 0 (ARRAY): Reduce, with accumulator starting as first item in array, and passed as first input (items are second input)

Any nonzero number is truthy, and any array containing a truthy value is truthy.

Interpreter

The reference implementation of Risky takes two inputs, and a third optional one. The first is the program, either as a string (string mode) or Uint8Array (binary mode). The second is the array of inputs (or a string). The third is an optional boolean value, which will force output either as a string or array of numbers (defaults to whatever form the input is).

You are free to create your own implementations of Risky, or front-ends for the reference implementation. It should perform exactly the same for any inputs (once parsed by the interpreter), so particular attention should be paid to the behavior of Risky's operators in certain edge cases.

Future

Risky is a proof-of-concept. It is not intended to be particularly well optimized for golfing. Risky is intended to show off the possibilities with "oddfix" (determining the arity of an operator based on some numerical property of the program's length).

It is highly advantageous under certain circumstances, described in detail above. This is due to the massive potential for overloading. Additional data types or an extra one or two bits per operator could easily double, quadruple, or even multiply by ten the number of effective operators, for a serious golfing language, without even considering prefix codes.

Currently, depending on how you count, Risky manages to overload about 104 operators into a 4-bit code page (at the cost of brevity in many scenarios). It may or may not be an effective and novel direction to take golfing languages. There are, I suspect, much better ways to decide the arity of an operator, which could help to prevent the harsh symmetry requirements Risky imposes. I think it's our duty as code golfers to find them ;p

You might also like...

A programming language (WIP)

Umo programming language Concept Effect system (not implemented) Subtyping (not implemented) Opt-in shared mutability (not implemented) Gradual typing

Feb 25, 2022

Jaksel Script, Programming language very modern and Indonesian style

Jaksel Script Jaksel Script is a new programming language, very modern, easy to learn, using Indonesia-slang language. No programming experience requi

Jan 3, 2023

The Javascript and canvas port of MarkovJunior : A Probabilistic Programming Language.

The Javascript and canvas port of MarkovJunior : A Probabilistic Programming Language.

MarkovJunior.js MarkovJunior is a probabilistic programming language where programs are combinations of rewrite rules and inference is performed via c

Nov 15, 2022

One-stop Go+ programming language environment manager

One-stop Go+ programming language environment manager

InGop (Go+ language) One-stop Go+ programming language environment manager How do I learn the Go+ programming language quickly? Start with installatio

Nov 21, 2022

An enhanced VSCode extension for the Move programming language.

Move Analyzer Plus Provides language support for the Move programming language. Install on the VSCode Extension Marketplace: Move Analyzer Plus on the

Aug 12, 2022

Simple JSON parse/stringify for the Wren programming language

wren-json Simple JSON parse/stringify for the Wren programming language. Parses strict json and relaxed json Comments Unquoted keys Trailing commas St

May 18, 2022

The interpretation implementation implemented programming language built for fun. I'm currently boring in full stack web development. So, I crafted this one LoL. 👻

The interpretation implementation implemented programming language built for fun. I'm currently boring in full stack web development. So, I crafted this one LoL.  👻

What's Wuttyi? Everything is expression 👻 I just developed this tiny programming language because of boring in higher level programming construct. Mo

Dec 13, 2022

Simple Math Programming Language (SMPL) for the Web

Simple Math Programming Language (SMPL) for the Web SMPL is a math-oriented programming language that can be interpreted in the browser. Its primary u

Dec 15, 2022

A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Sep 21, 2022

A probabilistic programming language based on pattern-rewriting

A probabilistic programming language based on pattern-rewriting

MJr-compiler MJr is a probabilistic programming language based on pattern-rewriting, heavily inspired by MarkovJunior by Maxim Gumin. This project pro

Dec 15, 2022

This is a boilerplate for creating your own languages for various use cases. You can even create your own programming language from scratch!

Bootstrap compiler This is a bootstrap compiler that can be used to compile to compiler written in the target language. You can write a compiler in th

Nov 14, 2022

This is a project that is in partial fulfillment of our CSCI 318 - Programming Language Concepts class of the Fall 2022 semester in New York Institute of Technology

StreetEasier A hub to search for apartments and roommate matching This project was bootstrapped with Create React App. Want to Test Yourself? 1.) Clon

Dec 5, 2022

The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming language for implementing different functions.

Little Man Computer The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming

Nov 17, 2022

i18n-language.js is Simple i18n language with Vanilla Javascript

i18n-language.js i18n-language.js is Simple i18n language with Vanilla Javascript Write by Hyun SHIN Demo Page: http://i18n-language.s3-website.ap-nor

Jul 12, 2022

A Programming Environment for TypeScript & Node.js built on top of VS Code

Programming Environment for TypeScript & Node.js A battery-included TypeScript framework built on top of Visual Studio Code Website Kretes is a progra

Dec 11, 2022

Jargon from the functional programming world in simple terms!

Functional Programming Jargon Functional programming (FP) provides many advantages, and its popularity has been increasing as a result. However, each

Jan 4, 2023

A reactive programming library for JavaScript

RxJS: Reactive Extensions For JavaScript RxJS 7 (beta) FOR 6.X PLEASE GO TO THE 6.x BRANCH Reactive Extensions Library for JavaScript. This is a rewri

Dec 28, 2022

Functional reactive programming library for TypeScript and JavaScript

Functional reactive programming library for TypeScript and JavaScript

Bacon.js A functional reactive programming lib for TypeScript JavaScript, written in TypeScript. Turns your event spaghetti into clean and declarative

Jan 1, 2023

Ultra-high performance reactive programming

Ultra-high performance reactive programming

________________________________ ___ |/ /_ __ \_ ___/__ __/ __ /|_/ /_ / / /____ \__ / _ / / / / /_/ /____/ /_ / /_/ /_/ \____/__

Dec 28, 2022
Comments
  • Is Sort supposed to modify the list?

    Is Sort supposed to modify the list?

    Consider the program __+1_ (concatenate the list of inputs and the list of inputs sorted). With an input of [3,2,1], I expected the result to be [3,2,1,1,2,3]; however, instead, I got [1,2,3,1,2,3]. Try it online!

    I'm guessing the 1 monad sorts the input list in place, meaning that every other reference to _ becomes the sorted version. Under some circumstances, the modification of _ can also affect ?: Try it online!

    I suspect this behavior is not intentional, but I'm not 100% sure, so I'm phrasing this issue as a question.

    opened by dloscutoff 2
  • Better padding strategy for binary mode

    Better padding strategy for binary mode

    Idea: instead of padding odd-length programs with a trailing _ in binary mode, what about padding with a leading _? Then the _ wouldn't even need to be trimmed off: it would simply apply the identity function to the program's return value.

    I can submit a pull request if you like.

    opened by dloscutoff 2
Owner
Ryan Tosh
Interested in just about anything. Game designer, challenge writer, student. Too many projects.
Ryan Tosh
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Visualize COVID-19 risky addresses in Shanghai.

Visualize COVID-19 risky addresses in Shanghai.

null 51 Dec 19, 2022
Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

CookBook - Hacktoberfest Find the book you want to read next! PRESENTED BY What is CookBook? A cookbook in the programming context is collection of ti

GDSC-NITH 16 Nov 17, 2022
Write "hello world" in your native language, code "hello world" in your favorite programming language!

Hello World, All languages! ?? ?? Write "hello world" in your native language, code "hello world" in your favorite language! #hacktoberfest2022 How to

Carolina Calixto 6 Dec 13, 2022
This a programming training app, aimed to help OMRI's students learng the magic world of programming.

OMRI App (fe-omri-app) This a programming training app, aimed to help OMRI's students learng the magic world of programming. Install the dependencies

OMRI Tech 2 Nov 19, 2022
⚡ Extremely fast online playground for every programming language.

Riju Riju is a very fast online playground for every programming language. In less than a second, you can start playing with a Python interpreter or c

Radon Rosborough 845 Dec 28, 2022
Programming language makes by hobby <3

Joule Programming language makes by hobby <3 About It's a compiled programming language written in JavaScript :/. Codes compile into Assembly code tha

null 6 Feb 17, 2022
VSCode extension for the rickroll-lang programming language (incomplete)

Rickroll-Lang VSCode Extension The Rick Roll programming language is a rickroll based, process oriented, dynamic, strong, esoteric programming languag

Siddhesh Zantye 6 Oct 10, 2022
A Flow-based programming language for universal applications.

Hlang A Flow-based programming language for universal applications. Hlang aims to make programming easier, faster and more comfortable. It avoids codi

HSET 5 Dec 25, 2022