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 17-Dec-2014 22:16:38

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

attempting to mutate a component of a list

colleagues:

I am trying to mutate a component in a list:

fun rebuild_list (list)=

let list -> temp_list in
while (tl temp_list) !=nil do
(
mutate hd list <- [strcat (hd list) "/"];
_fooS hd list;
set temp_list = tl temp_list;
);
0;;

I am getting the error:

mutate hd list <- [strcat hd list "/"??];
>>> ERROR - Type mismatch (detail):
Found:    [S [S]]
Expected: [S S]

whether I write
mutate hd list <- [strcat (hd list) "/"];
or
mutate hd list <- [strcat hd list)"/"];
or
mutate hd list <- [(strcat (hd list) "/")];

any input welcome to get rid of those [ ] I am generating.

thx
-h

Offline

#2 17-Dec-2014 22:50:40

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,162
Website

Re: attempting to mutate a component of a list

mutate work only on tuple

here hd list is S
a list is a tuple of tuples

[first_element nexttuple]

so you can use
mutate list <- [strcat (hd list) "/" _];
"_" is the ignored tuple element here the next tuple in the list

Offline

#3 17-Dec-2014 22:52:39

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,162
Website

Re: attempting to mutate a component of a list

but be careful here is will always add "/" on the first list element only

you should reconstruct a new list with lcat

Offline

#4 17-Dec-2014 23:26:57

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

Re: attempting to mutate a component of a list

arkeon wrote:

but be careful here is will always add "/" on the first list element only

you should reconstruct a new list with lcat

Thx arkeon....how would I use lcat to insert a "/" between each element of list?

Offline

#5 17-Dec-2014 23:32:36

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,162
Website

Re: attempting to mutate a component of a list

strcatnSep in tools.pkg

let strcatnSep list "/" -> path in

Offline

#6 18-Dec-2014 02:31:40

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

Re: attempting to mutate a component of a list

arkeon wrote:

strcatnSep in tools.pkg

let strcatnSep list "/" -> path in

thx!

how to turn the string harry/sally/jim/ to the list harry:sally:jim:nil and back into harry/sally/jim/:

proto strToListSep = fun [S S] [S r1];;
proto strcatnSep = fun [[S r1] S] S;;


fun secureLoad(pack)=

  let _testpak pack -> ret in
  if (ret == nil) then

  (
    _fooS "xmlparser loading";
    _load pack;
    1;
  )
  else
  (
    _fooS strcat "Error in " ret;
   0;
  );;
  
  
fun rebuild_list (list)=

let strcatnSep list "/" -> rebuilt_list_as_string in
let strcat rebuilt_list_as_string "/"->rebuilt_list_as_string in
_fooS  rebuilt_list_as_string;  
0;;

fun load_dependencies(parameter)=
let "locked/lib/_mlistlib.pkg"::"tools/os3dlib/tools.pkg"::nil -> list_of_dependencies in
(
		while (list_of_dependencies!= nil)&& (secureLoad hd list_of_dependencies) do
				(
					set list_of_dependencies = tl list_of_dependencies;
					_fooS "dependencies loading";
				);
		//all dependencies have been read
		if list_of_dependencies==nil then
  				(
  				
  							_fooS "done with  dependency loading";
  							_fooS strcatn "original string to chop is":: parameter::nil;
  							let strToListSep parameter "/" -> templist in
							(
							_fooS "separated list, each element split by a \" \, \" below";
							_fooSList templist; 
  							rebuild_list templist;
  							);
  				0;
  				) 
  		else
  				(
  							_fooS "error in dependency loading";
  				0;
  				);
);
0;;


fun main()=
_showconsole;
let "harry/sally/jim/" -> list_to_chop in
(

	load_dependencies list_to_chop;
);	
	
	0;;

Offline

Board footer

Powered by FluxBB