You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.
Something that I am quite familiar with other languages such as C++ or Python is the use of list or vector container. I saw on GSL one can use XML data structure instead of that, but sometimes it is even more efficient and reduces drastically code length using a list mechanism since XML can be much more seen as map or dictionary than a single list container.
Therefore, I created a small library of functions that implements functions for such a purpose here is the list of these functions:
list_new: create a new list
list_exists: check if the passed argument is a list
list_empty: does the list empty ?
list_append: append a new item into the list
list_get: get the i^th item of the list
list_delete: delete the i^th item of the list
list_foreach: apply a callback function to every single item in the list
list_print: standard output the whole list
It is also possible to add a list into another. Here is a GSL script showing a typical usage:
It wouldn't be terribly difficult to implement a new list object using a
GXL file. You can probably do a bit of reverse engineering by looking at
the existing GSL files, and the ggfunc.gsl script that processes GXL
files into C. As I wrote this code (many years ago) I can probably give
a hand or advice.
Cheers,
Jonathan
On 14/12/14 04:31, Caner Candan wrote:
Something that I am quite familiar with other languages such as C++ or
Python is the use of list or vector container. I saw on GSL one can use
XML data structure instead of that, but sometimes it is even more
efficient and reduces drastically code length using a list mechanism
since XML can be much more seen as map or dictionary than a single list
container.
Therefore, I created a small library of functions that implements
functions for such a purpose here is the list of these functions:
list_new: create a new list
list_exists: check if the passed argument is a list
list_empty: does the list empty ?
list_append: append a new item into the list
list_get: get the i^th item of the list
list_delete: delete the i^th item of the list
list_foreach: apply a callback function to every single item in the list
list_print: standard output the whole list
It is also possible to add a list into another. Here is a GSL script
showing a typical usage:
function global.list_foreach(list, callback, record)
check_arg_missing('list_foreach', 'list', my.list)
check_arg_missing('list_foreach', 'callback', my.callback)
my.record ?= XML.new('record')
for my.list. as i
$(my.callback)(i, my.record)
endfor
return my.record
endfunction
function print_callback(item, record)
check_arg_missing('print_callback', 'item', my.item)
check_arg_missing('print_callback', 'record', my.record)
if list_exists(my.item)
my.sublist_record = list_foreach(my.item, 'print_callback')
copy my.sublist_record to my.record
else
new my.record.field as f
define f. = my.item.
endnew
endif
endfunction
function recursive_print(record)
check_arg_missing('list_print', 'record', my.record)
my.s = "["
for my.record. as i
if name(i)?"" = "record"
my.s += recursive_print(i)
else
my.s += i.
endif
if !last(i)
my.s += ','
endif
endfor
my.s += "]"
return my.s
endfunction
function global.list_print(list)
check_arg_missing('list_print', 'list', my.list)
Something that I am quite familiar with other languages such as C++ or Python is the use of list or vector container. I saw on GSL one can use XML data structure instead of that, but sometimes it is even more efficient and reduces drastically code length using a list mechanism since XML can be much more seen as map or dictionary than a single list container.
Therefore, I created a small library of functions that implements functions for such a purpose here is the list of these functions:
It is also possible to add a list into another. Here is a GSL script showing a typical usage:
And the result:
I don't know if anyone see useful to add them as a builtin GSL feature.
Anyway, here is the source code:
The text was updated successfully, but these errors were encountered: