ListScript

From Esolang
Jump to navigation Jump to search
This article is a stub, which means that it is not detailed enough and needs to be expanded. Please help us by adding some more information.

// ListScript //

// ListScript made by User:Robotrage //

//syntax

$ 		                       - line input when no parameters specified
_var	   	                       - variable definition start with _
p[VAR]		                       - print // cant name functions 'p'
[CONDITION]?(WHENTRUE)(WHENFALSE)      - if statment, first () for when true second () for when false	 
;		                       - separate inline commands
[_a,_b,_c]		               - for mutliple param output and input


//notes

-script executes in order of index, with input of next line being output of last line unless line is called as a function in which case the single paramater is specified.


// Line definition (CAPITAL words to be replaced) //

>[INPUTPARAMS]>>LINENAME>>INDEX>OUTPUTTYPE|LINEBODY|>RETURN

(blank inputparams defaults to $)

//example//

>>>initial>>0>int|_x = 1+1|>_x
>>>addOne >>1>int|_y = $+1|>_y
>>>foo    >>2>int|_z = addFive[addOne[$]]|>_z
>>>addFive>>3>int|_i = $+5|>_i
>>>print  >>4>int|p[$]|>$
>>>if>>5>nul|[$==14]?(print[$+1])(print[$]) ; print[0]|>nul

// execution order of code above //

-line index 0 executes and does 1+1 to _x variable then returns _x OUTPUT = 2
-line index 1 runs taking _x input from previous line and adding 1, returning that variable _y OUTPUT = 3
-line index 2 runs taking input _y of value 3, that value is passed as input to line index 1 (addOne)
which returns a value of 4, this value is then passed to line index 3 (addFive) as input where we get 4 + 5
returning a value of 9 as _z which will then be returned from line index 2 (foo) OUTPUT = 9
-line index 3 runs taking input of 9 from foo, adding 5 making 14 and returning that value _i OUTPUT = 14
-line index 4 runs, the print function takes input parameter 14 and prints it
-line index 5 runs, conditional code within [] marked with ?, first parentheses run if true second if false, therefore
line index 4 runs with input 15, printing 15, then print[0] calls index 4 ands prints 0
-nul return and no larger indexes means program ends.

printed output is:

14 15 0

//anonymous function, function inside function gets executed in new index order starting at 0//

//to pass a parameter to an anonymous function we place it after the first > //

>INPUT>>>>INDEX>OUTPUTTYPE|LINEBODY|>RETURN
>>>init>>0>int|_x = 1|>_x
>>>plusOne>>1>int|_x = 2 ; >$>>>>0>int|_z = _x + $|>_z  |>_x // 2+1 = 3

//first class function demonstration//

//must be able to be returned from other functions, assigned to variables and passable as a parameters. //

>>>init>>0>int |_x = 0|>_x			//0
>>>foob>>1>func|_func = minusOne|>_func	//returns minusOne function
>>>bar >>2>int |_output=$[1]|>_output		//1-1 = 0
>>>minusOne>>3>int|_output=$-1|>_output	//0-1 = -1
>>>>>4>nul|p[$]|>nul				//print -1 and end


//Kestral or K combinator

>[_x,_y]>>kestrel>>0>int | |>_x	


//Starling or S combinator

>>>Starling>>0>int ||>[1,2,3]	
>[_x,_y,_z]>>one>>1>int |_res= >[_x,_z]>>two>>0>int ||>_x+_z ; >[_xz, _y, _z]>>three>>1>int[] ||>[_xz, _y+_z] ; >[_xz, _yz]>>four>>2>int[] ||>_xz+_yz|>_res