Talk:3var

From Esolang
Jump to: navigation, search

Hi, I'm LuaGeek2412, and this is my first programming language. I'm not the most experienced programmer, so any help writing an interpreter would be appreciated. Thanks! Oh, this is also my first page on any kind of wiki.LuaGeek2412 (talk)

Interpreter?

I could use some help writing an interpreter. I think I know how to do it in Lua. Anyone who could do it in a different language is welcome, but I want some help with Lua. I'll put some code in, feel free to edit if you find a bug or something.

a,b,r=0
function run(code)
   i=1
   while i<#code do
      command=code:sub(i,i)
      if command=="i" then
         a=a+1
      elseif command=="d" then
         a=a-1
      elseif command=="s" then
         a=a*a
      elseif command=="x" then
         a=math.abs(a)
      elseif command=="p" then
         io.write(a)
      elseif command=="P" then
         io.write(string.char(a))
      elseif command=="a" then
         b=b+1
      elseif command=="k" then
         b=b-1
      elseif command=="m" then
         b=b*b
      elseif command=="0" then
         b=math.abs(b)
      elseif command=="o" then
         io.write(b)
      elseif command=="O" then
         io.write(string.char(b))
      elseif command=="+" then
         r=a+b
      elseif command=="-" then
         r=a-b
      elseif command=="*" then
         r=a*b
      elseif command=="/" then
         r=a/b
      elseif command=="^" then
         r=a^b
      elseif command==">" then
         a=r
      elseif command=="<" then
         b=r
      elseif command=="w" then
         print(r)
      end
      i=i+1
   end
end

LuaGeek2412 (talk)

I decided that since there has still been no progress on the interpreter, I have decided to open it to Python. However, I have only just started learning Python, so I need help with this. Thanks guys! LuaGeek2412 (talk) 16:47, 2 April 2014 (EDT)

I built a simple C interpreter for this language here, if you're interested. Olls (talk) 20:32, 23 November 2014 (UTC)

Marked Loops

I tried modifying the CAT program to loop only until it received a newline character, but I realized I don't know the "right" way to do a "marked loop". Could you please add some examples to this page which use marked loops? --(this comment by Quintopia at 19:10, 26 January 2014‎ UTC; please sign your comments with ~~~~)

Thanks for pointing that out. I will get right on it. LuaGeek2412 (talk) 22:52, 26 January 2014 (UTC)

Conditional cat weirdness

I ran through the conditional cat in my head, and I'm pretty sure that it is saying that it only copies input to output if a>b AND a<b. I do not know how to fix this. What it essentially is saying is...

::something::
If a>b then
	If a<b then
		output(input)
               goto something 
       end
	goto something
end

Thus, the code will never run. Any ideas whatsoever from anyone? LuaGeek2412 (talk) 19:59, 27 January 2014 (UTC)

FTFY --Quintopia (talk) 04:19, 28 January 2014 (UTC)

Terminate

I'm debating adding a command to terminate the program. Or at least the loop. If I do, then what should it be? If I don't, why not? This could easily fix the conditional cat problem. Thanks for the feedback! LuaGeek2412 (talk) 20:17, 27 January 2014 (UTC)

Turing-completeness

I do not think that 3var is turing-complete, owing to the fact that you cannot emulate BF in 3var. Although, it may be turing-complete due to the limitless possible values of A, B, or R. Any help on this topic is appreciated. LuaGeek2412 (talk) 20:27, 27 January 2014 (UTC)

After a little bit of thought, I think I can see a way to translate Collatz functions to unbounded 3-var programs, involving a forever loop and a whole bunch of conditionals. Can you see it? --Quintopia (talk) 04:39, 28 January 2014 (UTC)
I do not follow. After a quick google search and a look at the page Collatz functions on this wiki, I am utterly confused. According to Google, the Collatz function is for even n, coll(n)=n/2 and for odd n, coll(n)=(3n+1)/2. Esolang says something that I do not understand. Are they equivalent? I do not know. Help? LuaGeek2412 (talk) 16:40, 28 January 2014 (UTC)
If you go by the definition I got from google, then this should infinitely set A=col(A), starting with A=1.
 @i   ~A=1
 {~while true do...
 	#
 	|[~B=next multiple of 2 up from A
 		aa
 	]
 	U(~if B>A... (if A is odd...)
 		#aaa
  		*>i ~A=(3*A)+1
 	)
 	#aa/>  ~A=A/2
 }
If not, then I'm just plain old confused. --LuaGeek2412 (talk) 18:49, 28 January 2014 (UTC)
THE Collatz function (as you have implemented here) is a specific example of a Generalized Collatz Function. Fractran is also a Generalized Collatz Function. Your implementation of one particular Collatz function gives the general principle of the idea of how one constructs such functions in 3var, though it is not quite a proof. A description of a method of translating any Collatz function to 3var would constitute a proof of Turing-completeness. --Quintopia (talk) 19:32, 28 January 2014 (UTC)
Could you please explain what a Collatz function is? --LuaGeek2412 (talk) 03:32, 29 January 2014 (UTC)
Given a list of m integers ai, and m more integers bi, a Collatz function f maps the integer mx+i to the integer aix + bi. The Collatz function you have above has m=2, and a={1,6} and b={0,1}. The Fractran program {3/2} has m=2, a={3,2} and b={0,0}. (In fact, all Fractran programs have bi=0 for all i, so the b list is not necessary to show that Iterated Collatz Functions are Turing-complete.) --Quintopia (talk) 05:16, 29 January 2014 (UTC)
I think I get it, but where does x come from? --LuaGeek2412 (talk)
Since the function input is the integer mx+i where i is less than m, it should be clear that x is the result of integer dividing the input by m... --Quintopia (talk) 17:12, 29 January 2014 (UTC)
I think you messed up the Fractran conversion, it should be a={3,2}, b={0,1}. The b's are definitely necessary in general. --Ørjan (talk) 19:12, 29 January 2014 (UTC)
Thanks for the fix. You're right, of course.--Quintopia (talk) 02:30, 31 January 2014 (UTC)
I think I may get it now. Possibly last n00by question: What is x in the above example? I'm guessing... 1. Thus making f(x)={2=1,3=7}. --LuaGeek2412 (talk) 23:10, 30 January 2014 (UTC)
x will oscillate between 0,1,2 forever with your example --Quintopia (talk) 02:30, 31 January 2014 (UTC)

Input

There is some confusion between the example programs and the spec. Are the input commands named ‘ and “ or are they named ' and "? --Quintopia (talk) 19:38, 28 January 2014 (UTC)

My computer is recognizing them as the same character, and they should both be accepted. They are apostrophe and quotation mark. I don't even know how you got the first ones (or how I got them). --LuaGeek2412 (talk) 20:24, 28 January 2014 (UTC)

Extensions

I've developed an extensions to this language, available on my github: https://github.com/Nikoraito/3var Nikoraito (talk) 17:54, 27 June 2017 (UTC)