Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 18-Nov-2018 21:48:50

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

playing around with building grids out of strings

long time (for me) and no coding, my brain has been getting out of shape

I've been thinking about how to build a grid of objects in scol, starting (and perhaps ending) with strings in the system console.

This code has two functions.

The first function takes a string element S , an integer I specifying how many times the element is to occur in a list,  and returns a list of strings: S R1

proto make_string_list =  fun [S [S r1] I ] [S r1];;

The second function takes a list of strings S r1, a multiplier, which counts how many individual strings are to be printed to the console before the console begins writing a new line I, and returns an output string S, which is a grid of the strings written with multiplier I strings per line:

proto build_line_return_string = fun[[S r1] I I S]  S;;

Here is the whole package. I figure this could be done in os3d to build grid like structures for fps games or, if the input of each element is varied, to build grid like city structures:

proto build_line_return_string = fun[[S r1] I I S]  S;;
proto make_string_list =  fun [S [S r1] I ] [S r1];;




fun make_string_list(element, list, iterations) =
let 0 -> counter in
(
while (counter < iterations) do
(
set list = element::list;
set counter=counter+1;
);
);
list;;



fun build_line_return_string (list, multiplier, counter, output_string)=
	
	//end of list, return full string
	if ((hd list)== nil) then
	(
	
	output_string;
	)
	else
	//not end of list yet
	(	
	if ((mod counter multiplier)==0)
	then
	(
	//add head of list to end of string, add line return since we are at a multiple of multiplier that 
        //determines line length and 
        //feed tail of list and changed string back into function
	set output_string= strcatn output_string::(hd list):: "\n"::nil;
	set counter = counter +1;
	build_line_return_string tl list multiplier counter output_string;
	)
	else
	(
        //add head of list to end of string followed by a space, feed tail of list 
        //and changed string  back into function
	set output_string = strcatn output_string::(hd list)::" "::nil;
	set counter = counter +1;
	build_line_return_string  tl list multiplier counter output_string;

	);
	);;	
	
fun main()=
_showconsole; 
let make_string_list "vv" nil 100-> string_list in
_fooS build_line_return_string string_list 2 1 nil;
0;;

Offline

#2 18-Nov-2018 23:02:32

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: playing around with building grids out of strings

Hello !

proto build_line_return_string = fun[[S r1] I I S]  S;;
proto make_string_list =  fun [S [S r1] I ] [S r1];;

fun make_string_list(element, list, iterations) =
	let 0 -> counter in
	while (counter < iterations) do
	(
		set list = element::list;
		++counter;
	);
	list;;



fun build_line_return_string (list, multiplier, counter, output_string)=
	
	//end of list, return full string
	if ((hd list) == nil) then
		output_string
	//not end of list yet
	else
	if ((mod counter multiplier) == 0) then
	(
		//add head of list to end of string, add line return since we are at a multiple of multiplier that 
                //determines line length and 
                //feed tail of list and changed string back into function
		set output_string = strcatn output_string::(hd list):: "\n"::nil;
		++counter;
		build_line_return_string tl list multiplier counter output_string;
	)
	else
	(
		//add head of list to end of string followed by a space, feed tail of list 
		//and changed string  back into function
		set output_string = strcatn output_string::(hd list)::" "::nil;
		++counter;
		build_line_return_string tl list multiplier counter output_string;
	);;	
	
fun main()=
	_showconsole; 
	let 100 -> iterations in
	let make_string_list "vv" nil iterations -> string_list in
	_fooS build_line_return_string string_list 7 1 nil;
	0;;

I just add few very minor changes. To be continued ...

I don't know what you want to do next...
you can try to write a more polymorphic package: for example, a list of any objects with a tuple of coordinates instead of string ? Or not ! smile Cool to see you again

Offline

#3 19-Nov-2018 15:41:27

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: playing around with building grids out of strings

thanks for that ++ insertion Iri.

A question...is there a way to add an element to the end of a list as opposed to the beginning (I've done some looking on redmine to see if the function is in one of the libraries but haven't found it):

If I change

set list = element::list;

to

set list = list::element;

scol throws an error, I assume because I am adding an element that comes after the end of the tail of the list, which is nil.

(!) Line #11:
	list??;;
>>> ERROR - Type mismatch (detail):
Found:    fun [S [S r1] I] [S r1]
Expected: fun [[[r1 r1] r1] [r1 r1] I] [r1 r1]

I'm also curious as to what:

Expected: fun [[[r1 r1] r1] [r1 r1] I] [r1 r1]

means. r1 states the type of recursivity. how can you have recursivity of recursivity? i thought recursivity is only a property of elements, such as S, I, F, user_defined_struct, etc. But recursivity of recursivity? I'm mystified. Sounds like something out of Godel's Theorem.


a list of any objects with a tuple of coordinates instead of string

yes that would be a great idea for creating endless cities. something where you create a grid of square shaped So3 scene nodes (randomly drawn from an array different meshes, all formed so that they can seamlessly join to one another), resize if needed, and then go explore, something like a less spectacular version of 4'10" of this (made with non realtime mandelbulb...https://www.youtube.com/watch?v=PWMTDRWJqu4 )

Last edited by hebdemnobad (19-Nov-2018 15:59:47)

Offline

#4 19-Nov-2018 16:17:41

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: playing around with building grids out of strings

hebdemnobad wrote:

scol throws an error, I assume because I am adding an element that comes after the end of the tail of the list, which is nil.

Yes.

hebdemnobad wrote:

I'm also curious as to what:

Expected: fun [[[r1 r1] r1] [r1 r1] I] [r1 r1]

The compiler is too crazy sometimes ...
[r1 r1] does not exist. It's senseless.
A recursivity level 2 can be exist (even level n but this is no utility in practice). By example : [S I r2]

To add an element at the end, you can see in 'lib/std/list.pkg' : there is not function for that but std_lApplyFunc could be a start.

Offline

#5 19-Nov-2018 16:33:19

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: playing around with building grids out of strings

I think a simple shortcut would be

1. turn the new string element into an S r1 list like this where String_element is a string and Lfirst_list is an [S r1] list:
2. join old list to new list sing os3d list function lcat    (p ,q  )   
3. return old list+new list

fun add_to_end_of_list (first list, String_element)=
//step 1
let String_element::nil-> last_list in
// step 2
lcat	 Lfirst_list last_list;;

I'll try this when I have time.

Last edited by hebdemnobad (19-Nov-2018 16:41:29)

Offline

Board footer

Powered by FluxBB