Talk:Whitespace

From Esolang
Jump to navigation Jump to search

Well, I think I've completed the page. Actually, maybe I can add a truth machine, but don't tell me to add a quine.--Quadril-Is (talk) 14:38, 16 November 2019 (UTC)

And they don't work. --Quadril-Is (talk) 03:25, 17 November 2019 (UTC)

april fools sidenote??

once at april fools google truthfully said:"gmail is much better than what youre using" basically BUT they were also making april fools jokes so the true statement also was treated as id´f it were a joke Example99 (talk) 13:48, 9 July 2023 (UTC)

I made a Python thing to make it easier to edit Whitespace code

I coded a script that converts the characters "n", "r", and "s" into the corresponding whitespace character and ignores the rest, so that I could code in Whitespace better. I even allowed comments using '//'.

input = '''
Visible Whitespace code goes here
'''
# remove line comments
input = input.split("\n")
input = ''.join([
    line[:line.find('//')] if line.find('//') != -1 else line
    for line in input
])
# convert 'n', 't', and 's' into whitespace, ignoring the rest
def to_ws(char_code):
    if char_code == 110:
            return '\n'
    if char_code == 115:
            return ' '
    if char_code == 116:
            return '\t'
    return ''
ws_code = ''.join([
    to_ws(ord(c)) for c in input
])
# print the result
print("[" + ws_code + "]")

I used this to code a Hello World that is a few bytes shorter than the sample given in the page. Since the tool ignores everything other than 'n', 's', and 't', I added '.' after the IMP like it's a namespace, '(' and ')' around parameters, and '#' before numeral literals.

s.s(           // stack > push number
 #s_tss_tsss_n // H (space = 0, tab = 1)
)
tn.ss          // I/O > print character at top of stack

s.s(#s_tts_stst_n) // e
tn.ss

s.s(#s_tts_ttss_n) // l
s.ns  // stack > duplicate
s.ns  // duplicate again for later
tn.ss
tn.ss

s.s(#s_tts_tttt_n) // o
s.ns  // duplicate for later
tn.ss

s.s(#s_ts_ssss_n) // space
tn.ss

s.s(#s_tst_sttt_n) // W
tn.ss

tn.ss // print the 'o' duplicated before

s.s(#s_ttt_ssts_n) // r
tn.ss

tn.ss // print the 'l' duplicated before

s.s(#s_tts_stss_n) // d = 0x65
tn.ss

s.s(#s_ts_ssst_n) // ! = 0x65
tn.ss

n.nn // halt

This takes 130 characters, and saves 51 characters over the 181-character version on the page by duplicating copies of 'l' and 'o'. --HaleyHalcyon (talk) 07:18, 30 October 2023 (UTC)

Update: I gave the IMPs and commands human-readable names, coded a transpiler, and formally defined Visible Whitespace! Is this easy to use and understand? HaleyHalcyon (talk) 08:18, 12 November 2023 (UTC)

Question

  1. What is "to call a subroutine"?
  2. What is "the location of stack"? Does it start from top or bottom? Does is starts with 0 or 1?

--None1 (talk) 12:36, 30 October 2023 (UTC)

To answer Q2, here’s a program I whipped up (replace s, t, and n with space, tab, and newline)
s.s(s tst n) // push 5
s.s(s tss n)
s.s(s tt n)
s.s(s ts n)
s.s(s t n)
s.s(s s n) // ... push 0

s.ts(s s n) // copy 0th
tn.st() // pop & print number
// this outputs “0”
s.ts(s t n) // copy 1st
tn.st()
// this outputs “1”
s.ts(s ts n) // copy 2nd
tn.st()
// this outputs “2”
n.nn() // halt
We can see that Whitespace follows the full + descending stack convention, meaning that the top of the stack is 0, and subsequent items are positive integer indices. --HaleyHalcyon (talk) 15:51, 30 October 2023 (UTC)
To answer Q1, here’s a Fibonacci calculator.
// Initialize values with two 1s.
s.s(s t n) // push 1
s.ns() // dupe

// I could make it loop, but that just adds
// unwanted complexity to this simple example.
n.st(s t n) // call sub 1
n.st(s t n)
n.st(s t n)
n.st(s t n)
n.st(s t n)
n.st(s t n)
n.st(s t n)
n.st(s t n)

// “Looping” ends here.
n.sn(t t n) // jump to -1

// Contents of the subroutine that gets called above.
n.ss(s t n) // declare label 1
s.s(s tsts n) // push \n
tn.ss() // print that \n
// This code takes the last 2 Fibonacci numbers
// as stack elements 1 and 0 respectively, and then
// destroys the smaller item as it prints the sum.
s.nt() // swap
s.ts(s t n)// dup at 1
ts.ss() // add
s.ns() // dup top
tn.st()// print num
n.tn() // return

// Where you jump to once the looping ends.
n.ss(t t n) // declare label -1
n.nn() // halt
A subroutive is basically a segment of the source code that acts like a function. --HaleyHalcyon (talk) 16:07, 30 October 2023 (UTC)

OK, now I understand, thanks for explaination! --None1 (talk) 10:21, 31 October 2023 (UTC)