Hello list,

I've reduced my program to a small example (and the output) and I am still
confused. I am training myself with neko and I understood that an array is
accessed by '[n]' notation but the fault(!?) if it exists, appears to be
with the return data from string_split.

The output from the program shows what I can tell is a LISP-like cons chain.
The $asize() tells me I have two items, which, on examination would the
'car' and 'cdr' parts.

The only thing I see is that the documentation for string_split says that
the return type for the function is 'list' which would then explain things
fully! :)

    *string list** string_split**(s : string, sep : string)*

The $typeof() returns 6, which according to the docs is 'array', and no
mention is made of a list  type at all.

Since writing this far, I have decided to post the whole file I am working
with: a means of loading the "std" library en-masse so I can just splash
around in the pool as it is such an awesome language. It feels like
assembler programming but with brains under the hood.

What I want to know is: what is the 'list' type and how do I deal with it ?
I've got a lot of LISP/scheme hours under my belt and it almost looks like
that I'd need a recursive function that just accessed array[0] then pushed
around again until exhausted.

Cheers guys.
Sean Charles
:)

---- THE OUTPUT ----
CSV:
open/2,close/1,name/1,write/4,read/4,write_char/2,read_char/1,seek/3,tell/1,eof/1,flush/1,contents/1,stdin/0,stdout/0,stderr/0
LEN: 2, TYPE: 6
RAW DATA:
[open/2,[close/1,[name/1,[write/4,[read/4,[write_char/2,[read_char/1,[seek/3,[tell/1,[eof/1,[flush/1,[contents/1,[stdin/0,[stdout/0,[stderr/0,null]]]]]]]]]]]]]]]
RAW DATA[0]:
open/2
RAW DATA[1]:
[close/1,[name/1,[write/4,[read/4,[write_char/2,[read_char/1,[seek/3,[tell/1,[eof/1,[flush/1,[contents/1,[stdin/0,[stdout/0,[stderr/0,null]]]]]]]]]]]]]]

---- THE CODE! ----
//!
//! Define the set of API functions from 'std' we will make available.
//! Erlang notation for the functions!
//!
var apiset = {
  file =>
"open/2,close/1,name/1,write/4,read/4,write_char/2,read_char/1,seek/3,tell/1,eof/1,flush/1,contents/1,stdin/0,stdout/0,stderr/0",
  md5 => "make_md5/1"
};


//!
//! Load minimum required string functions to split and load each primitve
//!
string_split = $loader.loadprim("[EMAIL PROTECTED]",2);
sprintf      = $loader.loadprim("[EMAIL PROTECTED]",2);


//!
//! This extracts each function from the list and loads the primitive
//! and attached it to the $exports variable so the called can use it.
//!
process_module = function( apiset, groups, current, max ) {
  if ( current < max ) {
    var group = $objget( apiset, groups[ current ]);
    var flist = string_split( group, "," );
    $print(sprintf("GROUP: (%d) %s\n", $array( $asize(flist), group)));
    $print( $typeof( flist ));
    process_group( flist, 0, $asize( flist ));
    process_module( apiset, groups, current+1, max ); }}


//!
//! This processes each <function/arity> combination
//!
process_group = function( flist, current, fmax ) {
  if ( current < fmax ) {
    $print(sprintf("FUNCTION: %s\n", flist[current] ));
    process_group( flist, current+1, fmax );
  }
}

process_function = function( name, arity ) {
  $print(sprintf("EXPORT: %s/%d", $array(name,arity)));
}



//!
//! Get a list of the keys and process them
//!
groups = $objfields( apiset );
//process_module( apiset, groups, 0, $asize( groups ));


csv="open/2,close/1,name/1,write/4,read/4,write_char/2,read_char/1,seek/3,tell/1,eof/1,flush/1,contents/1,stdin/0,stdout/0,stderr/0";

$print(sprintf("CSV: %s\n", csv ));
funs = string_split( csv, "," );
$print(sprintf("LEN: %d, TYPE: %d\n", $array( $asize( funs ), $typeof( funs
))));
$print("RAW DATA:\n");
$print( funs );
$print("\nRAW DATA[0]:\n");
$print( funs[0] );
$print("\nRAW DATA[1]:\n");
$print( funs[1] );
-- 
Neko : One VM to run them all
(http://nekovm.org)

Reply via email to