w (A)

From Esolang
Jump to navigation Jump to search

w is a postfix esoteric programming language invented by User:A based on wren designed for code golf. It has a very consistent syntax for stack operations, without involving the concept of blocks and infix operators, as well as avoiding the concept of modifyable accumulators! (W also only has a single stack, which prevents the program from being hard to read.)

In addition, w doesn't apply the operations directly - every instruction chain is treated as an anonymous function. This makes the language very easy to learn and write code in.

Project Euler 1

Project Euler 1:
1000             % Literal 1000
            W    % Filter out all numbers that fullfill
                 % the following condition in the range
                 % 1..100
    a5m          % The provided each input of F modulo 5
       a3m       % The provided each input of F modulo 3
          &      % And those values
           !     % Negation (i.e. remove those that don't)
             J   % Summate the remaining list

Due to W's shorthands, 1000 can be replaced with `3^`, i.e. 10 to the power of 3.

An example

Factorial finder



There is an implicitly-given input
    R For every item in
 .    the generated range
      from the implicitly given input
1     to the number 1:
  @   Roll down to exploit two operands
    R Reduce this range using this method:
      For the implicitly given 2 operands
      (the accumulator and the current item):
   *  Multiply them

Implicit output the value

Or, since W now auto-maps in the range (1..input) inclusive:


Do you make me up?



Implicitly provide 2 inputs

t    "Trim" them (a.trim(b) is removing all characters in b that exist in the string a)
   = Check equality with
 ""  the null string

Implicit output

Hello, world!

There isn't a built-in, so the string is in its literal form.

Hello, world!"


Implicitly provide a quote
Hello, world!"  Push this string

Implicit print




"             THe implicit quote
 p34CS+"      This string.
       p      Print & return the string.
        34CS+ prepend it with a quote.

Return this value.

There's also a quote built-in in W. (7 bytes)


Prime tester

Works for 1. Also, no boring built-ins in W for this one!



  W    % Generate a range from 1 to the input
       % Keep those items where the following condition is true:
m      % Find the remainder of the input and the current item of the range
 !     % Negate this result
   k2= % Is the length of the list 2?
       % Implicit output

Mean of array

This is an idea taken from the XENBLN page.


Reference implementation

Here is the implementation. This is a reimplementation in Python that makes sure all examples work. (Not in Wren, because I can't seem to get Wren to work...)